Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Hide WordPress' Categories widget on certain pages
<?php
/*
Plugin Name: Hide Categories Listing
Plugin URI: http://tarskitheme.com/
Description: Hide the Categories widget on certain pages.
Author: Benedict Eastaugh
Version: 1.0
Author URI: http://extralogical.net/
*/
function maybe_hide_categories_widgets($sidebars) {
if (!(is_page() || is_single())) return $sidebars;
// Add page IDs to this list, e.g.
// $hide_categories_on = array(1, 4, 9);
$hide_categories_on = array();
if (in_array(get_the_ID(), $hide_categories_on)
|| get_post_meta(get_the_ID(), 'hide_categories', true))
foreach($sidebars as $id => $sidebar)
foreach($sidebar as $i => $widget)
if (strpos($widget, "categories-") === 0)
unset($sidebars[$id][$i]);
return $sidebars;
}
add_filter('sidebars_widgets', 'maybe_hide_categories_widgets');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.