0

I have created a custom sidebar widgets using below code :

register_sidebar(array(
        'id' => 'sidebar-widget-1',
        'name' => 'Sidebar Widget 1',
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '',
        'after_title' => '',

    ));

and it is showing in Appearance -> Widgets and it is also showing content on frontend using dynamic_sidebar('Sidebar Widget 1').

But I want to get content of this register_sidebar by using its id into a variable.

How to get sidebar content by using its id?

0

In your sidebar.php or any other custom sidebar file call by ID like this

<?php get_sidebar('sidebar-widget-1'); ?>

Not like this

<?php get_sidebar('Sidebar Widget 1'); ?>

See the difference, I used ID in get_sidebar() function instead of name.

Now where ever you want sidebar appear in front-end, there call it like this

<?php get_sidebar('sidebar-widget-1'); ?>
  • Hello @Rishabh, I want to get sidebar content one by one with all options in a variable. – Vinaya Maheshwari Dec 28 '16 at 8:57
  • @Vinaya Maheshwari Sorry, Didn't get your point. What u mean by one by one and options of what variable? – Rishabh Dec 28 '16 at 9:26

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.