Forums

Adding a Sidebar to a theme with two other sidebars (23 posts)

  1. mjuanstudio
    Member
    Posted 11 months ago #

    I am trying to add an additional sidebar (with widgets) to my site which already has two other sidebars. I have gone through numerous instructions that I have found via WordPress and have been unable to add a new sidebar.

    I followed these directions:
    New way of adding sidebars

    I got up to where it states "you have to create a custom sidebar-file under the name sidebar-custom.php."

    The next step would be to see my sidebar under my appearance tab but it is not there.

    Help!

  2. Chip Bennett
    Member
    Posted 11 months ago #

    We'll need to see your actual code, in order to help.

  3. mjuanstudio
    Member
    Posted 11 months ago #

    What part of the code do you need to see?

  4. Chip Bennett
    Member
    Posted 11 months ago #

    The code you're using to add the additional sidebar.

  5. mjuanstudio
    Member
    Posted 11 months ago #

    This is in my widgets.php file

    [Code moderated as per Forum Rules - please use the Pastebin]

  6. Chip Bennett
    Member
    Posted 11 months ago #

    That is Widget-registering code, not dynamic sidebar-registering code.

    Can you post the code you're using to register your sidebar?

    (Also: forum rules require any code longer than about 10 lines to be added to a Pastebin, and linked in the topic.)

  7. mjuanstudio
    Member
    Posted 11 months ago #

    That is the only code that I have put in thus far. I stopped at this instruction because i did not see my sidebar listed under my widgets. I am unsure what my next step would be.

  8. Chip Bennett
    Member
    Posted 11 months ago #

    None of the code you added actually registers a sidebar.

    You need to register a sidebar in order for it to appear.

    See here: http://codex.wordpress.org/Function_Reference/register_sidebar

  9. mjuanstudio
    Member
    Posted 11 months ago #

    This is what I added in the widgets.php file:

    register_sidebar(array(
      'name' => 'custom',
      'description' => 'Widgets in this area will be shown on the right-hand side.',
      'before_title' => '',
      'after_title' => ''
    ));
    <?php if ( function_exists ('register_sidebar')) {
        register_sidebar ('custom');
    } ?>
  10. Chip Bennett
    Member
    Posted 11 months ago #

    Take out this bit:

    <?php if ( function_exists ('register_sidebar')) {
        register_sidebar ('custom');
    } ?>
  11. mjuanstudio
    Member
    Posted 11 months ago #

    So then where will I see my new sidebar. RIght now it is still pulling the old one even though I have named it 'custom' in my index file.

  12. Chip Bennett
    Member
    Posted 11 months ago #

    You need to hook that register_sidebar() call into the widgets_init hook.

  13. mjuanstudio
    Member
    Posted 11 months ago #

    Im sorry. Looking and cant find the widgets_init hook. Where would I find it?

  14. Chip Bennett
    Member
    Posted 11 months ago #

    You need to do something like this:

    function mytheme_register_sidebars() {
         register_sidebar(array(
              'name' => 'custom',
              'description' => 'Widgets in this area will be shown on the right-hand side.',
              'before_title' => '',
              'after_title' => ''
         ));
    }
    add_action( 'widgets_init', 'mytheme_register_sidebars' );
  15. mjuanstudio
    Member
    Posted 11 months ago #

    I customized it:

    function sdttheme_register_sidebars() {
         register_sidebar(array(
              'name' => 'custom',
              'description' => 'Widgets in this area will be shown on the right-hand side.',
              'before_title' => '',
              'after_title' => ''
         ));
    }
    add_action( 'widgets_init', 'sdttheme_register_sidebars' );

    Is this correct? What would be my next step from here/

  16. Chip Bennett
    Member
    Posted 11 months ago #

    Now, go to Dashboard -> Appearance -> Widgets

    Do you see your Sidebar listed?

  17. mjuanstudio
    Member
    Posted 11 months ago #

    no. Still only two.

  18. Chip Bennett
    Member
    Posted 11 months ago #

    Can you move that function and add_action call out of your widgets.php file, and directly into your functions.php file, just for testing?

  19. Chip Bennett
    Member
    Posted 11 months ago #

    Oh, wait: try hooking into 'after_setup_theme' rather than 'widgets_init'.

    i.e.:

    add_action( 'after_setup_theme', 'sdttheme_register_sidebars' );
  20. mjuanstudio
    Member
    Posted 11 months ago #

    Actually putting it in the Functions file worked! I see it now in my widgets!

  21. mjuanstudio
    Member
    Posted 11 months ago #

    thanks!

  22. Chip Bennett
    Member
    Posted 11 months ago #

    Great! So now you just need to add the dynamic sidebar somewhere in your template, and you're good to go.

  23. moist
    Member
    Posted 7 months ago #

    I installed the WP Big City theme, now I want the move the sidebar from the right to the left.
    Please help me.
    Thx.

Reply

You must log in to post.

About this Topic