0
votes

I faced the following issue: Can't remove Sidebar from the Posts page (in the native way without using plugins)

My steps:

We have 3 pages: Home, Blog, Contact

  1. Copying index.php - index-blog.php. Add to the new file Template name:blog and remove get_sidebar();
  2. Go to WP admin, Open pages - choose Blog - Edit - Templates - apply blog template (Sidebar is hidden on the Blog page)
  3. Go Settings - Reading. Choose Posts Page - Blog.
  4. Go back to the site - Blog page - Sidebar is shown.

Can assume there is an issue with files' hierarchy, but have no clue where I've made a mistake. Asking you to advice in this question

Thanks a lot in advance!

2

2 Answers

2
votes

When you set your blog page via Settings -> Reading, WordPress is skipping the template you choose for that page and will load index.php if there isn't a specific category template (see more about template hierarchy: https://developer.wordpress.org/themes/basics/template-hierarchy/).

So if you want your index-blog.php to be the template for your blog, you have to leave the 'Choose Posts Page' blank and only set your Blog page (Pages -> Blog) to use the blog template.

0
votes

For a template to be used you can set it on a page you have set to be the “post page” in your settings reading. Just leave the settings > reading select box for post page blank.