[Support request] back button to parent category

Home Forums Support [Support request] back button to parent category

Home Forums Support back button to parent category

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #557718
    arbeni

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

    #558160
    Leo
    Staff
    Customer Support

    Hi there,

    I believe you are looking for breadcrumbs.

    Check out YoastSEO.

    Let me know if this helps.

    #559034
    arbeni

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

    #559695
    Tom
    Lead Developer
    Lead Developer

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

    #559763
    arbeni

    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

    #560228
    Tom
    Lead Developer
    Lead Developer

    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 );
        }
    }
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.