wordpress - Call main theme function with plugin -
we created plugin new template , want hook main theme function , return main plugin function.
we tried with:
add_filter( "page_template", "test" ); function test( $template ) { if( 'plugin_name.php' == basename( $template ) ) $template = wp_plugin_dir . '/plugin_folder/plugin_name.php'; return $template; }
and changed page template in theme functions main function of plugin runs template inside plugin:
add_filter( "page_template", "main_plugin_function" );
is page_template right filter change theme template?
thanks help!
i think should use template_include
filter, filter hook executed before wordpress includes predetermined template file. can used override wordpress's default template behavior.
for example
add_filter( 'template_include', 'portfolio_page_template', 99 ); function portfolio_page_template( $template ) { if ( is_page( 'portfolio' ) ) { $new_template = locate_template( array( 'portfolio-page-template.php' ) ); if ( '' != $new_template ) { return $new_template; } } return $template; }
https://codex.wordpress.org/plugin_api/filter_reference/template_include
Comments
Post a Comment