5

Is there a way that i can place a certain widget anywhere on the site?

For example:

I'm using the text widget in my sidebar, for the title I put YouTube, and I placed the YouTube embed code in it. But I want that widget to go at the top of the site. How do I make this possible, while still using the widgets menu, but not show up in the sidebar, but wherever I place it?

If it's not possible, does anyone know of a YouTube sidebar widget, one that can let you place the widget code anywhere on the site and also do it from the widgets menu?

1
  • you need to create a custom widget area in your theme , and then in the widgets menu assign the widget to that area.
    – krembo99
    Mar 9, 2012 at 2:59

2 Answers 2

3

Just register another widget area. Don’t take the name sidebar literally, you can use the fields anywhere on your page.

In your theme’s functions.php:

add_action( 'after_setup_theme', 'register_multiple_widget_areas' );

function register_multiple_widget_areas()
{
    register_sidebar(
        array(
        'name'          => 'Sidebar',
        'id'            => 'sidebar',
        'description'   => 'describe the function of the box.'
        )
    );
    register_sidebar(
        array(
        'name'          => 'Header',
        'id'            => 'header-widget',
        'description'   => 'Goes at the top of the page.'
        )
    );
}

And wherever you need the header widget call:

dynamic_sidebar( 'header-widget' );

See also register_sidebar() and dynamic_sidebar().

0
2

You can use the_widget():

the_widget(
    'WP_Widget_Archives',
    [
        'title'    => __( 'Archives', 'your-textdomain' ),
        'count'    => true,
        'dropdown' => true,
    ],
    [
        'before_widget' => '<section class="widget__container">',
        'after_widget'  => '</section>',
        'before_title'  => '<h2 class="widget__title">',
        'after_title'   => '</h2>',
    ]
);
3
  • and add what to it, the title of the text widget? Mar 9, 2012 at 0:05
  • I guess you need to re-write your Q. I'm not quite sure if I understand.
    – kaiser
    Mar 9, 2012 at 1:12
  • details. arguments.
    – ahnbizcad
    Mar 25, 2016 at 2:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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