I need to call a custom header/footer from a plugin for a specific landing page. How can I do this? I know I can make a template in my theme and call it by supplying an argument to get_header()/get_footer().

However, I want to supply my footer/header from a plugin instead, since I often put all content associated with a custom landing page in a plugin. I don't want to have a footer template in my theme for every landing page.

What is the best solution for this? I don't want to hide content with CSS.

Here is a gist of what my landingpage plugin basically looks like:



You can intercept the template WordPress will be using with the template_include filter. Like this:

add_filter ('template_include','wpse303537_plugin_template', 10,1);
function wpse303537_plugin_template ($template) {
  if (is_front_page)
    $template = plugin_dir_path( __FILE__ ) . '/my-template.php';
  return $template;

Alternatively, you can include an almost empty template for the landing page in your theme and fill it through the action hook in get_header.

  • Thanks. However this just seems to replace the whole template right? I'm already replacing the main template with the page_template filter. I just want to call a specific footer or header but have it reside inside my plugin instead of the themes folder. Maybe I'm misunderstanding you? – Johan Dahl May 14 '18 at 14:39
  • Yes, that's what it does. Because you state that you want all content from the landing page in your plugin. If you already have a special template for this, go for the second option: have an empty header.php for that template and fill it through the hook from the plugin. – cjbj May 14 '18 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.