0

I'm very new to WP theming and I know there are several types of functions to add Widget areas.

The following one, for example, adds a widget area dedicated for menus:

# functions.php (register a new widget area):

    function newMenuWidgetArea() {
    register_nav_menus(
    array (
    'my-custom-menu' => __('newMenu'),
    'extra-menu' => __('newMenu')
    )
    );
    }
    add_action('init', 'newMenuWidgetArea');

# header.php (declare widgets in the new area to appear):

    <?php
    wp_nav_menu(array (
    'theme_location' => 'newMenu',
    'container_class' => 'newMenu')
    );
    ?>

The problem:

I don't want to add custom menus manually for example, so I don't look for a functions that add menus and their widget areas manually.

I wish to add menus from the GUI, hence I am looking forward to use a function that create global widget areas that can serve for any purpose, and then I will add into them anything I wish directly from the GUI (menu, text area, or whatever other widget).

The question:

What is the general function to add a general-purpose/multi-purpose Widget area?

The one I have for now creates a menu. not a widget area in which I could place widgets.

3
  • what is the "widget area" that you ask about? your question seems to be all about menus. Please edit the question and clarify what is that you mean Commented Jun 3, 2017 at 18:37
  • This might help: codex.wordpress.org/Widgetizing_Themes
    – cjbj
    Commented Jun 3, 2017 at 18:40
  • I've now edited the question @MarkKaplun
    – user121038
    Commented Jun 3, 2017 at 19:09

2 Answers 2

0

Adding on mikesars answer, afterwards, one needs to Place the widget in a template file like header.php (for example).

So it would be:

functions.php:

if ( function_exists('register_sidebar') )
  register_sidebar(array(
    'name' => 'Name of Widgetized Area',
    'before_widget' => '<div class = "widgetizedArea">',
    'after_widget' => '</div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
  )
);

Template file:

<?php if ( !function_exists('dynamic_sidebar') || 
!dynamic_sidebar("Widgetized Area") ) : ?>
<?php endif;?>
0

i think youre looking for the register_sidebarfunction.

if ( function_exists('register_sidebar') )
  register_sidebar(array(
    'name' => 'Name of Widgetized Area',
    'before_widget' => '<div class = "widgetizedArea">',
    'after_widget' => '</div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
  )
);

with this you get a new WidgetArea in the widget section in the backend.

You would then need to choose where you want it to appear. For example, if you would want it somewhere in the header, add this there, with this could:

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Name of Widgetized Area") ) : ?>
<?php endif;?>
2
  • Oh, I came across this but was sure, because of the name, that these are always in vertical (from the left or from the right). Maybe it's just me effected by the terminology common in Bootstrap, instead of Wordpress.
    – user121038
    Commented Jun 3, 2017 at 20:49
  • yeah the name is confusing. but in fact its just creates an area where you can place widgets.
    – mikesar
    Commented Jun 3, 2017 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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