WordPress, one of the most popular Content Management Systems[CMS] is my personal favorite. I have been using it for the last 6 months. Take a look at these websites:

  1. TechPassion
  2. aBacus
  3. Prodigy

With wp taking care of the backend, all I had to do was design a CSS for a theme framework. But then came a time, when the default wp features were just not enough! For instance, if I wish to include custom fields in the registration page, there is no option in the wp admin panel to do this. Then, I came to know about plugins. Plugins can extend WordPress to do almost anything you can imagine. However, there were some situations in which I couldn’t find a plugin that met my requirements. So I started to learn more about plugins, modified them [since they are GPLv2 Compatible] and installed them in my sites.

After developing a number of sites powered by WordPress, I noticed that I had to use the same action hooks to do some basic stuff like adding custom content to the header, footer and body. So I thought, why not develop a plugin with these features so that all the wp users can use it.

I started developing a plugin which lets the admin add custom code/content to different object types. Thanks to 12 part “How to Write a WordPress Plugin” at DevLounge.net by Ronald Huereca, I was able to successfully develop my first WordPress plugin:

CJ Custom Content

WordPress plugin page: http://wordpress.org/extend/plugins/cj-custom-content/

An easy way to add custom code to your object types (pages, posts)

The goal of this plugin is to help you include custom content with ease. Your HTML code (or JS) can be included various parts of the wordpress page/post such as

    • Header [Good for tracking codes such as Google Analytics]
    • Footer [Ideal for social networking site’s integration code]

    • Body

    • Top (or) Bottom of the post

Requires: 3.2 or higher
Compatible up to: 3.3



  1. Install through the WordPress admin or upload the plugin folder to your /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Go to the CJ Custom Content menu under Settings tab.

Download the plugin

[Size: 210 Kb]

Source code

Plugin Name: CJ Custom Content
Plugin URI: http://www.shibulijack.wordpress.com/cj-custom-content
Version: 2.0
Author: Shibu Lijack a.k.a CyberJack
Author URI: http://www.shibulijack.wordpress.com
Description: A Simple wp plugin to <strong>add custom content</strong> to wordpress pages. Custom html code can be added to the header, footer, body of all posts & pages, top and bottom of posts. With this plugin installed, it is very easy to insert scripts such as analytics track code, social networking sites integration snippet etc… via <a href="options-general.php?page=cj-custom-content.php">CJ Custom Content Settings</a> page.

  Copyright 2012 Shibu Lijack (email: shibulijack@gmail.com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as 
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

if (!function_exists("cjPluginSeriesContent_ap")) 
function cjPluginSeriesContent_ap() {
global $cj_pluginSeries_content;
if (!isset($cj_pluginSeries_content)) {
return; }
if (function_exists('add_options_page')) 
add_options_page('CJ Custom Content | Shibu Lijack', 'CJ Custom Content', 9, basename(__FILE__), array(&$cj_pluginSeries_content, 'printAdminPage')); }

if (!class_exists("cjPluginSeriesContent")) 
class cjPluginSeriesContent
	var $adminOptionsName = "cjPluginSeriesContentAdminOptions";
	function cjPluginSeriesContent() { 
	function cjPluginSeriesContent_settings_link($links) {
	$links[] = '<a href="'.admin_url('options-general.php?page=cj-custom-content').'">'.__('Settings', 'CJ Custom Content').'</a>';
	return $links;
	function addHeaderCode() { 
	$head = get_option($this->adminOptionsName);
	$opt_head = stripslashes($head['h_code']);
	$condition = $head['show_header'];
	<!-- CJ Custom Header Code -->
	<?php }
	function addFooterCode() { 
	$foot = get_option($this->adminOptionsName);
	$opt_foot = stripslashes($foot['f_code']);
	$condition = $foot['show_footer'];
	<!-- CJ Custom Footer Code -->
	<?php }
	//HTML body code
	function addContent($content = '') {
	$new = get_option($this->adminOptionsName);
	$opt_value = $new['content'];
	$condition = $new['add_content'];
		$content .= $opt_value; 
	return $content; 
	function addContentPostB($content = '') {
	if (is_single())
	$postb = get_option($this->adminOptionsName);
	$opt_postb = $postb['pb_code'];
	$condition = $postb['show_postb'];
		$content .= $opt_postb; }
	return $content; 
	function addContentPostT($content = '') {
	if (is_single())
	$postt = get_option($this->adminOptionsName);
	$opt_postt = $postt['pt_code'];
	$condition = $postt['show_postt'];
		$content = $opt_postt.$content;
	return $content; 
	function authorUpperCase($author = '') {
	return strtoupper($author);
	//Admin options
	function getAdminOptions() {
	$cjAdminOptions = array('show_header' => 'true', 'show_footer' => 'true', 'show_postb' => 'true', 'show_postt' => 'true', 'add_content' => 'true', 'comment_author' => 'true', 'content' => '' , 'h_code' => '' , 'f_code' => '' , 'pb_code' => '' , 'pt_code' => '');
	$cjOptions = get_option($this->adminOptionsName); 
	if (!empty($cjOptions)) {
	foreach ($cjOptions as $key => $option) $cjAdminOptions[$key] = $option;
	update_option($this->adminOptionsName, $cjAdminOptions); return $cjAdminOptions;
	function init() 
	//Print the admin page
	function printAdminPage() {
	$cjOptions = $this->getAdminOptions();
	if (isset($_POST['update_cjPluginSeriesContentSettings'])) 
	if (isset($_POST['cjHeader'])) { $cjOptions['show_header'] = $_POST['cjHeader']; }
	if (isset($_POST['cjFooter'])) { $cjOptions['show_footer'] = $_POST['cjFooter']; }
	if (isset($_POST['cjPostT'])) { $cjOptions['show_postt'] = $_POST['cjPostT']; }
	if (isset($_POST['cjPostB'])) { $cjOptions['show_postb'] = $_POST['cjPostB']; }
	if (isset($_POST['cjAddContent'])) { $cjOptions['add_content'] = $_POST['cjAddContent']; }
	if (isset($_POST['cjAuthor'])) { $cjOptions['comment_author'] = $_POST['cjAuthor']; }
	if (isset($_POST['cjContent'])) { $cjOptions['content'] = apply_filters('content_save_pre',$_POST['cjContent']); }
	if (isset($_POST['cjHeadContent'])) { $cjOptions['h_code'] = apply_filters('content_save_pre',$_POST['cjHeadContent']); }
	if (isset($_POST['cjFootContent'])) { $cjOptions['f_code'] = apply_filters('content_save_pre',$_POST['cjFootContent']); }
	if (isset($_POST['cjContentPostT'])) { $cjOptions['pt_code'] = apply_filters('content_save_pre',$_POST['cjContentPostT']); }
	if (isset($_POST['cjContentPostB'])) { $cjOptions['pb_code'] = apply_filters('content_save_pre',$_POST['cjContentPostB']); }
	update_option($this->adminOptionsName, $cjOptions);
	<div class="updated"><p><strong><?php _e("Settings Updated.","cjPluginSeriesContent");?></strong></p></div>
	<?php } ?>
<div class=wrap>
<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
<?php screen_icon( 'plugins' ); ?><h2>CJ Custom Content</h2>
<br><a href="https://shibulijack.wordpress.com/2012/02/03/cj-custom-content/" target="_blank" class="button-secondary">Visit Plugin Page</a> <a href="https://www.facebook.com/pages/CJ-Custom-Content-wp-Plugin/354642587888416" target="_blank" class="button-secondary">Facebook</a><br>
<br>Plugin developed by <a href="mailto:shibulijack@gmail.com">Shibu Lijack</a></br>

<table class="widefat">
<th  >Custom Header Content:</th>
<th>Custom Footer Content:</th>
<td width="50%"  ><textarea name="cjHeadContent" style="width: 90%; height: 100px;"><?php
'cjPluginSeriesContent') ?></textarea><p>Places the code between < head > and < /head ><br><i>Example: Google Analytics Tracking Code</i></p></td>
<td width="50%"><textarea name="cjFootContent" style="width: 90%; height: 100px;"><?php
'cjPluginSeriesContent') ?></textarea>
<p>Places the code just above < /body ><br><i>Example: Social Networking sites integration code</i></p></td>
<tr><td  ><h3>Enable Custom Header?</h3>
<p><label for="cjHeader_yes"><input type="radio"
id="cjHeader_yes" name="cjHeader" value="true" <?php if ($cjOptions['show_header'] == "true") { _e('checked="checked"', "cjPluginSeriesContent"); }?> /> Yes</label>&nbsp;&nbsp;&nbsp;&nbsp;<label for="cjHeader_no"><input type="radio" id="cjHeader_no" name="cjHeader" value="false" <?php if ($cjOptions['show_header'] == "false") { _e('checked="checked"', "cjPluginSeriesContent"); }?>/> No</label></p>
<p><i>Selecting "No" will disable the custom code inserted in the header</i></p><br></td>
<td><h3>Enable Custom Footer?</h3>
<p><label for="cjFooter_yes"><input type="radio"
id="cjFooter_yes" name="cjFooter" value="true" <?php if ($cjOptions['show_footer'] == "true") { _e('checked="checked"', "cjPluginSeriesContent"); }?> /> Yes</label>&nbsp;&nbsp;&nbsp;&nbsp;<label for="cjFooter_no"><input type="radio" id="cjHeader_no" name="cjFooter" value="false" <?php if ($cjOptions['show_footer'] == "false") { _e('checked="checked"', "cjPluginSeriesContent"); }?>/> No</label></p>
<p><i>Selecting "No" will disable the custom code inserted in the footer</i></p><br></td>

<table class="widefat">
<th colspan="2">Custom Body Content:</th>
<td width="50%"><textarea name="cjContent" style="width: 90%; height: 100px;"><?php
'cjPluginSeriesContent') ?></textarea>
<p>Places the code between < body > and < /body > in all the pages and posts.</p></td>
<td width="50%"><h4>Enable Custom Page/Post Content?</h4>
<p><label for="cjAddContent_yes"><input type="radio" id="cjAddContent_yes" name="cjAddContent" value="true" <?php if ($cjOptions['add_content'] == "true") { _e('checked="checked"', "cjPluginSeriesContent"); }?> /> Yes</label>&nbsp;&nbsp;&nbsp;&nbsp;<label for="cjAddContent_no"><input type="radio" id="cjAddContent_no" name="cjAddContent" value="false" <?php if ($cjOptions['add_content'] == "false") { _e('checked="checked"', "cjPluginSeriesContent"); }?>/> No</label></p>
<p><i>Selecting "No" will disable the content from being added into the end of every post/page.</i></p><br></td>

<table class="widefat">
<tr><th  >Custom Post Content[TOP]:</th>
<th>Custom Post Content[BOTTOM]:</th></tr></thead>
<td width="50%"  ><textarea name="cjContentPostT" style="width: 90%; height: 100px;"><?php
'cjPluginSeriesContent') ?></textarea>
<p>Places the code at the <strong>top</strong> of every single post but not on pages.</p></td>
<td width="50%"><textarea name="cjContentPostB" style="width: 90%; height: 100px;"><?php
'cjPluginSeriesContent') ?></textarea>
<p>Places the code at the <strong>bottom</strong> of every single post but not on pages.</p>
<td  ><h4>Enable Custom Post Content?</h4>
<p><label for="cjAddContentPT_yes"><input type="radio" id="cjAddContentPT_yes" name="cjPostT" value="true" <?php if ($cjOptions['show_postt'] == "true") { _e('checked="checked"', "cjPluginSeriesContent"); }?> /> Yes</label>&nbsp;&nbsp;&nbsp;&nbsp;<label for="cjAddContentPT_no"><input type="radio" id="cjAddContentPT_no" name="cjPostT" value="false" <?php if ($cjOptions['show_postt'] == "false") { _e('checked="checked"', "cjPluginSeriesContent"); }?>/> No</label></p>
<p><i>Selecting "No" will disable the content from being added into the top of every post.</i></p><br></td>
<td><h4>Enable Custom Post Content?</h4>
<p><label for="cjAddContentPB_yes"><input type="radio" id="cjAddContentPB_yes" name="cjPostB" value="true" <?php if ($cjOptions['show_postb'] == "true") { _e('checked="checked"', "cjPluginSeriesContent"); }?> /> Yes</label>&nbsp;&nbsp;&nbsp;&nbsp;<label for="cjAddContentPB_no"><input type="radio" id="cjAddContentPB_no" name="cjPostB" value="false" <?php if ($cjOptions['show_postb'] == "false") { _e('checked="checked"', "cjPluginSeriesContent"); }?>/> No</label></p>
<p><i>Selecting "No" will disable the content from being added into the bottom of every post/page.</i></p><br></td>

<div class="submit">
<input type="submit" class="button-primary" name="update_cjPluginSeriesContentSettings" value="<?php _e('Update Settings', 'cjPluginSeriesContent') ?>" /></div></form></div>

if (class_exists("cjPluginSeriesContent")) 
	$cj_pluginSeries_content = new cjPluginSeriesContent();

//Actions and Filters
if (isset($cj_pluginSeries_content)) {
add_action('activate_cj/cj-custom-content.php', array(&$cj_pluginSeries_content, 'init'));
add_action('admin_menu', 'cjPluginSeriesContent_ap');
add_action('wp_head', array(&$cj_pluginSeries_content, 'addHeaderCode'), 1);
add_action('wp_footer', array(&$cj_pluginSeries_content, 'addFooterCode'), 1);
add_filter('the_content', array(&$cj_pluginSeries_content, 'addContent'));
add_filter('the_content', array(&$cj_pluginSeries_content, 'addContentPostB'));
add_filter('the_content', array(&$cj_pluginSeries_content, 'addContentPostT'));
add_filter('plugin_action_links_'.plugin_basename(__FILE__), array(&$cj_pluginSeries_content, 'cjPluginSeriesContent_settings_link'), 10, 1);

Published by Shibu Lijack

Frontend Web Developer | Music Enthusiast | Foodie | Technophile

Join the Conversation


  1. Hi, thank you for the nice work you done.
    I used your plugin to override my theme and published custom footer. now I need to exclude this action from few pages. how can I do that?
    my programming skills are very fair!!

    1. First of all, thank you.
      If you wish to exclude the footer action from a few pages, say for example pages with id 12 and 13, include the following snippet in the function addFooterCode()

      if(!isPage(12) || !isPage(13))

      $foot = get_option($this->adminOptionsName);
      /* the rest of the footer code as it is */
      …<?php }


      The above snippet will add the custom footer code only if the page id is not 12 or 13. Hope it helps.

  2. Shibu – in theory I love this plugin. Getting to work is a bit harder. I’ve no problem getting to add content to the right posts. The problem is that when I paste my html into any of the boxes the quote marks get escaped i.e. ” becomes \”. Of course all my links break 🙂

    WP Version: current.
    BTW I’ve tried pasting doing this from either firefox or chrome under windows. Its an issue in both cases.

    Mark Levison

    1. I have rectified this issue in the addHeaderCode and addFooterCode function by using the stripslashes() function. Check the code above. I should have done this for other functions as well. May be sometime soon.
      In order to remove the escaped quotes, modify this line:
      $opt_value = $new[‘content’];
      $opt_value = stripslashes($new[‘content’]);
      Hope it helps. Thank you for using my plugin 🙂

  3. Hi CJ,
    Ecellent plugin, does just what I need.
    However, I’m having the same issue with ‘/’ in the Body Content pane. I tried your fix in the add_content() function as shown here:

    function addContent($content = ”) {
    $new = get_option($this->adminOptionsName);
    $opt_value = $new[‘content’];
    $condition = $new[‘add_content’];
    $content .= stripslashes($opt_value);
    return $content;
    function addContentPostB($content = ”) {
    if (is_single())
    $postb = get_option($this->adminOptionsName);
    $opt_postb = $postb[‘pb_code’];
    $condition = $postb[‘show_postb’];
    $content .= stripslashes($opt_postb); }
    return $content;

    However, it must be incorrect as the problem still exists. Any help would be appreciated!


    1. First of all, sorry for the late reply Steve.
      Now let’s come to the solution.
      Instead of:
      $content .= stripslashes($opt_value);
      do this:
      $opt_value = stripslashes($new[‘content’]);

  4. Hi CJ,
    I’m having the same problem with slashes, however they are appearing within the Custom Body Content. I’ve added the same code from your fix listed above, but probably did it wrong as there was no change.
    Any assistance would be appreciated!

    Steve Pritchard

Leave a comment

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: