Sidebar on 'Posts' (only, not pages)

Related to this thread: https://theme.co/apex/forum/t/new-sidebar-widget-not-showing/30375

After using that code in the thread, we notice that pages are showing the sidebar container. We only need that on posts. Xpro is recognizing pages as “content” it seems? How can we get a sidebar on ‘post’ only.

Thanks!

Hi there,

Please try:

add_filter( 'ups_sidebar', 'post_sidebar' );

function post_sidebar($sidebar){

	if(is_singular( 'post' )) {
		return 'sidebar-main';
	}
	return $sidebar;
}

Hope this helps.

Thanks, Jade, but that didn’t work.

I still have a blank container showing the space where a sidebar should be. https://www.screencast.com/t/xkW74SrBGsmB

The sidebar content doesn’t show on pages, just the blank container. We need just one main container on pages.

Thanks!

Hi There,

Thanks for the clarification but that is not the case on our end (your pages has no sidebar https://prnt.sc/jhw323), please clear your browser cache.

The code provided by Alaa on other thread should not affect the pages, because of the if(is_singular( 'post' ) in it. It could be from your other customization.

Cheers!

Hi, there is no customization related to this. When I emailed you, I put the settings back to full width because it was messing up all the ‘page’ pages on the site.

In the customizer, I followed the original instructions for a sidebar. I selected "Content left, Sidebar right " in Layout. The sidebar is showing on both pages and posts, not just posts. The sidebar content shows up on the ‘post’ pages where it should, but all the ‘page’ pages get an empty sidebar—where it should be full width. I don’t want a sidebar on pages, but it’s showing up when I select "Content left, Sidebar right ". How do I make all ‘page’ pages full-width and still show the sidebar on posts?
https://www.screencast.com/t/fHjjzXKBa I re-set back to normal right now. So you won’t see a sidebar or an empty container.

Thanks!

Hi,

To add sidebar to your post, please add the code below in your child theme’s functions.php file

function add_mysidebar_post($layout){
    if(is_singular('post')){
        $layout = "content-sidebar";
    }
    return $layout;
}

add_filter('x_option_x_layout_content', 'add_mysidebar_post',999);

The filter to change the layout should be x_option_x_layout_content not ups_sidebar

Hope that helps.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.