How to quickly switch custom post type singular template?

you can do it like this: //add movies_view to query vars add_filter(‘query_vars’, ‘my_query_vars’); function my_query_vars($vars) { // add movies_view to the valid list of variables $new_vars = array(‘movies_view’); $vars = $new_vars + $vars; return $vars; } then add a template redirect based on that query_var: add_action(“template_redirect”, ‘my_template_redirect’); // Template selection function my_template_redirect() { global $wp; … Read more

Multiple areas of dynamic content in a page

The example you gave has a listing of three pages and four posts (which are dated). The same can be achieved by one of the following: two different Custom Post Types, one per block, e. g. post_type=”products” and post_type=”projects”; children of two another pages, e. g. children of “Products” in one block and children of … Read more

Add Archive Page Template via Plugin

WordPress has a template_include filter which you can use. // Add a filter to ‘template_include’ hook add_filter( ‘template_include’, ‘wpse_force_template’ ); function wpse_force_template( $template ) { // If the current url is an archive of any kind if( is_archive() ) { // Set this to the template file inside your plugin folder $template = WP_PLUGIN_DIR .”https://wordpress.stackexchange.com/”. … Read more

Loading page content into a variable in template

You can always use the output buffering to store the printing contents in a variable. function return_get_template_part($slug, $name=null) { ob_start(); get_template_part($slug, $name); $content = ob_get_contents(); ob_end_clean(); return $content; } $content = return_get_template_part(‘content’, ‘page’); This would be most preferable to keep using the get_template_part() right now. An alternative would be to use locate_template() function but it … Read more

How to add custom template in plugin?

This plugin looks for page_contact.php from active theme’s folder and uses plugin’s templates/page_contact.php as a fallback. <?php /** * Plugin Name: Test Plugin */ add_filter( ‘template_include’, ‘contact_page_template’, 99 ); function contact_page_template( $template ) { $file_name=”page_contact.php”; if ( is_page( ‘contact’ ) ) { if ( locate_template( $file_name ) ) { $template = locate_template( $file_name ); } … Read more

How to redirect WordPress home page to custom static HTML page

This code may help resolve the issue for this particular situation. Put this code in yor theme’s functions.php. add_action(‘template_redirect’, ‘default_page’); function default_page(){ if(is_home() or is_front_page()){ exit( wp_redirect(“http://path/to/your/html/file”)); } } Replace http://path/to/your/html/file to exact url of html file. I hope this helps.