• Resolved invisionary

    (@invisionary)


    Hello,

    Please can you add an option to prevent the Posts link from being included in the Breadcrumb trail? Example below, where both the POSTS link and the NEWS link take a visitor to effectively the same page and POSTS is not normally accessible to site visitors but search bots will follow it.

    Many thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Dmytro – WPMU DEV Support

    (@wpmudevsupport16)

    Hello @invisionary,

    I hope you’re doing great today.

    From your screenshot I assume, that Posts is the top level category, and News is its subcategory.

    If the above is correct, could you please try adding the following PHP code snippet as a must use plugin:

    <?php
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }
    
    $root_category_name = 'Posts';
    $root_category_link = '/posts/';
    
    add_action( 'smartcrawl_breadcrumbs_after_prepare_items', function() {
    
            if ( ! is_singular('post') ) {
                return;
            }
            global $root_category_name;
            $categories = get_the_category();
            foreach ( $categories as $category) {
                
                $cat_id = $category->term_id;
                $parent_cat_ids = get_ancestors( $cat_id, 'category');
                $root_cat_id = count($parent_cat_ids) > 0 ? $parent_cat_ids[count($parent_cat_ids) - 1] : 0;
    
                if (get_the_category_by_ID($root_cat_id) === $root_category_name ){
                    add_action('wp_head', 'sc_breadcrumb_css', 999 );
                    return;
                }
    
            }
    
            return;
    
        
    }, 999);
    
    function sc_breadcrumb_css() {
            global $root_category_link;
    		?>
    
    		<style>
    		    span.smartcrawl-breadcrumb-separator:nth-child(4), .smartcrawl-breadcrumb a[href*="<?php echo $root_category_link; ?>"] {
                  display: none !important;
                }
    		</style>
    
    			<?php
    }

    Please replace Posts with the category name, and /posts/ with its link on these lines:

    $root_category_name = 'Posts';
    $root_category_link = '/posts/';

    Save the code as a PHP file in your text editor, for example: smartcrawl-remove-posts-category-breadcrumbs.php

    Finally, upload the saved file to /wp-content/mu-plugins/ directory on the server, and check the breadcrumbs after that.

    Hope this helps. Please let us know if you have further questions.

    Best Regards,
    Dmytro

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @invisionary

    I hope you are doing well.

    We haven’t heard from you in a while, I’ll go and mark this thread as resolved. If you have any additional questions or require further help, please let us know!

    Best Regards
    Patrick Freitas

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Preventing Posts from being included in Breadcrumbs’ is closed to new replies.