WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Yoast Breadcrumbs] Exclude categories? (4 posts)

  1. rhythmdoctor
    Member
    Posted 5 years ago #

    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.

  2. john.andrews
    Member
    Posted 4 years ago #

    @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

  3. SauloB
    Member
    Posted 4 years ago #

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

    Worked fine for my site :)

    Thanks.

  4. SauloB
    Member
    Posted 4 years ago #

    Ok, it's not working right.

    I choose to exclude the category id '50', but it excludes the '50' and '5' too :(

    Any help?

Topic Closed

This topic has been closed to new replies.

About this Topic