Set page template automatically according to parent slug

You can override the hierarchy and load a specific page template via the page_template filter. The fastest way is to identify the parent page by ID: function wpd_page_template_filter( $template ){ $page = get_queried_object(); if( 42 == $page->post_parent ){ // en page has ID of 42 $template = locate_template( ‘page-en.php’ ); } return $template; } add_filter( … Read more

How to load page template according to the Searched Page

Just use wp_get_referer(), and a few other functions to get the simple name of the referring page, e.g. if (basename(parse_url(wp_get_referer(), PHP_URL_PATH)) == ‘my-search-page’) { (Or you could use string searching or matching instead of parse_urland basename). (Also note wp_get_referer is deliberately misspelled. It originates in a misspelling in one of the web standards) Addendum Might … Read more

Blog template with different header to rest of site

Try this: if ( !is_home() && !is_cart() && !is_checkout() && !is_account_page() ) : if ( is_page( ‘contact-us’ ) ): get_template_part( ‘template-parts/header/header’, ‘map’ ); else: get_template_part( ‘template-parts/header/header’, ‘slider’ ); endif; endif; is_home() will return true if the current page/query is for the blog homepage, otherwise it returns false. You can read up about is_home() on the … Read more

different sidebars depending on template (is_page_template is not working)

One possiblilty: Keep the new code in sidebar.php in your child theme. In blog-page.php, change the line get_sidebar(‘blog-sidebar’); to do_action( ‘storefront_sidebar’ ); (as in an original page.php). Tested in a blog-page.php page template without custom query and loop, and also no woocommerce installed, this should work. If not, the custom query and loop might interfere. … Read more