WordPress Create Custom Page Templates With Plugins
- Article
- Comment
WordPress Create Custom Page Templates With Plugins. In WordPress, We have options to create Custom template for specific post and pages. This is most usable function for the Theme developers. But if the same kind of custom templates required for the custom plugin creators, Here is a function, which will help you to create a custom template for a function.
Generally, the custom template and default templates will be called with the ” get_page_template() ” function. So here is an alternative filter to override the functions. ” page_template ” . Than let’s write a custom function to hook our page as a template.
<?php add_filter( 'page_template', 'kv_custom_plugin_page_template' ); ?>
And here is the code for the custom function “kv_custom_plugin_page_template” .
function kv_custom_plugin_page_template( $page_template ){ if ( is_page( 'kv-codes-page-slug' ) ) { $page_template = dirname( __FILE__ ) . '/kv-template.php'; } return $page_template; }
That’s it , now, you can test it on live.