How do I override template-tags.php in twentyseventeen theme

If you take a look at template-tags.php file, then you’ll see something like that:

if ( ! function_exists( 'twentyseventeen_posted_on' ) ) :
/**
 * Prints HTML with meta information for the current post-date/time and author.
 */
function twentyseventeen_posted_on() {

    // Get the author name; wrap it in a link.
    $byline = sprintf(
        /* translators: %s: post author */
        __( 'by %s', 'twentyseventeen' ),
        '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . get_the_author() . '</a></span>'
    );

    // Finally, let's write all of this to the page.
    echo '<span class="posted-on">' . twentyseventeen_time_link() . '</span><span class="byline"> ' . $byline . '</span>';
}
endif;

The if statement in the first line of that code is responsible for checking if given function is already defined.

So what you can do about it? Just define your own function called twentyseventeen_posted_on in your child theme and your function will be the one that is used.

Important: It’s crucial that you define your function before TwentySeventeen defines it’s own version.

Leave a Comment