How to change the selected Template using javascript?

You are already using the correct action, i.e. wp.data.dispatch( ‘core/editor’ ).editPost(), however, you should instead change the property named template. I.e. wp.data.dispatch( ‘core/editor’ ).editPost( { template: ‘article.php’ } ) Yes, _wp_page_template is the meta key in the database, but in the REST API, a property named template exists in place of direct access on that … Read more

How WP determines archive page vs single page?

TL;DR: WordPress uses URL query string variables to select a template based on the Template Hierarchy. General template selection steps Permalink structures are used to create rewrite rules. Rewrite rules take a pretty permalink URL and convert it into a plain URL with a query string. Parameters from the query string are used to choose … Read more

In 2016 theme, how can I force all single attachment posts to use content-attachment.php rather than image.php?

There’s a couple things you could do. If we follow the Template Hierarchy you could rename your content-attachment.php file to attachment.php and remove image.php. This will ensure that the image view will fallback to attachment.php. If you want to use content-attachment.php then you could use the template_include hook to tell WordPress to load in which … Read more

Custom post type template not loading from plugin

I think your first method isn’t working because it’s a theme method, not a plugin method. I could be entirely incorrect but I think the method of using single-custom_post_type.php only works for themes. (Again, I 100% could be wrong.) However, this is what I use and it always works: function wpse_post_type_templates( $template ) { if( … Read more

Post archive is not using the assigned template

Question: why doesn’t it use news.php? This is due to a design decision. If you look at the diagram for the Template Hierarchy, you will notice that the Blog Home page type (black box) has a line connecting directly to the home.html primary template (blue box) with no options in between. If you go to … Read more

How to check if a custom post type uses a custom template?

I mean “Full Width” like we do with pages : is_page_template( ‘Full Width’ ) ? is_page_template() does not accept a Template Name value like Full Width, but instead, a file name such as full-width.php or templates/full-width.php. Secondly, is_page_template() can be used with any post types and not just Pages (page post type), so you can … Read more

Unload templates; disable parent Template Parts using only “theme.json”

Does anyone have any suggestions on how to disable certain template parts in a child theme using theme.json in WordPress with Gutenberg? Using only theme.json this is not possible, and runs counter to the vision for full site editing. In the future it’s possible that not only the parent theme templates might be visible, but … Read more