Version Description
3-Apr-2017
- Adds option for individual post code to replace the site-wide code:
- Head and footer managed independently of each other
- Individual post code appends to site-wide by default
- Check the Replace Site-wide Head/Footer Code checkbox to replace or remove the Site-wide code for the respective area
- Fixes post meta fields:
- No longer saves post meta fields when not needed
- Deletes post meta fields if empty when saved/updated
Download this release
Release Info
Developer | joerhoney |
Plugin | AddFunc Head & Footer Code |
Version | 1.4 |
Comparing to | |
See all releases |
Code changes from version 1.3 to 1.4
- addfunc-head-footer-code.php +53 -38
- options.php +2 -0
- readme.txt +33 -22
addfunc-head-footer-code.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: AddFunc Head & Footer Code
|
4 |
Plugin URI:
|
5 |
Description: Allows admins to add code to the <head> and/or <footer> of an individual post and/or site-wide. Ideal for scripts such as Google Analytics conversion tracking codes and any other general or page-specific JavaScript.
|
6 |
-
Version: 1.
|
7 |
Author: AddFunc
|
8 |
Author URI: http://profiles.wordpress.org/addfunc
|
9 |
License: Public Domain
|
@@ -51,15 +51,27 @@ define('AFHDFTRCD_NICK', 'Head & Footer Code');
|
|
51 |
$plugin_id = AFHDFTRCD_ID;
|
52 |
include(self::file_path('options.php'));
|
53 |
}
|
54 |
-
public static function output_head_code(
|
55 |
{
|
56 |
-
$
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
}
|
59 |
-
public static function output_footer_code(
|
60 |
{
|
61 |
-
$
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
}
|
64 |
}
|
65 |
if (is_admin())
|
@@ -79,57 +91,60 @@ endif;
|
|
79 |
Metabox w/head & footer fields for all post types (including custom)
|
80 |
*/
|
81 |
|
82 |
-
add_action(
|
83 |
function aFhfc_add()
|
84 |
{
|
85 |
-
if
|
86 |
-
add_meta_box(
|
87 |
}
|
88 |
}
|
89 |
-
function aFhfc_mtbx(
|
90 |
{
|
91 |
-
$values = get_post_custom(
|
92 |
-
$head_text = isset(
|
93 |
-
$
|
94 |
-
|
|
|
|
|
95 |
?>
|
96 |
<p>
|
97 |
<label for="aFhfc_head_code">Head:</label>
|
98 |
<textarea class="large-text" name="aFhfc_head_code" id="aFhfc_head_code"><?php echo $head_text; ?></textarea>
|
|
|
|
|
99 |
</p>
|
100 |
<p>
|
101 |
<label for="aFhfc_footer_code">Footer:</label>
|
102 |
<textarea class="large-text" name="aFhfc_footer_code" id="aFhfc_footer_code"><?php echo $footer_text; ?></textarea>
|
|
|
|
|
103 |
</p>
|
104 |
<?php
|
105 |
}
|
106 |
-
add_action(
|
107 |
-
function aFhfc_save(
|
108 |
{
|
109 |
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
|
110 |
if( !isset( $_POST['aFhfc_mb_nonce'] ) || !wp_verify_nonce( $_POST['aFhfc_mb_nonce'], 'aFhfc_nonce' ) ) return;
|
111 |
if( !current_user_can( 'manage_options' ) ) return;
|
112 |
if( isset( $_POST['aFhfc_head_code'] ) )
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
if( isset( $_POST['aFhfc_footer_code'] ) )
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
*/
|
125 |
-
|
126 |
-
function aFhfc_head_output( $post ) {
|
127 |
-
$aFhfc_head_code = get_post_meta( get_the_ID(), 'aFhfc_head_code', true );
|
128 |
-
echo $aFhfc_head_code."\n";
|
129 |
-
}
|
130 |
-
add_action('wp_head', 'aFhfc_head_output');
|
131 |
-
function aFhfc_footer_output( $post ) {
|
132 |
-
$aFhfc_footer_code = get_post_meta( get_the_ID(), 'aFhfc_footer_code', true );
|
133 |
-
echo $aFhfc_footer_code."\n";
|
134 |
}
|
135 |
-
add_action('wp_footer', 'aFhfc_footer_output');
|
3 |
Plugin Name: AddFunc Head & Footer Code
|
4 |
Plugin URI:
|
5 |
Description: Allows admins to add code to the <head> and/or <footer> of an individual post and/or site-wide. Ideal for scripts such as Google Analytics conversion tracking codes and any other general or page-specific JavaScript.
|
6 |
+
Version: 1.4
|
7 |
Author: AddFunc
|
8 |
Author URI: http://profiles.wordpress.org/addfunc
|
9 |
License: Public Domain
|
51 |
$plugin_id = AFHDFTRCD_ID;
|
52 |
include(self::file_path('options.php'));
|
53 |
}
|
54 |
+
public static function output_head_code()
|
55 |
{
|
56 |
+
$site_head_code = get_option('aFhfc_site_wide_head_code');
|
57 |
+
$meta_head_code = get_post_meta(get_the_ID(),'aFhfc_head_code',true);
|
58 |
+
$head_replace = get_post_meta(get_the_ID(),'aFhfc_head_replace',true);
|
59 |
+
if(!empty($head_replace)){
|
60 |
+
echo $meta_head_code."\n";
|
61 |
+
}else{
|
62 |
+
echo $site_head_code."\n".$meta_head_code."\n";
|
63 |
+
}
|
64 |
}
|
65 |
+
public static function output_footer_code()
|
66 |
{
|
67 |
+
$site_footer_code = get_option('aFhfc_site_wide_footer_code');
|
68 |
+
$meta_footer_code = get_post_meta( get_the_ID(),'aFhfc_footer_code',true);
|
69 |
+
$footer_replace = get_post_meta(get_the_ID(),'aFhfc_footer_replace',true);
|
70 |
+
if(!empty($footer_replace)){
|
71 |
+
echo $meta_footer_code."\n";
|
72 |
+
}else{
|
73 |
+
echo $site_footer_code."\n".$meta_footer_code."\n";
|
74 |
+
}
|
75 |
}
|
76 |
}
|
77 |
if (is_admin())
|
91 |
Metabox w/head & footer fields for all post types (including custom)
|
92 |
*/
|
93 |
|
94 |
+
add_action('add_meta_boxes','aFhfc_add');
|
95 |
function aFhfc_add()
|
96 |
{
|
97 |
+
if(current_user_can('manage_options')){
|
98 |
+
add_meta_box('aFhfcMetaBox','Head & Footer Code','aFhfc_mtbx','','normal','high');
|
99 |
}
|
100 |
}
|
101 |
+
function aFhfc_mtbx($post)
|
102 |
{
|
103 |
+
$values = get_post_custom($post->ID);
|
104 |
+
$head_text = isset($values['aFhfc_head_code']) ? esc_attr($values['aFhfc_head_code'][0]) : '';
|
105 |
+
$head_replace = isset($values['aFhfc_head_replace']) ? esc_attr($values['aFhfc_head_replace'][0]) : '';
|
106 |
+
$footer_text = isset($values['aFhfc_footer_code']) ? esc_attr($values['aFhfc_footer_code'][0]) : '';
|
107 |
+
$footer_replace = isset($values['aFhfc_footer_replace']) ? esc_attr($values['aFhfc_footer_replace'][0]) : '';
|
108 |
+
wp_nonce_field('aFhfc_nonce', 'aFhfc_mb_nonce');
|
109 |
?>
|
110 |
<p>
|
111 |
<label for="aFhfc_head_code">Head:</label>
|
112 |
<textarea class="large-text" name="aFhfc_head_code" id="aFhfc_head_code"><?php echo $head_text; ?></textarea>
|
113 |
+
<input id="aFhfc_head_replace" type="checkbox" name="aFhfc_head_replace" value="1" <?php checked($head_replace,'1'); ?> />
|
114 |
+
<label for="aFhfc_head_replace">Replace Site-wide Head Code</label>
|
115 |
</p>
|
116 |
<p>
|
117 |
<label for="aFhfc_footer_code">Footer:</label>
|
118 |
<textarea class="large-text" name="aFhfc_footer_code" id="aFhfc_footer_code"><?php echo $footer_text; ?></textarea>
|
119 |
+
<input id="aFhfc_footer_replace" type="checkbox" name="aFhfc_footer_replace" value="1" <?php checked($footer_replace,'1'); ?> />
|
120 |
+
<label for="aFhfc_footer_replace">Replace Site-wide Footer Code</label>
|
121 |
</p>
|
122 |
<?php
|
123 |
}
|
124 |
+
add_action('save_post','aFhfc_save');
|
125 |
+
function aFhfc_save($post_id)
|
126 |
{
|
127 |
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
|
128 |
if( !isset( $_POST['aFhfc_mb_nonce'] ) || !wp_verify_nonce( $_POST['aFhfc_mb_nonce'], 'aFhfc_nonce' ) ) return;
|
129 |
if( !current_user_can( 'manage_options' ) ) return;
|
130 |
if( isset( $_POST['aFhfc_head_code'] ) )
|
131 |
+
if( empty( $_POST['aFhfc_head_code'] ) )
|
132 |
+
delete_post_meta( $post_id, 'aFhfc_head_code' );
|
133 |
+
else
|
134 |
+
update_post_meta( $post_id, 'aFhfc_head_code',$_POST['aFhfc_head_code'] );
|
135 |
+
$aFHFCHRChk = (isset($_POST['aFhfc_head_replace']) && $_POST['aFhfc_head_replace'])? '1' : '';
|
136 |
+
if(empty($_POST['aFhfc_head_replace']))
|
137 |
+
delete_post_meta($post_id,'aFhfc_head_replace');
|
138 |
+
else
|
139 |
+
update_post_meta($post_id,'aFhfc_head_replace',$aFHFCHRChk);
|
140 |
if( isset( $_POST['aFhfc_footer_code'] ) )
|
141 |
+
if( empty( $_POST['aFhfc_footer_code'] ) )
|
142 |
+
delete_post_meta( $post_id, 'aFhfc_footer_code' );
|
143 |
+
else
|
144 |
+
update_post_meta( $post_id, 'aFhfc_footer_code', $_POST['aFhfc_footer_code'] );
|
145 |
+
$aFHFCFRChk = (isset($_POST['aFhfc_footer_replace']) && $_POST['aFhfc_footer_replace'])? '1' : '';
|
146 |
+
if(empty($_POST['aFhfc_footer_replace']))
|
147 |
+
delete_post_meta($post_id,'aFhfc_footer_replace');
|
148 |
+
else
|
149 |
+
update_post_meta($post_id,'aFhfc_footer_replace',$aFHFCFRChk);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
}
|
|
options.php
CHANGED
@@ -19,6 +19,8 @@
|
|
19 |
</div> <!-- post-body-content -->
|
20 |
<!-- sidebar -->
|
21 |
<div id="postbox-container-1" class="postbox-container">
|
|
|
|
|
22 |
</div> <!-- #postbox-container-1 .postbox-container -->
|
23 |
</div> <!-- #post-body .metabox-holder .columns-2 -->
|
24 |
<br class="clear">
|
19 |
</div> <!-- post-body-content -->
|
20 |
<!-- sidebar -->
|
21 |
<div id="postbox-container-1" class="postbox-container">
|
22 |
+
<h2></h2>
|
23 |
+
<p></p>
|
24 |
</div> <!-- #postbox-container-1 .postbox-container -->
|
25 |
</div> <!-- #post-body .metabox-holder .columns-2 -->
|
26 |
<br class="clear">
|
readme.txt
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
|
2 |
=== AddFunc Head & Footer Code ===
|
3 |
|
4 |
-
Contributors: AddFunc,
|
5 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7AF7P3TFKQ2C2
|
6 |
Tags: head code, footer code, add to head, per page, script, tracking code, Google Analytics, javascript, meta tags, insert code, wp_head, wp_footer
|
7 |
Requires at least: 3.0.1
|
8 |
-
Tested up to: 4.
|
9 |
-
Stable tag: 1.
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
@@ -46,7 +46,7 @@ Wherever `wp_footer()` is located in your theme.
|
|
46 |
|
47 |
= Will AddFunc Head & Footer Code work if there is no `wp_head()` or `wp_footer()` in my theme? =
|
48 |
|
49 |
-
Wherever one of those functions is missing, your code will not be output there. But omitting one of them does not stop the other one from working. AddFunc Head & Footer Code will also save your code regardless. It just can't output your code without the presence of those functions in the theme.
|
50 |
|
51 |
= Does it really require WordPress 3.0.1 or later? =
|
52 |
|
@@ -60,10 +60,21 @@ Yes. [addfunc.com](http://addfunc.com/)
|
|
60 |
|
61 |
1. Simply paste your code into one of these two fields and it will be included on every page of your website.
|
62 |
|
63 |
-
2. Add your code to these fields respectively and it will output specifically to this page, post or custom post type.
|
64 |
|
65 |
== Changelog ==
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
= 1.3 =
|
68 |
23-Jun-2015
|
69 |
|
@@ -72,50 +83,50 @@ Yes. [addfunc.com](http://addfunc.com/)
|
|
72 |
= 1.2 =
|
73 |
19-Jun-2015
|
74 |
|
75 |
-
* Discovered addfunc-head-footer-code.php was saved with text encoding Western (Mac OS Roman). ~>:( Changed to Unicode (UTF-8)
|
76 |
-
* This was probably changed during a recent update on the plugin's tags (the tags for the WordPress Plugin Repository), so maybe two weeks ago. Previous downloads should have been UTF-8
|
77 |
-
* Also changed version 1.1 to UTF-8 because leaving a Mac OS Roman version in the repository would be pointless. So 1.1 and 1.2 are the same, except for the readme.txt
|
78 |
|
79 |
= 1.1 =
|
80 |
28-Nov-2014
|
81 |
|
82 |
-
* Fixes meta box nounce
|
83 |
-
* Changes all references to Average (including but not limited to "avrg", "average", etc.) to relate to AddFunc (changing project name)
|
84 |
-
* Changes a few other function and variable names for namespacing purposes
|
85 |
-
* Submitted to WordPress under the name AddFunc
|
86 |
|
87 |
= 1.0 =
|
88 |
7-Aug-2014
|
89 |
|
90 |
-
* Includes readme.txt
|
91 |
-
* Submitted to WordPress
|
92 |
|
93 |
= 0.4.1 =
|
94 |
6-Aug-2014
|
95 |
|
96 |
-
* Code cleaned up (mostly comments removed)
|
97 |
-
* Excludes unnecessary file: style.css
|
98 |
|
99 |
= 0.4 =
|
100 |
8-Jul-2014
|
101 |
|
102 |
-
* Bug fix: replaced "my-meta-box-id" with "avrghdftrcdMetaBox" (duh)
|
103 |
|
104 |
= 0.3 =
|
105 |
27-Oct-2013
|
106 |
|
107 |
-
* Hid Head & Footer Code meta box from non-admin users
|
108 |
|
109 |
= 0.2 =
|
110 |
15-Oct-2013
|
111 |
|
112 |
-
* Adds a Head & Footer Code settings page for site-wide code (for admins only)
|
113 |
|
114 |
= 0.1 =
|
115 |
14-Aug-2013
|
116 |
|
117 |
-
* Adds Head & Footer Code meta box to all pages, posts and cusom post types
|
118 |
-
* Saves Head & Footer Code entry to the database as custom fields
|
119 |
-
* Outputs code to the website in `wp_head()` and `wp_footer()
|
120 |
|
121 |
== Upgrade Notice ==
|
1 |
|
2 |
=== AddFunc Head & Footer Code ===
|
3 |
|
4 |
+
Contributors: AddFunc,joerhoney
|
5 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7AF7P3TFKQ2C2
|
6 |
Tags: head code, footer code, add to head, per page, script, tracking code, Google Analytics, javascript, meta tags, insert code, wp_head, wp_footer
|
7 |
Requires at least: 3.0.1
|
8 |
+
Tested up to: 4.8
|
9 |
+
Stable tag: 1.4
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
46 |
|
47 |
= Will AddFunc Head & Footer Code work if there is no `wp_head()` or `wp_footer()` in my theme? =
|
48 |
|
49 |
+
Wherever one of those functions is missing, your code will not be output there. But omitting one of them does not stop the other one from working. AddFunc Head & Footer Code will also save your code regardless. It just can't output your code without the presence of those functions in the theme.
|
50 |
|
51 |
= Does it really require WordPress 3.0.1 or later? =
|
52 |
|
60 |
|
61 |
1. Simply paste your code into one of these two fields and it will be included on every page of your website.
|
62 |
|
63 |
+
2. Add your code to these fields respectively and it will output specifically to this page, post or custom post type. Optionally replace or remove the site-wide code on any individual post or page.
|
64 |
|
65 |
== Changelog ==
|
66 |
|
67 |
+
= 1.4 =
|
68 |
+
3-Apr-2017
|
69 |
+
|
70 |
+
* Adds option for individual post code to replace the site-wide code:
|
71 |
+
- Head and footer managed independently of each other
|
72 |
+
- Individual post code appends to site-wide by default
|
73 |
+
- Check the *Replace Site-wide Head/Footer Code* checkbox to replace or remove the Site-wide code for the respective area
|
74 |
+
* Fixes post meta fields:
|
75 |
+
- No longer saves post meta fields when not needed
|
76 |
+
- Deletes post meta fields if empty when saved/updated
|
77 |
+
|
78 |
= 1.3 =
|
79 |
23-Jun-2015
|
80 |
|
83 |
= 1.2 =
|
84 |
19-Jun-2015
|
85 |
|
86 |
+
* Discovered addfunc-head-footer-code.php was saved with text encoding Western (Mac OS Roman). ~>:( Changed to Unicode (UTF-8).
|
87 |
+
* This was probably changed during a recent update on the plugin's tags (the tags for the WordPress Plugin Repository), so maybe two weeks ago. Previous downloads should have been UTF-8.
|
88 |
+
* Also changed version 1.1 to UTF-8 because leaving a Mac OS Roman version in the repository would be pointless. So 1.1 and 1.2 are the same, except for the readme.txt.
|
89 |
|
90 |
= 1.1 =
|
91 |
28-Nov-2014
|
92 |
|
93 |
+
* Fixes meta box nounce.
|
94 |
+
* Changes all references to Average (including but not limited to "avrg", "average", etc.) to relate to AddFunc (changing project name).
|
95 |
+
* Changes a few other function and variable names for namespacing purposes.
|
96 |
+
* Submitted to WordPress under the name AddFunc.
|
97 |
|
98 |
= 1.0 =
|
99 |
7-Aug-2014
|
100 |
|
101 |
+
* Includes readme.txt.
|
102 |
+
* Submitted to WordPress.
|
103 |
|
104 |
= 0.4.1 =
|
105 |
6-Aug-2014
|
106 |
|
107 |
+
* Code cleaned up (mostly comments removed).
|
108 |
+
* Excludes unnecessary file: style.css.
|
109 |
|
110 |
= 0.4 =
|
111 |
8-Jul-2014
|
112 |
|
113 |
+
* Bug fix: replaced "my-meta-box-id" with "avrghdftrcdMetaBox" (duh).
|
114 |
|
115 |
= 0.3 =
|
116 |
27-Oct-2013
|
117 |
|
118 |
+
* Hid Head & Footer Code meta box from non-admin users.
|
119 |
|
120 |
= 0.2 =
|
121 |
15-Oct-2013
|
122 |
|
123 |
+
* Adds a Head & Footer Code settings page for site-wide code (for admins only).
|
124 |
|
125 |
= 0.1 =
|
126 |
14-Aug-2013
|
127 |
|
128 |
+
* Adds Head & Footer Code meta box to all pages, posts and cusom post types.
|
129 |
+
* Saves Head & Footer Code entry to the database as custom fields.
|
130 |
+
* Outputs code to the website in `wp_head()` and `wp_footer()`.
|
131 |
|
132 |
== Upgrade Notice ==
|