Template Parts: A Hestia Example

Let's say your theme is showing something on your pages and posts, but you aren't sure where to go to get rid of it. You've checked the Customizer and there is no option to remove.

In my example, we are looking at Hestia. Here's our category archive.

We've got a portfolio here, so we might not want or need the word 'Category'. We might just want it to say 'My Work'.

By looking at archive.php (WordPress's default category archive template), something jumps out at us right away.

<?php the_archive_title( '<h1 class="hestia-title">', '</h1>' ); ?>

So, it's easy to know WHERE we want to make our change. But, how do we get rid of 'Category:'?

Some template tags are what we call 'extendable'. We are going to write a quick function in functions.php to change how 'the_archive_title' works. Here's what we'll add to functions.php.

add_filter( 'get_the_archive_title', function ($title) 
        if ( is_category() ) 
        { $title = single_cat_title( '', false ); 
            return $title;

Do you see what this does? We are emptying out the title title variable and echoing it back out again so that it only contains our single title and nothing else.

Now our page looks like this (see below).

Ok, what else do we see in the screenshot above?

I see post dates and author info. That's going to be inside of our all-purpose content.php.

 <div class="author">
                        /* translators: %1$s is Author name wrapped, %2$s is Time */
                        esc_html__( 'By %1$s, %2$s', 'hestia' ),
                        /* translators: %1$s is Author name, %2$s is author link */
                            '<a href="%2$s" title="%1$s" class="vcard author"><strong class="fn">%1$s</strong></a>',
                            esc_html( get_the_author() ),
                            esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) )
                            /* translators: %1$s is Time since post, %2$s is author Close tag */
                            esc_html__( '%1$s ago %2$s', 'hestia' ),
                                /* translators: %1$s is Time since, %2$s is Link to post */
                                '<a href="%2$s"><time>%1$s</time>',
                                esc_html( human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) ),
                                esc_url( get_permalink() )
                    <time class="date updated published" datetime="<?php echo esc_html( get_the_date( DATE_W3C ) ); ?>"><?php echo esc_html( get_the_time( get_option( 'date_format' ) ) ); ?></time>

Do you see how all of that code is encaspsulated within the "author" div? You would delete everything in the above code block to remove the author and date from our content.

Click on a post and you'll see some dates again.

I've shown you how to go into a template file and delete them, but we could also use css through the 'Additional CSS' panel in the theme's Customizer. Inspecting the html of a single post shows me a header 4 (h4) element with an author class. See rendered html and the source code view the element inspector in the screenshot below.

I could use the following to hide it.

h4.author { display: none }