Hello. The question is: How can I (without using plugins) remove the sidebar from the Record Page?

My actions: There are pages: Home, Blog, Contact

  1. Copying index.php - index-blog.php. In it I add the Template name: blog index-blog.php and remove get_sidebar ();
  2. Go to admin panel, open Pages - Blog - Edit - Template - use the template index-blog.php (Sidebar on the Blog page is missing)
  3. I pass Settings - Reading. I choose the Record Page - Blog.
  4. I go to the site - the Blog page - Sidebar is displayed.

If I understand correctly, the problem lies in the hierarchy of files, but I cannot understand exactly what the error is. I beg your advice

Thank you in advance!

    2 answers 2

    Make the output sidebar conditional, to do this, open the template editor, select the main page (index.php) and wrap it in if.

    However, there is no check function on the blog, so a crutch is needed. Write to the very bottom of the file

    function is_blog () { global $post; $posttype = get_post_type($post ); return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ; 

    }

    Then where do you get the sidebar output?

     <?php if (!is_blog()) { get_sidebar(); } ?> 

    This way the sidebar will be displayed on all pages except the blog.

      Depends on the topic. In general, it is sufficient to remove the call to the saibar from the recording template .

      But for any change in themes, it is worth using the mechanism of child themes .

      In addition, since version 4.7, VP has the opportunity to create post templates similar to page templates .