Override header.php with one in plugin's folder
-
Hi there,
I’m creating a plugin that make use of a custom post type, i need it to be theme-independent so i am overriding the template with my own which is in my plugin’s folder, this is how i do it:
define( 'PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); //Template fallback add_filter( "template_include", 'ps_theme_redirect' ); function ps_theme_redirect( $template ) { //cpt is the slug of the custom post type registered if ( get_post_type() == 'cpt' ) { if ( is_single() ) { //looks in the current theme directory for the template if so it is returned otherwise the template from the plugin directory is returned. if ( file_exists( get_stylesheet_directory() . '/single-cpt.php' ) ) return get_stylesheet_directory() . '/single-cpt.php'; return PLUGIN_PATH . '/templates/single-cpt.php'; } else { if ( file_exists( get_stylesheet_directory() . '/archive-cpt.php' ) ) return get_stylesheet_directory() . '/archive-cpt.php'; return PLUGIN_PATH . '/templates/archive-cpt.php'; } } return $template; }
Now i need also to do this with the header because i don’t want to show menus and stuff that a theme might have in header.
Can anyone please advice on how to do this? Basically i need to override theme’s header.php with the one i have in my plugins folder.
Thanks in advance,
Stelios
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘Override header.php with one in plugin's folder’ is closed to new replies.