Title: Remove plugin header code from specific page templates
Last modified: August 18, 2016

---

# Remove plugin header code from specific page templates

 *  [abelcreative](https://wordpress.org/support/users/abelcreative/)
 * (@abelcreative)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/remove-plugin-header-code-from-specific-page-templates/)
 * Plugins are great, except they add so much code to your header. Is there a way
   to only display that code on certain pages or templates? For instace, gallery
   plugins or flickr plugins – I often only need that code on my photos page, not
   every single page/post on the site.

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

 *  Thread Starter [abelcreative](https://wordpress.org/support/users/abelcreative/)
 * (@abelcreative)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/remove-plugin-header-code-from-specific-page-templates/#post-612935)
 * found a great solution here:
 * [http://urbangiraffe.com/plugins/headspace2/](http://urbangiraffe.com/plugins/headspace2/)
 * Testing it now
 *  Thread Starter [abelcreative](https://wordpress.org/support/users/abelcreative/)
 * (@abelcreative)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/remove-plugin-header-code-from-specific-page-templates/#post-612939)
 * so far it seems it only lets you show disabled plugins on certain pages – not
   sure why that’s helpful?
 *  [jonahcoyote](https://wordpress.org/support/users/jonahcoyote/)
 * (@jonahcoyote)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/remove-plugin-header-code-from-specific-page-templates/#post-613129)
 * I badly wanted to know how to do this as well and I couldn’t make headspace do
   exactly what I wanted. Which was to remove the plugin code included by plugins
   on specific pages…
 * I found one solution but its a little tricky. It involves editing the code for
   those plugins you want to remove the code for. Each plugin will have a block 
   of code that is used to insert whatever it is that the plugin needs in the <head
   > of your site. Only problem, like we know, is that the code is inserted into
   every page and it is usually only needed on one page.
 * An example: I’m using the excellent [cforms](http://www.deliciousdays.com/cforms-plugin)
   form plugin as a contact form on a contact page (id = 12). So I opened up the
   cforms main code in the plugin editor and did a quick find for ‘<script’ and 
   soon found the block I was looking for:
 *     ```
       function cforms_style() {
       	global $cforms_root, $localversion;
       	echo "\n\t<!-- Start Of Script Generated By cforms v".$localversion." [Oliver Seidel | www.deliciousdays.com] -->\n";
       	echo "\t".'<link rel="stylesheet" type="text/css" href="' . $cforms_root . '/styling/' . get_option('cforms_css') . '" />'."\n";
       	echo "\t".'<script type="text/javascript" src="' . $cforms_root. '/js/simplecalendar.js"></script>'."\n";
       	echo "\t".'<script type="text/javascript" src="' . $cforms_root. '/js/cforms.js"></script>'."\n";
       	if( get_option('cforms_datepicker')=='1' )
       		echo "\t".'<script type="text/javascript">'."\n".
       			 "\t".'var dp = new CalendarPopup(\'datepicker\');'."\n".
       			 "\t".'dp.setTodayText(\''.stripslashes(get_option('cforms_dp_today')).'\');'."\n".
       			 "\t".'dp.setMonthNames('.stripslashes(get_option('cforms_dp_months')).');'."\n".
       			 "\t".'dp.setDayHeaders('.stripslashes(get_option('cforms_dp_days')).');'."\n".
       			 "\t".'</script>'."\n";
       	echo "\t".'<!-- End Of Script Generated By cforms -->'."\n\n";
   
       }
       ```
   
 * All I did was add a little [conditional logic](http://codex.wordpress.org/Conditional_Tags)
   courtesy of wordpress to insert the above block of code only if on a specific
   page – you could also do sets of pages, categories or whatever else is at your
   disposal. So from the above I ended up with:
 *     ```
       function cforms_style() {
       	global $cforms_root, $localversion;
       	if (is_page('12')) { //only link style and script if on contact page
       	echo "\n\t<!-- Start Of Script Generated By cforms v".$localversion." [Oliver Seidel | www.deliciousdays.com] -->\n";
       	echo "\t".'<link rel="stylesheet" type="text/css" href="' . $cforms_root . '/styling/' . get_option('cforms_css') . '" />'."\n";
       	echo "\t".'<script type="text/javascript" src="' . $cforms_root. '/js/simplecalendar.js"></script>'."\n";
       	echo "\t".'<script type="text/javascript" src="' . $cforms_root. '/js/cforms.js"></script>'."\n";
       	if( get_option('cforms_datepicker')=='1' )
       		echo "\t".'<script type="text/javascript">'."\n".
       			 "\t".'var dp = new CalendarPopup(\'datepicker\');'."\n".
       			 "\t".'dp.setTodayText(\''.stripslashes(get_option('cforms_dp_today')).'\');'."\n".
       			 "\t".'dp.setMonthNames('.stripslashes(get_option('cforms_dp_months')).');'."\n".
       			 "\t".'dp.setDayHeaders('.stripslashes(get_option('cforms_dp_days')).');'."\n".
       			 "\t".'</script>'."\n";
       	echo "\t".'<!-- End Of Script Generated By cforms -->'."\n\n";
       	} else { // else display nothing
   
       	}
       }
       ```
   
 * Notice the little if line of code where im checking if we’re on page id 12 then
   insert the following code. Else, don’t. I Don’t know if I needed the else in 
   there but oh well it works. If you ran into any problems just make sure that 
   you’ve opened and closed all the brackets and that your code is formatted properly.
 * Now of course with each plugin you’re probably not going to have an identical
   block of code like above, but thats the challenge! Basically though you just 
   have to find the block of code in the plugin where it inserts its code to be 
   placed in the <head> and use some conditional logic.
 * Good luck!
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/remove-plugin-header-code-from-specific-page-templates/#post-613130)
 * That’s neat!
 * Now the really nice thing on behalf of plugin authors would to provide an option
   on the plugin’s admin/setting page where we type in the Page/post ID… and the
   plugin takes that and creates its own conditional line 🙂
 * So, any takers out there for the first plugin that adds its own style/code ONLY
   on the set page’s head???
 *  Thread Starter [abelcreative](https://wordpress.org/support/users/abelcreative/)
 * (@abelcreative)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/remove-plugin-header-code-from-specific-page-templates/#post-613153)
 * Great idea jonahcoyote and very good challenge moshu – I have no idea why more
   people aren’t pining for this!
 *  [oeroek](https://wordpress.org/support/users/oeroek/)
 * (@oeroek)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/remove-plugin-header-code-from-specific-page-templates/#post-613227)
 * I had the same problem with removing the cforms code from the header but don’t
   like to mess in the plugin code since you should redo your actions after every
   update and cforms updates a lot.
 * I think the following line is much easier. You could write a plugin for it or
   include it in functions.php which has my preference.
 *     ```
       function remove_cforms_header() {
   
       		if (!is_page('13')){
   
       	   remove_action('wp_head', 'cforms_style');}
           }
   
           add_action('wp_head', 'remove_cforms_header', 1);
       ```
   
 * Basically it adds an action to wp_head in which the style sheet for cforms is
   called. My custom function looks into the wp_head and only takes action if the
   page is not my contact page, ie page 13.
 * On all other posts and pages the function remove_action is used to remove the
   cforms action.
 * I had some trouble implementing this and note that the priority variable ‘1’ 
   is absolutely required since it gives this action a higher priority than the 
   action by cforms.
 * Hope it helps
 *  [oeroek](https://wordpress.org/support/users/oeroek/)
 * (@oeroek)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/remove-plugin-header-code-from-specific-page-templates/#post-613228)
 * edit:** the option above to only show the cforms header on specific pages is 
   also part of the options in global settings. I think I re invented the wheel.

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

The topic ‘Remove plugin header code from specific page templates’ is closed to 
new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 4 participants
 * Last reply from: [oeroek](https://wordpress.org/support/users/oeroek/)
 * Last activity: [17 years, 9 months ago](https://wordpress.org/support/topic/remove-plugin-header-code-from-specific-page-templates/#post-613228)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
