1

I'm currently using twentyseventeen child theme and I need to modify the link on single post page below the article. His href is forwarding to category of the post.

I'm pretty new to filters in wp so I really don't know which filter should I use in this case. Also i would love to know, how could i know or where to find these filters?

2 Answers 2

2

The category link that you are referring to, that is displayed beneath the single post page content is not added with a filter. It is displayed via a function called twentyseventeen_entry_footer().

If you take a look at the themes files you can find the function on line #59, within the file:

/wp-content/themes/twentyseventeen/inc/template-tags.php

Here is the twentyseventeen_entry_footer() functions code:

if ( ! function_exists( 'twentyseventeen_entry_footer' ) ) :
    /**
     * Prints HTML with meta information for the categories, tags and comments.
     */
    function twentyseventeen_entry_footer() {

        /* translators: used between list items, there is a space after the comma */
        $separate_meta = __( ', ', 'twentyseventeen' );

        // Get Categories for posts.
        $categories_list = get_the_category_list( $separate_meta );

        // Get Tags for posts.
        $tags_list = get_the_tag_list( '', $separate_meta );

        // We don't want to output .entry-footer if it will be empty, so make sure its not.
        if ( ( ( twentyseventeen_categorized_blog() && $categories_list ) || $tags_list ) || get_edit_post_link() ) {

            echo '<footer class="entry-footer">';

            if ( 'post' === get_post_type() ) {
                if ( ( $categories_list && twentyseventeen_categorized_blog() ) || $tags_list ) {
                    echo '<span class="cat-tags-links">';

                        // Make sure there's more than one category before displaying.
                    if ( $categories_list && twentyseventeen_categorized_blog() ) {
                        echo '<span class="cat-links">' . twentyseventeen_get_svg( array( 'icon' => 'folder-open' ) ) . '<span class="screen-reader-text">' . __( 'Categories', 'twentyseventeen' ) . '</span>' . $categories_list . '</span>';
                    }

                    if ( $tags_list && ! is_wp_error( $tags_list ) ) {
                        echo '<span class="tags-links">' . twentyseventeen_get_svg( array( 'icon' => 'hashtag' ) ) . '<span class="screen-reader-text">' . __( 'Tags', 'twentyseventeen' ) . '</span>' . $tags_list . '</span>';
                    }

                    echo '</span>';
                }
            }

            twentyseventeen_edit_link();

            echo '</footer> <!-- .entry-footer -->';
        }
    }
endif;

As you should see from the original function code, the first line is:

if ( ! function_exists( 'twentyseventeen_entry_footer' ) ) :

So, if the function already exists the code in the parent theme will be ignored. Due to the way WordPress works, it loads the child themes functions.php file first, before the parent theme.

In order to modify this code you would copy or create your own twentyseventeen_entry_footer() function within your child themes functions.php file (without the function_exists() line, and without the final endif; line).

Therefore, by creating the twentyseventeen_entry_footer() function within your child theme, this will override the default functionality of the parent themes function.

Update To remove this category link completely with a template override:

On line #24 of the Twenty Seventeen themes single.php file, you should see the following code:

get_template_part( 'template-parts/post/content', get_post_format() );

If you then look in the folder referenced in the line above:

/wp-content/themes/twentyseventeen/template-parts/post/

You will see various 'content' PHP files for the various post formats. The default one for normal posts is content.php

Simply copy this file to your child theme within a new folder called in your child theme called /template-parts/post/ and then remove the lines that references the twentyseventeen_entry_footer() function (lines #73-#77):

<?php
if ( is_single() ) {
    twentyseventeen_entry_footer();
}
?>

You can use template overrides for any template files in the parent themes root folder or within the /template-parts/ folder. Simply copy the file to your child theme in the same folder structure.

NB. However, it might be simpler, in this particular case, to just create an empty/blank twentyseventeen_entry_footer() function in your child theme - it just depends whether you would still want this function to work for other post types or post formats (if it's used elsewhere)...

2
  • you are god, big thanks for that complicated answer. i don't wanna remove the link, but for my future learning i would really appreciate if you shortly describe how could it be done. Commented Apr 10, 2018 at 20:11
  • @Facegame_Cz - I've just updated my answer to explain how to do a template override for you too. Glad I could help. Don't forget to upvote my answer too, it's greatly appreciated! ;-)
    – Mat
    Commented Apr 10, 2018 at 20:39
0

I coming late to this party, but I have just found that the method suggested above is NOT recommended.

Refer this post ("get_parent_theme_file_path vs. get_template_directory") and this article ("get_theme_file_uri and get_theme_file_path") (mentioned in the post). They are both authored by Bravokeyl.

As noted above, the display of post footer is driven by the function "twentyseventeen_entry_footer" on line #59 of '/wp-content/themes/twentyseventeen/inc/template-tags.php'. The question that bugged me was... 'how did the system know to activate this function?'. If you look at the parent 'functions.php' lines #566-#586, you can see that all the files in the 'inc' folder are "required'. This is the trigger to activate "twentyseventeen_entry_footer". The method used to "require" the 'inc' folder files uses a new function (from Vn4.7) called "get_parent_theme_file_path".

Bravokeyl provides an excellent discussion of what the function does and why. There's also an example of how one can/should move control of the included files from the parent to the child theme.

In my case, I created a new folder (inc) in my child theme and I copied the parent template-tags.php to a copy in the child. Here's my code for template-tags.php. It worked a treat and is much easier and more reliable than the alternatives suggested.

add_filter('parent_theme_file_path','twentyseventeen_parent_template_tags',10,2);
function twentyseventeen_parent_template_tags($path,$file){
    if('inc/template-tags.php' == $file) {
        $gsd=get_stylesheet_directory();
        $file = 'inc/template-tags.php';
        $path = $gsd."/".$file;
 }
 return $path;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.