Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using widgets outside the sidebar?

Tags:

wordpress

Is it possible to use widgets outside of the sidebar? When you assign them in the admin panel you have to drag them to your sidebar but I would like to implement a search function outside the sidebar. Can I do this?

like image 910
vincent Avatar asked Sep 09 '10 11:09

vincent


People also ask

Can sidebar be customized?

You can customize your sidebar in the WordPress Customizer tool, or on the Widgets page in the dashboard.

What are WordPress sidebar Widgets?

A sidebar is a widgetized area of your WordPress website, where you can display content that isn't part of the main webpage. This secondary content is added to your website via widgets—for example, you might use a widget to display a list of your most recently published blogs, a tag cloud, or a search bar.


2 Answers

The correct answer is use the_widget()

I used it to integrate a widget into my own custom widget. Check out the codex for details on how to use it.

like image 133
Vlad Socaciu Avatar answered Oct 02 '22 18:10

Vlad Socaciu


Absolutely. This thread in the WordPress support forums should get you going. It creates a new widget area ready called Homepage that can then be used in any of your theme's template files:

Your theme's functions.php

if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'name'=> 'Main',
        'id' => 'main',
        'before_widget' => '<div class="widget_box side">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
    register_sidebar(array(
        'name'=> 'Homepage',
        'id' => 'homepage',
        'before_widget' => '<div class="widget_box">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
}

The template file you want the Homepage widget in

<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Homepage')) : ?>

Alternatively, you can use the My Custom Widgets plugin to do the same thing.

like image 43
Pat Avatar answered Sep 28 '22 18:09

Pat