Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to show a widget in only one page of my site, as i can see it is not possible right?

Should i add that for all my site pages or not?

share|improve this question
Is this a custom theme or a custom widget? – toscho Dec 22 '12 at 13:56
custom theme, FashionStyle from SMthemes dot com – Badaboooooom Dec 22 '12 at 14:47
Widget Display Options Another Plugin that does this – Scott Apr 18 at 0:31

3 Answers

It depends on where you want to show the widget.

Let’s start with the widget area (sidebar) registration:

add_action( 'wp_loaded', 'wpse_76959_register_widget_area' );
function wpse_76959_register_widget_area()
{
    register_sidebar(
        array (
            'name'          => __(
                'Widgets on page Sample Page',
                'theme_textdomain'
                ),
            'description'   => __(
                'Will be used on a page with a slug "sample-page" only.',
                'theme_textdomain'
                ),
            'id'            => 'sample-only',
            'before_widget' => '<div id="sample-only-widget">',
            'after_widget'  => '</div>',
            'before_title'  => '<h2>',
            'after_title'   => '</h2>',
        )
    );
}

This is quite simple. We register a new widget area with some custom markup.

enter image description here

Now we have to show it somewhere. We could add a custom action in our page.php template:

do_action( 'show_sample_widget' );

Or we could use an existing action, this would limit the places where the widget is available. For example the action loop_start is called the first time we call the_post() in a loop. If we want to set the widget on top of the page content, we use that hook:

add_action( 'loop_start', 'wpse_76959_render_widget' );

function wpse_76959_render_widget()
{
    is_page( 'sample-page' ) && dynamic_sidebar( 'sample-only' );
    remove_action( current_filter(), __FUNCTION__ );
}

For a custom action we’d use instead:

add_action( 'show_sample_widget', 'wpse_76959_render_widget' );
share|improve this answer

There are several plugins that allow to show widgets based on specific conditions:

An alternative solution is given by the following plugin, which allows you to define a custom set of widgets on a per-page basis, directly from the edit page screen:

share|improve this answer

It's possible. The easiest way is to use a plugin such as http://wordpress.org/extend/plugins/display-widgets/

share|improve this answer

Your Answer

 
discard

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.