• Resolved Nirr

    (@nirmithamw)


    Hello!

    I need to exclude showing categories & tags on Google.
    So, I’ve turned on Hide from search results option for Categories & tags.

    However, for the post that I publish after installing Slim SEO,
    It’s showing the “Category” path, instead of Website name or Post URL.

    Why this happen and how to fix this?

    Note:- I’ve also turned of breadcrumbs shortcode option.

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

    (@stranger03)

    Hello Nirr! The breadcrumbs you see in search results are derived from schema markup.
    This filter should help:

    add_filter( 'slim_seo_breadcrumbs_links', function( $links ) {
        if ( is_singular( 'post' ) ) {
            unset( $links[1] );
        }
        return $links;
    } );

    To ensure that the category is no longer visible in the schema markup, check the post page here:
    https://search.google.com/test/rich-results

    Thread Starter Nirr

    (@nirmithamw)

    Thanks for the reply, Dmitry!

    I tried that snippit, and unfortunately it didn’t work for me.

    However, I created the below snippet with the help of ChatGPT and it did work!

    add_filter( 'slim_seo_breadcrumbs_links', function( $links ) {
    if ( is_singular() ) { // For singular posts, pages, or custom post types
    foreach ( $links as $index => $link ) {
    if ( strpos( $link['url'], '/category/' ) !== false ) {
    unset( $links[$index] );
    }
    }
    $links = array_values( $links ); // Reindex the array
    }
    return $links;
    });

    Or this?

    add_filter( 'slim_seo_breadcrumbs_links', function( $links ) {
    // Filter the links to remove any that contain '/category/'
    $links = array_filter( $links, function( $link ) {
    return strpos( $link['url'], '/category/' ) === false;
    });

    // Reindex the array after filtering
    $links = array_values( $links );

    return $links;
    });

    I think 2nd code is more concise and efficient.

    Which do you recommend @anh Tran? Can we use them safely?

    • This reply was modified 1 month, 1 week ago by Nirr.
    • This reply was modified 1 month, 1 week ago by Nirr.
    Plugin Author Anh Tran

    (@rilwis)

    Hi @nirmithamw and @stranger03

    Your snippets are correct and safe to use. Glad that you guys figured it out!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.