Best way to implement short piece of code into theme

Question in title. What do you think?
For example some static peice of text like Copyright in footer.
All themes that i saw(for example WP basic theme) just put all that text directly into theme files.
Maybe i miss some good approach? Thank you for help!

My first though was to use “get_template_part” - but not shure will it be correct for all thhis small peieces of text…

I would just put it directly in the footer template

Or do this, if you’re using it in multiple places

1 Like

Completely agree, no need to overthink a simple piece of text in the footer :slight_smile:

Maybe my english is bad. But footer was only as example. In themes can be a lot of static text’s

Yeah my rule of thumb is if I have to include something in more than one place, I keep it DRY and use get_template_part and put that partial into the /templates/ folder. So I’d do that.

But u should avoid leave any peiece od Data in code, aren’t u? Following Fauler and MVC principles, or i wrong in that? And i think we should give to users of web site full control of it, not trough HTML code, but from admin panel

What about single peoece of text\data? see my comment about MVC\Fauler

I think you’re thinking about saving data places in the admin and then getting those to show on the front end?

If so, this isn’t the place to ask about that. We only provide support for theming with Roots. For adding text in the footer or whatever into the admin panel you could use the customizer api or ACF’s options page or something like that.

For one, WordPress does not follow the MVC paradigm, it’s all about events. However, it seems like you simply don’t want to have any data in the templates. That’s fine, but my point previously was that if you have content in only one spot, no need to overcomplicate it. If you want it to be user-editable from the WP admin, then follow what JulienMelissas has already linked.

1 Like

Thatk you for your answer! I understand this place not only as Sage theme support, but as very good workflow for developing, and i can’t ask this question in any other plaves if i want to learn how it to work lie you did :slight_smile:

Is really what I’m looking for!

1 Like

Yeah I know that WP does not follow MVC, but Sage is based on 12 factors up, and 12 factors based on Fowler works. And as I understand his works, we should try to separate data from code.

Just wanted to mention that Bedrock is based on the 12 factor app methodology, not Sage (completely different projects)

What I did was to define a widget area and then let the user put what they want in there.

<div class="container section-footer-copyright">
  <div class="row">
    <div class="col-md-6">
      <?php dynamic_sidebar('footer-copyright'); ?>
    <div class="col-md-6">
        if (has_nav_menu('copyright_navigation')) :
          wp_nav_menu(array('theme_location' => 'copyright_navigation', 'walker' => new Roots_Nav_Walker(), 'menu_class' => 'list-inline list-pipeseparator pull-right'));

You can setup custom widget areas and toolbars in ./lib/init.php in Roots (since I started typing this i’ve realised this is kind of a sage question but as its also asking for general best practice I’m going to post it anyway).

Then I just add in a Text Widget and put the the copyright and developed by snippet in on a per client basis.

heh… your code looks almost like main) but I don’t think that it is a perfect way)