Support » Plugins and Hacks » [Plugin: Yoast Breadcrumbs] Exclude categories?

  • Yoast,

    I tried to figure out how to do this on my own but couldnt.

    Is there a way to exclude specific categories in any way. Because I have a featured category, and it appears that your plugin chooses categories alphabetically, all posts in this category show that category where as Id prefer they were to display their more related category.

Viewing 3 replies - 1 through 3 (of 3 total)
  • @rythmdoctor, I also needed this functionality. I had already written a function to remove unwanted categories from any get_the_category result, so I was able to add just one line to Yoast’s plugin.

    Put the following code in your functions.php. Change 30,31,32 to the ID(s) you wish to exclude.

    function get_the_category_exclusions($categories) {
    	$args = array(
    		'categories' => $categories,
    		'exclude'    => '30,31,32'
    	);
    	return exclude_categories($args);
    }
    
    function exclude_categories($args) {
    	$count = 0;
    	foreach ($args['categories'] as $category) {
    		if(strpos($args['exclude'],$category->cat_ID)){
    			unset($args['categories'][$count]);
    		}
    		$count++;
    	}
    	$categories = $args['categories'];
    	return array_values($categories);
    }

    Then on yoast-breadcrumbs.php add the following after $cats = get_the_category(); (approx line:232).

    $cats = get_the_category_exclusions($cats);

    This solution is tested and working for WP v2.8.4 Plugin v0.8.4

    john.andrews, thank you very much for this function.

    Worked fine for my site 🙂

    Thanks.

    Ok, it’s not working right.

    I choose to exclude the category id ’50’, but it excludes the ’50’ and ‘5’ too 🙁

    Any help?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Yoast Breadcrumbs] Exclude categories?’ is closed to new replies.