• Resolved haizdesign

    (@haizdesign)


    Is there code I can add to a template that checks if a custom sidebar is being used, and if not, display other content?

    This is for a custom post type that has it’s own sidebar-cpt.php

    In my site I have set my sidebar with an ID of sidebar-1 to be replaced. I have tried this without success:

    if ( is_active_sidebar( 'sidebar-1' ) ) {
        return;
    }
    
    // alternate content here

    I have also tried changing the sidebar-1 string for CustomSidebars and csb_clone.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello @haizdesign

    Hope you’re doing well!

    Would you please elaborate and provide more information about what you wish to achieve? The Custom Sidebars plugin allows showing sidebars on a custom post type pages out of the box. Click on SideBar Location link and select custom post type from the list

    Make sure that the sidebar for custom content sidebar-cpt.php is allowed to be replaced. Please see this screenshot

    If there is no custom sidebar assigned, it will show a default sidebar.

    Please advise,

    Kind regards,
    Nastia

    Thread Starter haizdesign

    (@haizdesign)

    Hi Nastia,
    Thanks for your reply and the screenshots. I have resolved my issue and your response made me realise I was overthinking it!

    My custom post type used a template that called in it’s own sidebar. (In my functions.php it’s called sidebar-projects). This sidebar had a few custom queries pulling in related content. I wanted to be able to use this sidebar?to either display the queries or be replaceable. After making sure I checked the box to allow this sidebar to be replaced, I put some conditional code in my template:

    <?php 
        if ( dynamic_sidebar('sidebar-projects') ) { 
            return;
    } else ?> 
    
    // other code here

    Thanks for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Check if has custom sidebar’ is closed to new replies.