Home Forums General Issues Sidebar Selector bypass


Sidebar Selector bypass

  • Hello and thanks for this great plugin!

    I’m currently have ACF with the Sidebar Selector extension installed on a custom theme that sells advertising and is subscription based. It was painless to install and configure. Thanks for that. All of my sidebars showed up immediately.

    The site currently calls in a specific sidebar based on category using this code

    		if( in_category('example') ) {
    		} else {
    			is_user_logged_in() ? get_sidebar("primary") : get_sidebar("visitor");
    	} ?>

    This works exactly how I need it to 99.9% of the time. However, there are going to be times when I want to override this and use a different sidebar, which is why I installed ACF with the sidebar extension. Can you recommend a way to bypass or nullify the above command and allow me to select a sidebar in the editor?

    Thanks in advance.

    GG Jindrak

  • for example you may try something like this in your functions.php

    add_action('get_sidebar', 'special_sidebar');
    function special_sidebar($sidebar) {
      $new_side_bar = get_field('ACFSideBarField');
      if ($new_side_bar) {
        return $new_side_bar;
      return $sidebar;

    it will change the $name in get_sidebar($name)

  • I’m certainly no php master, here. Do I need to change $sidebar to the name of my new sidebar?

    If so, I can just do this for every one of my sidebars?

  • You have to change $new_side_bar = get_field(‘ACFSideBarField‘)
    ACFSideBarField to your custom-sidebar-name-field slug.
    And thats all

    Every time when wordpress will try to call function get_sidebar() it will check existance of the field ACFSideBarField in curent post and if find will change the name of sidebar for loading.

    Sorry for my english )) I speak russian most of time =)

    P.S. that code block was for functions.php of your template. Just place it for example at the end of file

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Sidebar Selector bypass’ is closed to new replies.