Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I run a horror related blog. Google is upset with me for displaying adsense in a sidebar widget for one specific post number (4603) that contains an article about an 18+ topic. How can I disable the widgets for a specific id?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

I'd recommend the plugin Widget Logic to handle all your needs. You can just add logical tags to the individual widgets on the sidebar.

share|improve this answer
this worked, thanks! –  Poe Apr 24 '13 at 15:33

You can filter sidebars_widgets and remove the widget you don’t need.

Example with a search widget; uncomment the debug code to find the correct identifier.

if ( ! is_admin() )
    add_filter( 'sidebars_widgets', 'remove_specific_widget' );

function remove_specific_widget( $widgets )
    if ( ! is_single( 402 ) ) // Post ID, title, slug, or array of such
        return $widgets;

    if ( ( $key = array_search( 'search-3', $widgets['primary-widget-area'] ) ) !== FALSE ) {
        unset( $widgets['primary-widget-area'][ $key ] );

    // use this to inspect the current widget parameters
    //print '<pre>$widgets = ' . htmlspecialchars( var_export( $widgets, TRUE ), ENT_QUOTES, 'utf-8', FALSE ) . '</pre>';

    return $widgets;
share|improve this answer
looking forward to testing this code, thanks! –  Poe Apr 24 '13 at 15:34

I'd recommend Widget Manager Light or Display Widgets plugin for this. It's easier than using conditional tags or any code. You can see details on here.

Widget Manager Light let's you chose which widget to show on which post easily.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.