Site logo

Archived topic

back button to parent category

5 replies · Started by arbeni on April 23, 2018

Viewing posts 1–6 of 6

Hey there,
it is possible to insert a back button (single post) and return to the parent category?
Thanks

Hi there,

I believe you are looking for breadcrumbs.

Check out YoastSEO.

Let me know if this helps.

Thanks for the quick answer. But I just went back to the previous category

So this button would be a link to the category that the post belongs to? What if the post has multiple categories?

Hey Tom,
Yes this button would be a link to the category that the post belongs to.
- no post doesn't have multiple category

Thanks

Try this PHP:

add_action( 'generate_after_content', 'tu_add_category_link' );
function tu_add_category_link() {
    if ( is_single() ) {
        $category = get_the_category();
        $first_category = $category[0];
        printf( '<a class="category-button" href="%s">%s</a>', get_category_link( $first_category ), $first_category->name );
    }
}
This archived topic is closed to new replies.