• Resolved Johnny

    (@johnny18sg)


    Dear Ben,

    I created a Custom Post Type (CPT) called word. Unlike posts, I am not able to set the Layout to “No Sidebar” in the Customizer.

    The link provided shows the single post of word with the right and left sidebars.

    How do I change the Layout to “No Sidebar” for this CPT?

    Appreciate your help.

    Thank you.

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Theme Author Ben Sibley

    (@bensibley)

    Hi Johnny,

    Are you familiar with writing and editing PHP? I can point you in the right direction to edit this code, but I’m afraid there isn’t currently an option in Mission News for changing the layouts of custom post types.

    Thread Starter Johnny

    (@johnny18sg)

    Yes, I am familiar with php. Please direct me.

    Thank you.

    Theme Author Ben Sibley

    (@bensibley)

    Okay great!

    The first step is to activate a child theme. You can download a starter child theme for Mission News here: https://www.competethemes.com/help/child-theme-mission-news/

    Then add this function into the functions.php file:

    function mission_news_cpt_layout_class( $classes ) {
    
    	if ( is_singular( 'word' ) ) {
    		$classes[] = 'layout-no-sidebar';
    	} 
    	return $classes;
    }
    add_filter( 'body_class', 'mission_news_cpt_layout_class' );

    You might have to rename “word” to the exact string you named your CPT with. That function is going to apply the no sidebar styles to the CPT pages.

    Next, copy both the sidebar-left.php and sidebar-right.php files into the child theme. Then add this to the top of both files:

    if ( is_singular( 'word' ) ) {
      return;
    }

    That will prevent the sidebars from being output on the CPT pages. Again, the string “word” might need to be adjusted here.

    Thread Starter Johnny

    (@johnny18sg)

    Works perfectly!

    Thank you much for taking time to help me ??

    Theme Author Ben Sibley

    (@bensibley)

    You’re welcome! Glad I could help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Layout for Custom Post Types’ is closed to new replies.