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.

How to consolidate multiple static page templates into one dynamic one?

Personally, I build everything within index.php of each template. I then do conditional checks. Example: if(is_front_page()){ // Home page layout } elseif(is_page()){ // General page layout if(is_page(‘contact’)){ // Page layout specific to the contact page } elseif(is_page(‘about’)){ // Page layout specific to the about page } } Read more on conditional tags.

Dynamically link to the latest post or simulate request of specific post in page template

You can filter wp_nav_menu_objects and add a new item. Here is a simple plugin doing that: <?php # -*- coding: utf-8 -*- /** * Plugin Name: Latest Post In Menu * Description: Append a link to the latest post to all nav menus called with the argument <code>’add_latest_post’ => TRUE</code>. * Plugin URI: http://wordpress.stackexchange.com/q/59892/73 * … Read more