Title: Template-tags.php &amp; Child Theme
Last modified: August 30, 2016

---

# Template-tags.php & Child Theme

 *  Resolved [caroline](https://wordpress.org/support/users/makeupedia/)
 * (@makeupedia)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/template-tagsphp-child-theme/)
 * I [already read this thread](https://wordpress.org/support/topic/child-theme-and-template-tagsphp?replies=16)
   but couldn’t solve it.
 * I noticed that my childtheme template-tags.php does not work, instead it uses
   the parent.
 * Changed _get\_template\_directory()_ to _get\_stylesheet\_directory()_, gave 
   nothing but error.
 * Is there anything important I have missed here?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/template-tagsphp-child-theme/#post-6438792)
 * you cannot re-use a the full code of template-tags.php in a child theme, even
   if you get the folder structure and the ‘require…’ code right.
 * the way to change functions which are created in the parent theme’s template-
   tags.php, depends on what exactly you want to customize.
 * some of the functions are ‘pluggable’ – [https://codex.wordpress.org/Pluggable_Functions](https://codex.wordpress.org/Pluggable_Functions)
 * other functionalities might be added via _filter_, in which case you can remove
   the filter and add a new one – [https://codex.wordpress.org/Plugin_API/Filter_Reference](https://codex.wordpress.org/Plugin_API/Filter_Reference)
 * other functionalities might be added via _actions_, in which case you can remove
   the action and add a new one – [https://codex.wordpress.org/Plugin_API/Action_Reference](https://codex.wordpress.org/Plugin_API/Action_Reference)
 *  Thread Starter [caroline](https://wordpress.org/support/users/makeupedia/)
 * (@makeupedia)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/template-tagsphp-child-theme/#post-6439091)
 * I understand and removed the childs template-tags.php, but still `<?php twentyfifteen_entry_meta();?
   >` gives error.
 * Could it be that my child theme can’t reach the parent template-tags.php?
 * I took the php entry-meta code from parent template-tag.php and put it in my 
   childs functions.php. After that, the entry meta author and date showed up, but
   not the categories and tags which still gave error.
 * Why it still won’t work when I rely on parents templates and have deleted my 
   child ones is a mystery for me.
 *  Thread Starter [caroline](https://wordpress.org/support/users/makeupedia/)
 * (@makeupedia)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/template-tagsphp-child-theme/#post-6439102)
 * Solved!
 * I had to copy this from parent template-tags.php into child functions.php.
 * No idea why but seems like my child don’t read the parents template-tags.php.
 *     ```
       if ( ! function_exists( 'twentyfifteen_entry_meta' ) ) :
       /**
        * Prints HTML with meta information for the categories, tags.
        *
        * @since Twenty Fifteen 1.0
        */
       function twentyfifteen_entry_meta() {
       	if ( is_sticky() && is_home() && ! is_paged() ) {
       		printf( '<span class="sticky-post">%s</span>', __( 'Featured', 'twentyfifteen-child' ) );
       	}
   
       	$format = get_post_format();
       	if ( current_theme_supports( 'post-formats', $format ) ) {
       		printf( '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>',
       			sprintf( '<span class="screen-reader-text">%s </span>', _x( 'Format', 'Used before post format.', 'twentyfifteen-child' ) ),
       			esc_url( get_post_format_link( $format ) ),
       			get_post_format_string( $format )
       		);
       	}
   
       	if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) {
       		$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
   
       		if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
       			$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
       		}
   
       		$time_string = sprintf( $time_string,
       			esc_attr( get_the_date( 'c' ) ),
       			get_the_date(),
       			esc_attr( get_the_modified_date( 'c' ) ),
       			get_the_modified_date()
       		);
   
       		printf( '<span class="posted-on"><span class="screen-reader-text">%1$s </span><a href="%2$s" rel="bookmark">%3$s</a></span>',
       			_x( 'Posted on', 'Used before publish date.', 'twentyfifteen-child' ),
       			esc_url( get_permalink() ),
       			$time_string
       		);
       	}
   
       	if ( 'post' == get_post_type() ) {
       		if ( is_singular() || is_multi_author() ) {
       			printf( '<span class="byline"><span class="author vcard"><span class="screen-reader-text">%1$s </span><a class="url fn n" href="%2$s">%3$s</a></span></span>',
       				_x( 'Author', 'Used before post author name.', 'twentyfifteen-child' ),
       				esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
       				get_the_author()
       			);
       		}
   
       		$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) );
       		if ( $categories_list && twentyfifteen_categorized_blog() ) {
       			printf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
       				_x( 'Categories', 'Used before category names.', 'twentyfifteen' ),
       				$categories_list
       			);
       		}
   
       		$tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen-child' ) );
       		if ( $tags_list ) {
       			printf( '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
       				_x( 'Tags', 'Used before tag names.', 'twentyfifteen-child' ),
       				$tags_list
       			);
       		}
       	}
   
       	if ( is_attachment() && wp_attachment_is_image() ) {
       		// Retrieve attachment metadata.
       		$metadata = wp_get_attachment_metadata();
   
       		printf( '<span class="full-size-link"><span class="screen-reader-text">%1$s </span><a href="%2$s">%3$s &times; %4$s</a></span>',
       			_x( 'Full size', 'Used before full size attachment link.', 'twentyfifteen-child' ),
       			esc_url( wp_get_attachment_url() ),
       			$metadata['width'],
       			$metadata['height']
       		);
       	}
   
       	if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
       		echo '<span class="comments-link">';
       		comments_popup_link( __( 'Leave a comment', 'twentyfifteen-child' ), __( '1 Comment', 'twentyfifteen-child' ), __( '% Comments', 'twentyfifteen-child' ) );
       		echo '</span>';
       	}
       }
       endif;
   
       /**
        * Determine whether blog/site has more than one category.
        *
        * @since Twenty Fifteen 1.0
        *
        * @return bool True of there is more than one category, false otherwise.
        */
       function twentyfifteen_categorized_blog() {
       	if ( false === ( $all_the_cool_cats = get_transient( 'twentyfifteen_categories' ) ) ) {
       		// Create an array of all the categories that are attached to posts.
       		$all_the_cool_cats = get_categories( array(
       			'fields'     => 'ids',
       			'hide_empty' => 1,
   
       			// We only need to know if there is more than one category.
       			'number'     => 2,
       		) );
   
       		// Count the number of categories that are attached to the posts.
       		$all_the_cool_cats = count( $all_the_cool_cats );
   
       		set_transient( 'twentyfifteen_categories', $all_the_cool_cats );
       	}
   
       	if ( $all_the_cool_cats > 1 ) {
       		// This blog has more than 1 category so twentyfifteen_categorized_blog should return true.
       		return true;
       	} else {
       		// This blog has only 1 category so twentyfifteen_categorized_blog should return false.
       		return false;
       	}
       }
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Template-tags.php & Child Theme’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/twentyfifteen/4.2/screenshot.png)
 * Twenty Fifteen
 * [Support Threads](https://wordpress.org/support/theme/twentyfifteen/)
 * [Active Topics](https://wordpress.org/support/theme/twentyfifteen/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/twentyfifteen/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/twentyfifteen/reviews/)

## Tags

 * [child](https://wordpress.org/support/topic-tag/child/)
 * [childtheme](https://wordpress.org/support/topic-tag/childtheme/)
 * [template tags](https://wordpress.org/support/topic-tag/template-tags/)

 * 3 replies
 * 2 participants
 * Last reply from: [caroline](https://wordpress.org/support/users/makeupedia/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/template-tagsphp-child-theme/#post-6439102)
 * Status: resolved