Support » Theme: Ryu » Child theme and template-tags.php

  • Resolved mrmonster


    I’m setting up a child theme for Ryu, and everything was going well until I tried to change template-tags.php (there’s some meta content I wanted out). The changes I made weren’t taking, and after a bit of research I found I had to point to it. It gets called in the functions.php. So I tried using get_template and later get_stylesheet, and I tried putting it in the header and in a new functions.php, but all I got was a blank screen when I reloaded a page (in fact, just by putting functions.php in the child theme directory, I got a blank screen.)

    Any idea on how to correctly point to template_tags.php?


Viewing 15 replies - 1 through 15 (of 15 total)
  • As an an example of one of the things I tried, I created a new functions.php file for the child theme and put this in there:

    * Custom template tags for this theme.
    require get_template_directory() . ‘/inc/template-tags.php’;


    But all I got was a blank/white screen. I also tried the same with get_stylesheet.

    Most of functions in here

    are wrapped in if ( ! function_exists() ) so you could just redeclare the same function name in your child theme’s functions.php and make it your own.

    That might be beyond my skills, but I think I know what you’re trying to say. I’ll try to mess with it more. But it still doesn’t explain why I got a white screen, though. Is there any simpler way of doing this? Should I skip the whole child theme thing altogether?

    I tried to change template-tags.php (there’s some meta content I wanted out).

    If that thing is wrapped in a <span> tag, you could just remove it via CSS display none. So your child theme doesn’t need to have anything to do with php functions.

    Child theme is necessary only if you need to overwrite template or make some changes in function. For changes in CSS only, a Custom CSS plugin would do.

    Ah, ok, thanks. Actually, that was my first objective — removing some meta content. But now I’m doing major surgery on it (wanting to add share icons). I might end up just pointing to the file from the original functions.php. Anyway, I’ll fool around with it and report back.

    Well, no matter what I did, I couldn’t get the functions.php in my Ryu child theme to point to the child theme version of template-tags.php without getting a white screen. So I ended up modifying a line in the parent functions.php to point to my edited version of template-tags.php (also residing in the parent theme directory):

     * Custom template tags for this theme.
    require get_template_directory() . '/inc/template-tags2.php';

    This way I don’t have to modify the original template-tags file, but whenever the theme gets updated, I just have to remember to change that line in functions.php to the above to point to tags2.

    Moderator Kathryn


    Automattic Happiness Engineer

    I’m glad you found a workaround.

    Just in case you didn’t already see it, this is how the functions.php file works in child themes:

    Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)

    There’s more information here:

    (in fact, just by putting functions.php in the child theme directory, I got a blank screen.)

    This can happen if there are any blank lines at the beginning or end of a functions.php file – not sure if that was the case for your file, but just thought I’d mention it.

    For now it sounds like you’re all set but just thought I’d add these little bits just in case.

    Yeah, I double-checked for blank lines but didn’t find anything, so it could be something else.

    Workaround is working — I put a text file note in the directory to remind myself to update the functions.php after a theme update!

    Thanks for your input, K!

    Looks like a similar issue to the one I just posted about. There’s a bug in the template-tags.php file. Basically the function_exists() line is incorrect.

    Once you correct the line, you can put a fresh functions.php in your child theme and put a modified ryu_entry_meta() function in it with the meta data you want to have displayed.

    See here for more info:

    The functions_exist() bug has been fixed, so you can now modify the entry meta function in your child theme.

    Thanks — and thanks to CarlJoseph.

    Great job. Beautiful theme. Glad I’m using it.

    Glad you like the theme! 🙂 This thread appears to be resolved, so I’ll go ahead and mark it as such.

    I just ran into this problem with a different theme. The solution was to copy the template-tags.php file to the child theme. Then I created a blank functions.php file which only included that template file like so:
    include get_stylesheet_directory() . ‘/inc/template-tags.php’;

    Notice the difference between get_template_directory() and get_stylesheet_directory(). The template_directory always points to the parent theme, hence you have to use get_stylesheet_directory one to include the template file from the child theme.

    After that is done, the file gets correctly loaded prior to the parent theme and declares the function with the modifications wanted in the child theme.

    @jelo77 I tried your solution, but i got a blank page.

    Moderator Kathryn


    Automattic Happiness Engineer

    Hi jorgicio – could you start a separate thread in the Ryu forum (assuming you’re running Ryu) so we can help you more easily with troubleshooting one-on-one? Please provide a link to your site as well, thanks.

    Could you also copy the contents of your functions.php file into a Pastebin and provide a link to it in your new thread so I can have a look.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Child theme and template-tags.php’ is closed to new replies.