Change directory where get_header(), get_footer() and get_sidebar() look for templates

Simple solution, use get_template_part(). For example: get_template_part( ‘partials/footer’ ); Which would get the footer.php inside the partials/ directory. Another example: get_template_part( ‘partials/footer’, ‘home’ ); Which would get the footer-home.php inside the partials/ directory. One more example: get_template_part( ‘partials/footer/blog’ ); Which would get the blog.php inside the partials/footer/ directory.

WordPress Template Hierarchy

You can use the dynamic filter {type}_template (where {type} is the current query type e.g. single, index etc.) found in get_query_template(): function wpse_204848_get_id_template( $template ) { if ( $post = get_queried_object() ) { if ( $_template = locate_template( “single-{$post->post_type}-{$post->ID}.php” ) ) $template = $_template; } return $template; } add_filter( ‘single_template’, ‘wpse_204848_get_id_template’ ); For a portfolio … Read more

Remove header and footer but KEEP all css and js etc for a custom post template?

If someone needs something similar, I actually found an answer to my issue and it is to pass arguments to get_header() and get_footer(). <?php get_header(‘customposttype); ?> <div style=”width:500px;”> <?php $id = get_the_id(); echo do_shortcode( ‘[skwidget id=”‘ . $id . ‘”]’ ); ?> </div> <?php get_footer(‘customposttype’); ?> and copy header.php to header-{customposttype}.php and footer.php to footer-{customposttype}.php … Read more

Turn query string to sub page

Put this code in your functions.php– function the_dramatist_url_rewrite() { global $wp_rewrite; add_rewrite_tag(‘%sub%’, ‘([^&]+)’); add_rewrite_rule( ‘^events/%year%/%monthnum%/%day%/%postname%/?’, ‘index.php/events/%year%/%monthnum%/%day%/%postname%?sub=$matches[1]’, ‘top’ ); } add_action(‘init’, ‘the_dramatist_url_rewrite’, 10, 0); The go to the permalinks page in the settings menu at dashboard and hit Save Changes button. Hope this is gonna help.

Dequeue script in template isn’t working

Move your project_dequeue_unnecessary_scripts() function to your functions.php file and add a conditional statement to determine if the appropriate template is being loaded. E.g.: // Remove Mobile Header function project_dequeue_unnecessary_scripts() { if ( is_page_template( ‘name-of-template.php’ ) ) { wp_dequeue_script( ‘enterprise-responsive-menu’ ); wp_deregister_script( ‘enterprise-responsive-menu’ ); } } add_action( ‘wp_print_scripts’, ‘project_dequeue_unnecessary_scripts’ ); I suspect that your function is … Read more

Load template file without a post type

You could setup a custom rewrite rule using add_rewrite_rule and send these requests to a custom page. Your URL structure could be /index-page/single-event-slug The rule would point all of the single events to a separate page where you can then set your template events-single.php. Another option is to pass the events in as a query … Read more