Title: Custom header for plugin single post template
Last modified: April 27, 2024

---

# Custom header for plugin single post template

 *  [Arifur06](https://wordpress.org/support/users/arifur06/)
 * (@arifur06)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/custom-header-for-plugin-single-post-template/)
 * i am developing a plugin.
 * i want to have it no header and no footer. Only content or meta tages value will
   show. No header and no footer.
 * how do declare no header and no footer?
 * regards

Viewing 12 replies - 1 through 12 (of 12 total)

 *  [Stef](https://wordpress.org/support/users/serafinnyc/)
 * (@serafinnyc)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/custom-header-for-plugin-single-post-template/#post-17718273)
 * You want no header and no footer where? Inside the settings panel of your app?
   Need more information.
 *  Thread Starter [Arifur06](https://wordpress.org/support/users/arifur06/)
 * (@arifur06)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/custom-header-for-plugin-single-post-template/#post-17718428)
 * Hi. Thanks for reply.
 * I want In single template (custom post type) will not show the header and footer.
   I added an header-custom.php and footer-custom.php in theme file.
 * And declared header from plugin single.php this way.
 * <?php get_header (‘custom’)?> and <?php get_footer (‘custom’?>
 * When the theme get updates the header_custom.php and footer-custom.php are deleted
   and I have to upload the custon header again..
 * so I want to include header in plugin file.
 * Regards:
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/custom-header-for-plugin-single-post-template/#post-17719058)
 * Custom templates are better off [in a child theme](https://developer.wordpress.org/themes/advanced-topics/child-themes/)
   than a plugin. Your template file will be safe in either. If you name your template`"
   single-{$post-type}.php"` and keep it in a child theme, it’ll automatically be
   used for any single post requests of that type. If you instead kept it in a plugin
   you’d need to use “template_include” or “template_redirect” hooks to cause the
   template to be used.
 * Header files typically include the HTML and HEAD tags. Be sure these exist on
   your template somehow even if there’s no visible header. Within the HEAD section
   you need to `do_action('wp_head');` or else important page resources will not
   be loaded.
 *  Thread Starter [Arifur06](https://wordpress.org/support/users/arifur06/)
 * (@arifur06)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/custom-header-for-plugin-single-post-template/#post-17719163)
 * Thanks for your reply.
 * i did this using child theme but when i change theme i had to add child theme
   and declare header again.. That is why I wanted to keep it in plugin. So that
   i can use the plugin in any theme when i declare a blank header and footer from
   plugin directory.
 * regards
 *  [Stef](https://wordpress.org/support/users/serafinnyc/)
 * (@serafinnyc)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/custom-header-for-plugin-single-post-template/#post-17719215)
 * To clarify, you want to create an app that inside it you can turn off and on 
   the header and footer whenever you want. Is that correct?
 *  Thread Starter [Arifur06](https://wordpress.org/support/users/arifur06/)
 * (@arifur06)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/custom-header-for-plugin-single-post-template/#post-17719250)
 * yes. Correct
 *  [Stef](https://wordpress.org/support/users/serafinnyc/)
 * (@serafinnyc)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/custom-header-for-plugin-single-post-template/#post-17719258)
 * For this we’d need to see what you have coded so far. Makes no sense to advise
   blindly
 *  Thread Starter [Arifur06](https://wordpress.org/support/users/arifur06/)
 * (@arifur06)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/custom-header-for-plugin-single-post-template/#post-17719295)
 *     ```wp-block-code
       <?php get_header('custom');?>
       <div class="ful-area">						
           <div class="bg-area">
               <div class="cont-area">
                   <div class="avatar">
                       <img src="<?php echo get_post_meta(get_the_ID(), "nfc_avatar", true); ?>" alt="">
                   </div>
   
                   <div class="name">
                       <a href="<?php the_permalink(); ?>"><h2><?php echo get_post_meta(get_the_ID(), "nfc_name", true); ?> </h2></a>
                   </div>
   
                   <div class="designation">
                       <h3><?php echo get_post_meta(get_the_ID(), "nfc_desig", true); ?> </h3>
                       <h4><?php echo get_post_meta(get_the_ID(), "nfc_company", true); ?> </h4>
                       <div class="bio">
                            <?php the_content(); ?>
                       </div>
                   </div>
                   <div class="contact-icon">
   
                   <?php $contactdet = get_post_meta(get_the_ID(), "_nfc_con_details", true );?>
   
                           <?php foreach 
                            ($contactdet as $singcontact): 
                            $nfc_contact_icon = $singcontact['_nfc_con_icon'];
                           ?>
   
                       <div class="email-icon">
   
                           <a href="<?php echo esc_url($singcontact['_nfc_con_link']);?>"><i class="<?php echo esc_attr($nfc_contact_icon);?> con-icon"></i>
                           <div class="contact-info">
                               <div class="email"><?php echo esc_html($singcontact['_nfc_con_title']);?></div>
                               <div class="email-text"><?php echo esc_html($singcontact['_nfc_con_info']);?></div>
                           </div></a>
                       </div>               
                               <?php endforeach; ?>
                       </div>
   
                   <div class="social">
                       <div class="social-icon">
                           <div class="social">
                               <div class="social-icon">
       <?php get_header('nfcs');?>
       <div class="ful-area">						
           <div class="bg-area">
               <div class="cont-area">
                   <div class="avatar">
                       <img src="<?php echo get_post_meta(get_the_ID(), "nfc_avatar", true); ?>" alt="">
                   </div>
   
                   <div class="name">
                       <a href="<?php the_permalink(); ?>"><h2><?php echo get_post_meta(get_the_ID(), "nfc_name", true); ?> </h2></a>
                   </div>
   
                   <div class="designation">
                       <h3><?php echo get_post_meta(get_the_ID(), "nfc_desig", true); ?> </h3>
                       <h4><?php echo get_post_meta(get_the_ID(), "nfc_company", true); ?> </h4>
                       <div class="bio">
                            <?php the_content(); ?>
                       </div>
                   </div>
                   <div class="contact-icon">
   
                   <?php $contactdet = get_post_meta(get_the_ID(), "_nfc_con_details", true );?>
   
                           <?php foreach 
                            ($contactdet as $singcontact): 
                            $nfc_contact_icon = $singcontact['_nfc_con_icon'];
                           ?>
   
                       <div class="email-icon">
   
                           <a href="<?php echo esc_url($singcontact['_nfc_con_link']);?>"><i class="<?php echo esc_attr($nfc_contact_icon);?> con-icon"></i>
                           <div class="contact-info">
                               <div class="email"><?php echo esc_html($singcontact['_nfc_con_title']);?></div>
                               <div class="email-text"><?php echo esc_html($singcontact['_nfc_con_info']);?></div>
                           </div></a>
                       </div>               
                               <?php endforeach; ?>
                       </div>
   
                   <div class="social">
                       <div class="social-icon">
                           <div class="social">
                               <div class="social-icon">
       <?php $nfccarddetails = get_post_meta(get_the_ID(), "_nfc_card_details", true );?>  
                                   <?php foreach 
                                   ($nfccarddetails as $singcard): 
                                    $nfc_f_icon = $singcard['_nfc_social_icon'];
                                     ?>
                             <a href="<?php echo esc_url($singcard['_nfc_social_link']);?>"><i class="fa-brands <?php echo esc_attr($nfc_f_icon);?> icons-round"></i></a>
                           <?php endforeach; ?>
   
                       </div>
   
                           </div>
                       </div>
                   </div>
   
                   <div class="save-btn">
                       <a href="<?php echo get_post_meta(get_the_ID(),"nfc_btn_link",true); ?>"><?php echo get_post_meta(get_the_ID(),"nfc_btn_text",true); ?></a>
                   </div>
   
               </div>
           </div>
       </div>			
          <?php get_footer('custom');?>
       ```
   
 * i created blank header and footer in theme files then call it in custom post 
   type ‘singke-template.php here
 *  [Stef](https://wordpress.org/support/users/serafinnyc/)
 * (@serafinnyc)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/custom-header-for-plugin-single-post-template/#post-17719298)
 * I mean your plugin. Where is the code for your plugin your developing? This looks
   like a custom template file, not a plugin.
 *     ```wp-block-code
       <?php
       /*
       Plugin Name: Header Footer Toggle
       Plugin URI: https://thebonsaigroup.io
       Description: Allows toggling the visibility of the header and footer from the admin panel.
       Version: 1.0
       Author: Your Name
       Author URI:  https://thebonsaigroup.io
       */
   
       // Hook for adding admin menus
       add_action('admin_menu', 'hft_add_pages');
   
       // Action function for adding menus
       function hft_add_pages() {
           add_menu_page('Header Footer Toggle', 'Header Footer Toggle', 'manage_options', 'headerfooter', 'hft_admin_settings_page');
       }
   
       // Include the settings page function from another file only if it's not already declared
       if (!function_exists('hft_admin_settings_page')) {
           include('hft-admin-page.php');
       }
   
       function hft_toggle_elements() {
           $options = get_option('hft_settings');
           echo '<style>';
           if (isset($options['header']) && !$options['header']) {
               echo 'html body header { display: none !important; }'; // More specific selector
           }
           if (isset($options['footer']) && !$options['footer']) {
               echo 'html body footer { display: none !important; }'; // More specific selector
           }
           echo '</style>';
       }
   
       add_action('wp_head', 'hft_toggle_elements', 100);
       add_action('wp_footer', 'hft_toggle_elements', 100); // Move the action to wp_footer with high priority
       ```
   
 * Like that. However, I believe you are going about this all wrong. You are better
   off creating custom meta boxes so that you can toggle on and off the header and
   footer on any page. Rather than build a template file.
    -  This reply was modified 2 years, 1 month ago by [Stef](https://wordpress.org/support/users/serafinnyc/).
 *  Thread Starter [Arifur06](https://wordpress.org/support/users/arifur06/)
 * (@arifur06)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/custom-header-for-plugin-single-post-template/#post-17719874)
 *     ```wp-block-code
       <?php
       /**
        * Plugin Name: Cardsof
        * Plugin URI: #
        * Description: A custom business card creator for virtual assistants. ".
        * Version: 1.0
        * Author: Arifur06
        * Author URI: #
        * Text Domain: crds
        **/
   
       	if ( ! defined( 'ABSPATH' ) ) {
       	die( 'We\'re sorry, but you can not directly access this file.' );
       }	 
       //plugin styles
   
       		function nfc_card_style()
       		{
       			wp_enqueue_style("fontawesome",plugins_url("assets/css/fontawesome.min.css", __FILE__));
       			wp_enqueue_style("dark",plugins_url("assets/css/dark.css", __FILE__));
       			wp_enqueue_style("all-min",plugins_url("assets/css/all.min.css", __FILE__));
       		}
       		add_action("wp_enqueue_scripts", "nfc_card_style");
   
       		if (!function_exists("nfc_cardz_post_type")) {
       			// Register Custom Post Type
       			function nfc_cardz_post_type()
       			{
       				$labels = [
       					"name" => _x("NFC Cards Zone", "Post Type General Name", "nfccz"),
       					"description" => _x("NFC Cards Zone", "Post Type General Name", "nfccz"),
       					"singular_name" => _x("nfc-card", "Post Type Singular Name", "nfccz"),
       					"menu_name" => __("NFC Cards", "nfccz"),
       					"name_admin_bar" => __("Post Type", "nfccz"),
       					"archives" => __("Item Archives", "nfccz"),
       					"attributes" => __("Card Attributes", "nfccz"),
       					"parent_item_colon" => __("Parent Item:", "nfccz"),
       					"all_items" => __("All Cards", "nfccz"),
       					"add_new_item" => __("Add New Card", "nfccz"),
       					"add_new" => __("Add New Card", "nfccz"),
       					"new_item" => __("New Card", "nfccz"),
       					"edit_item" => __("Edit Card", "nfccz"),
       					"update_item" => __("Update Card", "nfccz"),
       					"view_item" => __("View Item", "nfccz"),
       					"view_items" => __("View Items", "nfccz"),
       					"search_items" => __("Search Item", "nfccz"),
       					"not_found" => __("Not found", "nfccz"),
       					"not_found_in_trash" => __("Not found in Trash", "nfccz"),
       					"featured_image" => __("Profile Image", "nfccz"),
       					"set_featured_image" => __("Set Profile image", "nfccz"),
       					"remove_featured_image" => __("Remove profile image", "nfccz"),
       					"use_featured_image" => __("Use as profile image", "nfccz"),
       					"insert_into_item" => __("Insert into item", "nfccz"),
       					"uploaded_to_this_item" => __("Uploaded to this item", "nfccz"),
       					"items_list" => __("Items list", "nfccz"),
       					"items_list_navigation" => __("Items list navigation", "nfccz"),
       					"filter_items_list" => __("Filter items list", "nfccz"),
       				];
       				$args = [
       					"label" => __("nfc-card", "nfccz"),
       					"description" => __(
       						"You can add individual cards in this post type",
       						"nfccz"
       					),
       					"labels" => $labels,
       					"supports" => ["title", "thumbnail", "editor"],
       					"hierarchical" => false,
       					"public" => true,
       					'menu_icon' => 'dashicons-index-card',
       					"show_ui" => true,
       					"show_in_menu" => true,
       					"show_in_admin_bar" => true,
       					"show_in_nav_menus" => true,
       					"can_export" => true,
       					"has_archive" => false,
       					"exclude_from_search" => true,
       					"publicly_queryable" => true,
       					"capability_type" => "page",
       				];
       				register_post_type("nc", $args);
       			}
       			add_action("init", "nfc_cardz_post_type", 0);
       		}
   
       		require_once "options/init.php";
       		require_once "options/options.php";
       		require_once "shortcode.php";
   
       		// single post
       		add_filter( 'single_template', 'override_single_template' );
       		function override_single_template( $single_template ){
       			global $post;
   
       			$file = dirname(__FILE__) .'/templates/single-'. $post->post_type .'.php';
   
       			if( file_exists( $file ) ) $single_template = $file;
   
       			return $single_template;
       		}
       ```
   
 *  [Stef](https://wordpress.org/support/users/serafinnyc/)
 * (@serafinnyc)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/custom-header-for-plugin-single-post-template/#post-17720890)
 * How come we don’t have a flag for spammy posters? #Mods? Qwhifr needs to be blocked.
 * [@arifur06](https://wordpress.org/support/users/arifur06/) thanks, but this is
   a CPT. This is not a custom meta box. You need to learn how to code a WP [Custom Meta Box](https://wpengine.com/resources/create-custom-wordpress-meta-box/)
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/custom-header-for-plugin-single-post-template/#post-17722300)
 * [@serafinnyc](https://wordpress.org/support/users/serafinnyc/) — if you see any
   spam in the forums you can use the “report this topic” side bar tool and explain
   further in the “why” box that the issue is a particular reply. You can even directly
   link to the reply by copy/pasting the reply’s timestamp link.
 * Thanks for the help you’ve provided here in the forums!

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Custom header for plugin single post template’ is closed to new replies.

## Tags

 * [footer](https://wordpress.org/support/topic-tag/footer/)
 * [header](https://wordpress.org/support/topic-tag/header/)
 * [plugin](https://wordpress.org/support/topic-tag/plugin/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 12 replies
 * 4 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [2 years, 1 month ago](https://wordpress.org/support/topic/custom-header-for-plugin-single-post-template/#post-17722300)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
