Head & Footer Code - Version 1.1.0

Version Description

  • Tested: on WordPress 5.1.4, 5.3.2 and 5.4-beta3 with PHP 7.2.15 and 7.3.7
  • Fix: Backslashes are removed on post/page update in article specific HEAD/BODY/FOOTER code reported by @asherber (update_post_meta pass key and value to update_metadata which expect them slashed key and value)
  • Add: Support for wp_body_open Body hook introduced in WordPress 5.2
  • Add: Backward compatibility for wp_body_open for older WordPress installations
  • Add: FAQ Instructions on how to implement support for wp_body_open to any theme
  • Update: Links and wording on plugin settings page
  • Update: Screenshots
Download this release

Release Info

Developer urkekg
Plugin Icon Head & Footer Code
Version 1.1.0
Comparing to
See all releases

Code changes from version 1.0.9.1 to 1.1.0

head-footer-code.php CHANGED
@@ -7,8 +7,8 @@
7
* @wordpress-plugin
8
* Plugin Name: Head & Footer Code
9
* Plugin URI: https://urosevic.net/wordpress/plugins/head-footer-code/
10
- * Description: Easy add site-wide and/or article specific custom code to head and/or footer sections (before the &lt;/head&gt; or &lt;/body&gt;) by hooking to <code>wp_head</code> and <code>wp_footer</code>.
11
- * Version: 1.0.9.1
12
* Author: Aleksandar Urosevic
13
* Author URI: https://urosevic.net
14
* License: GPL-3.0+
@@ -22,8 +22,8 @@ if ( ! defined( 'WPINC' ) ) {
22
die;
23
}
24
25
- define( 'WPAU_HEAD_FOOTER_CODE_VER', '1.0.9.1' );
26
- define( 'WPAU_HEAD_FOOTER_CODE_DB_VER', '2' );
27
define( 'WPAU_HEAD_FOOTER_CODE_FILE', basename( __FILE__ ) );
28
define( 'WPAU_HEAD_FOOTER_CODE_INC', dirname( __FILE__ ) . '/inc/' );
29
7
* @wordpress-plugin
8
* Plugin Name: Head & Footer Code
9
* Plugin URI: https://urosevic.net/wordpress/plugins/head-footer-code/
10
+ * Description: Easy add site-wide and/or article specific custom code to head and/or footer sections (before the &lt;/head&gt; or &lt;/body&gt; or opening &lt;body&gt;) by hooking to <code>wp_head</code>, <code>wp_footer</code> and <code>wp_body_open</code>.
11
+ * Version: 1.1.0
12
* Author: Aleksandar Urosevic
13
* Author URI: https://urosevic.net
14
* License: GPL-3.0+
22
die;
23
}
24
25
+ define( 'WPAU_HEAD_FOOTER_CODE_VER', '1.1.0' );
26
+ define( 'WPAU_HEAD_FOOTER_CODE_DB_VER', '3' );
27
define( 'WPAU_HEAD_FOOTER_CODE_FILE', basename( __FILE__ ) );
28
define( 'WPAU_HEAD_FOOTER_CODE_INC', dirname( __FILE__ ) . '/inc/' );
29
inc/class-auhfc-meta-box.php CHANGED
@@ -48,11 +48,12 @@ abstract class AUHfc_Meta_Box {
48
if ( ! empty( $_POST['auhfc'] ) ) {
49
50
$auhfc['head'] = ( ! empty( $_POST['auhfc']['head'] ) ) ? $_POST['auhfc']['head'] : '';
51
$auhfc['footer'] = ( ! empty( $_POST['auhfc']['footer'] ) ) ? $_POST['auhfc']['footer'] : '';
52
$auhfc['behavior'] = ( ! empty( $_POST['auhfc']['behavior'] ) ) ? $_POST['auhfc']['behavior'] : '';
53
54
if ( ! empty( $auhfc ) ) {
55
- update_post_meta( $post_id, '_auhfc', $auhfc );
56
}
57
}
58
@@ -65,7 +66,7 @@ abstract class AUHfc_Meta_Box {
65
*/
66
public static function html( $post ) {
67
wp_nonce_field( '_head_footer_code_nonce', 'head_footer_code_nonce' ); ?>
68
- <p>Here you can insert article specific code for Head (before the <code>&lt;/head&gt;</code>) and Footer (before the <code>&lt;/body&gt;</code>) sections. They work in exactly the same way as site-wide code, which you can configure under <a href="tools.php?page=head_footer_code">Tools / Head &amp; Footer Code</a>.</p>
69
<label><?php esc_attr_e( 'Behavior', 'head-footer-code' ); ?></label><br />
70
<select name="auhfc[behavior]" id="auhfc_behavior_replace">
71
<option value="append" <?php echo ( 'append' === auhfc_get_meta( 'behavior' ) ) ? 'selected' : ''; ?>>Append to the site-wide code</option>
@@ -76,6 +77,10 @@ abstract class AUHfc_Meta_Box {
76
<textarea name="auhfc[head]" id="auhfc_head" class="widefat code" rows="5"><?php echo auhfc_get_meta( 'head' ); ?></textarea>
77
<p class="description">Example: <code>&lt;link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/style.css" type="text/css" media="all"&gt;</code></p>
78
<br />
79
<label for="auhfc_footer"><?php _e( 'Footer Code', 'head-footer-code' ); ?></label><br />
80
<textarea name="auhfc[footer]" id="auhfc_footer" class="widefat code" rows="5"><?php echo auhfc_get_meta( 'footer' ); ?></textarea>
81
<p class="description">Example: <code>&lt;script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/script.js"&gt;&lt;/script&gt;</code></p>
48
if ( ! empty( $_POST['auhfc'] ) ) {
49
50
$auhfc['head'] = ( ! empty( $_POST['auhfc']['head'] ) ) ? $_POST['auhfc']['head'] : '';
51
+ $auhfc['body'] = ( ! empty( $_POST['auhfc']['body'] ) ) ? $_POST['auhfc']['body'] : '';
52
$auhfc['footer'] = ( ! empty( $_POST['auhfc']['footer'] ) ) ? $_POST['auhfc']['footer'] : '';
53
$auhfc['behavior'] = ( ! empty( $_POST['auhfc']['behavior'] ) ) ? $_POST['auhfc']['behavior'] : '';
54
55
if ( ! empty( $auhfc ) ) {
56
+ update_post_meta( $post_id, '_auhfc', wp_slash( $auhfc ) );
57
}
58
}
59
66
*/
67
public static function html( $post ) {
68
wp_nonce_field( '_head_footer_code_nonce', 'head_footer_code_nonce' ); ?>
69
+ <p>Here you can insert article specific code for Head (before the <code>&lt;/head&gt;</code>), Body (after the <code>&lt;body&gt;</code>) and Footer (before the <code>&lt;/body&gt;</code>) sections. They work in exactly the same way as site-wide code, which you can configure under <a href="tools.php?page=head_footer_code">Tools / Head &amp; Footer Code</a>.</p>
70
<label><?php esc_attr_e( 'Behavior', 'head-footer-code' ); ?></label><br />
71
<select name="auhfc[behavior]" id="auhfc_behavior_replace">
72
<option value="append" <?php echo ( 'append' === auhfc_get_meta( 'behavior' ) ) ? 'selected' : ''; ?>>Append to the site-wide code</option>
77
<textarea name="auhfc[head]" id="auhfc_head" class="widefat code" rows="5"><?php echo auhfc_get_meta( 'head' ); ?></textarea>
78
<p class="description">Example: <code>&lt;link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/style.css" type="text/css" media="all"&gt;</code></p>
79
<br />
80
+ <label for="auhfc_body"><?php _e( 'Body Code', 'body-footer-code' ); ?></label><br />
81
+ <textarea name="auhfc[body]" id="auhfc_body" class="widefat code" rows="5"><?php echo auhfc_get_meta( 'body' ); ?></textarea>
82
+ <p class="description">Example: <code>&lt;script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/body-start.js" type="text/css" media="all"&gt;&lt;/script&gt;</code></p>
83
+ <br />
84
<label for="auhfc_footer"><?php _e( 'Footer Code', 'head-footer-code' ); ?></label><br />
85
<textarea name="auhfc[footer]" id="auhfc_footer" class="widefat code" rows="5"><?php echo auhfc_get_meta( 'footer' ); ?></textarea>
86
<p class="description">Example: <code>&lt;script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/script.js"&gt;&lt;/script&gt;</code></p>
inc/front.php CHANGED
@@ -5,18 +5,22 @@ if ( ! defined( 'WPINC' ) ) {
5
}
6
7
/**
8
- * Inject site-wide code to head and footer with custom priorty.
9
*/
10
$auhfc_defaults = auhfc_defaults();
11
12
if ( empty( $auhfc_defaults['priority_h'] ) ) {
13
$auhfc_defaults['priority_h'] = 10;
14
}
15
if ( empty( $auhfc_defaults['priority_f'] ) ) {
16
$auhfc_defaults['priority_f'] = 10;
17
}
18
// Define actions for HEAD and FOOTER
19
add_action( 'wp_head', 'auhfc_wp_head', $auhfc_defaults['priority_h'] );
20
add_action( 'wp_footer', 'auhfc_wp_footer', $auhfc_defaults['priority_f'] );
21
22
/**
@@ -80,6 +84,68 @@ function auhfc_wp_head() {
80
81
} // END function auhfc_wp_head()
82
83
/**
84
* Inject site-wide and Article specific footer code before the </body>
85
*/
@@ -139,3 +205,12 @@ function auhfc_wp_footer() {
139
unset( $auhfc_post_type, $auhfc_settings, $auhfc_meta, $behavior, $out );
140
141
} // END function auhfc_wp_footer()
5
}
6
7
/**
8
+ * Inject site-wide code to head, body and footer with custom priorty.
9
*/
10
$auhfc_defaults = auhfc_defaults();
11
12
if ( empty( $auhfc_defaults['priority_h'] ) ) {
13
$auhfc_defaults['priority_h'] = 10;
14
}
15
+ if ( empty( $auhfc_defaults['priority_b'] ) ) {
16
+ $auhfc_defaults['priority_b'] = 10;
17
+ }
18
if ( empty( $auhfc_defaults['priority_f'] ) ) {
19
$auhfc_defaults['priority_f'] = 10;
20
}
21
// Define actions for HEAD and FOOTER
22
add_action( 'wp_head', 'auhfc_wp_head', $auhfc_defaults['priority_h'] );
23
+ add_action( 'wp_body_open', 'auhfc_wp_body', $auhfc_defaults['priority_b'] );
24
add_action( 'wp_footer', 'auhfc_wp_footer', $auhfc_defaults['priority_f'] );
25
26
/**
84
85
} // END function auhfc_wp_head()
86
87
+
88
+ /**
89
+ * Inject site-wide and Article specific body code right after opening <body>
90
+ */
91
+ function auhfc_wp_body() {
92
+
93
+ // Get post type
94
+ if ( is_singular() ) {
95
+ global $wp_the_query;
96
+ $auhfc_post_type = $wp_the_query->get_queried_object()->post_type;
97
+ } else {
98
+ $auhfc_post_type = 'not singular';
99
+ }
100
+
101
+ // Get variables to test
102
+ $auhfc_settings = auhfc_defaults();
103
+
104
+ // Get meta for post only if it's singular
105
+ if ( 'not singular' !== $auhfc_post_type && in_array( $auhfc_post_type, $auhfc_settings['post_types'] ) ) {
106
+ $auhfc_meta = auhfc_get_meta( 'body' );
107
+ $behavior = auhfc_get_meta( 'behavior' );
108
+ $dbg_set = "type: {$auhfc_post_type}; bahavior: {$behavior}; priority: {$auhfc_settings['priority_b']}; do_shortcode: {$auhfc_settings['do_shortcode']}";
109
+ } else {
110
+ $auhfc_meta = '';
111
+ $behavior = '';
112
+ $dbg_set = $auhfc_post_type;
113
+ }
114
+
115
+ // If no code to inject, simple exit
116
+ if ( empty( $auhfc_settings['body'] ) && empty( $auhfc_meta ) ) {
117
+ return;
118
+ }
119
+
120
+ // Prepare code output.
121
+ $out = '';
122
+
123
+ // Inject site-wide body code
124
+ if (
125
+ ! empty( $auhfc_settings['body'] ) &&
126
+ (
127
+ 'replace' !== $behavior ||
128
+ ( 'replace' == $behavior && ! in_array( $auhfc_post_type, $auhfc_settings['post_types'] ) ) ||
129
+ ( 'replace' == $behavior && in_array( $auhfc_post_type, $auhfc_settings['post_types'] ) && empty( $auhfc_meta ) )
130
+ )
131
+ ) {
132
+ $out .= auhfc_out( 's', 'b', $dbg_set, $auhfc_settings['body'] );
133
+ }
134
+
135
+ // Inject article specific body code if post_type is allowed
136
+ if ( ! empty( $auhfc_meta ) && in_array( $auhfc_post_type, $auhfc_settings['post_types'] ) ) {
137
+ $out .= auhfc_out( 'a', 'b', $dbg_set, $auhfc_meta );
138
+ }
139
+
140
+ // Print prepared code.
141
+ echo $out;
142
+ // echo ( 'y' === $auhfc_settings['do_shortcode'] ) ? do_shortcode( $out ) : $out;
143
+
144
+ // Free some memory.
145
+ unset( $auhfc_post_type, $auhfc_settings, $auhfc_meta, $behavior, $out );
146
+
147
+ } // END function auhfc_wp_body()
148
+
149
/**
150
* Inject site-wide and Article specific footer code before the </body>
151
*/
205
unset( $auhfc_post_type, $auhfc_settings, $auhfc_meta, $behavior, $out );
206
207
} // END function auhfc_wp_footer()
208
+
209
+ /**
210
+ * Add `wp_body_open` backward compatibility for WordPress installations prior 5.2
211
+ */
212
+ if ( ! function_exists( 'wp_body_open' ) ) {
213
+ function wp_body_open() {
214
+ do_action( 'wp_body_open' );
215
+ }
216
+ }
inc/helpers.php CHANGED
@@ -136,7 +136,7 @@ function auhfc_get_meta( $field_name = '' ) {
136
/**
137
* Return debugging string if WP_DEBUG constant is true.
138
* @param string $scope Scope of output (s - SITE WIDE, a - ARTICLE SPECIFIC)
139
- * @param string $location Location of output (h - HEAD, f - FOOTER)
140
* @param string $message Output message
141
* @param string $code Code for output
142
* @return string Composed string
@@ -149,7 +149,20 @@ function auhfc_out( $scope = null, $location = null, $message = null, $code = nu
149
return;
150
}
151
$scope = 's' == $scope ? 'Site-wide' : 'Article specific';
152
- $location = 'h' == $location ? 'HEAD' : 'FOOTER';
153
return sprintf(
154
'<!-- Head & Footer Code: %1$s %2$s section start (%3$s) -->%5$s %4$s%5$s<!-- Head & Footer Code: %1$s %2$s section end (%3$s) -->%5$s',
155
$scope, // 1
@@ -159,3 +172,7 @@ function auhfc_out( $scope = null, $location = null, $message = null, $code = nu
159
"\n" // 5
160
);
161
} // END function auhfc_out( $scope = null, $location = null, $message = null, $code = null )
136
/**
137
* Return debugging string if WP_DEBUG constant is true.
138
* @param string $scope Scope of output (s - SITE WIDE, a - ARTICLE SPECIFIC)
139
+ * @param string $location Location of output (h - HEAD, b - BODY, f - FOOTER)
140
* @param string $message Output message
141
* @param string $code Code for output
142
* @return string Composed string
149
return;
150
}
151
$scope = 's' == $scope ? 'Site-wide' : 'Article specific';
152
+ switch ( $location ) {
153
+ case 'h':
154
+ $location = 'HEAD';
155
+ break;
156
+ case 'b':
157
+ $location = 'BODY';
158
+ break;
159
+ case 'f':
160
+ $location = 'FOOTER';
161
+ break;
162
+ default:
163
+ $location = 'UNKNOWN';
164
+ break;
165
+ }
166
return sprintf(
167
'<!-- Head & Footer Code: %1$s %2$s section start (%3$s) -->%5$s %4$s%5$s<!-- Head & Footer Code: %1$s %2$s section end (%3$s) -->%5$s',
168
$scope, // 1
172
"\n" // 5
173
);
174
} // END function auhfc_out( $scope = null, $location = null, $message = null, $code = null )
175
+
176
+ function auhfc_body_note() {
177
+ return '<p class="notice"><strong>Please note!</strong> Usage of this hook should be reserved for output of <em>unseen elements</em> like <code>&lt;script&gt;</code> tags or additional metadata. It should not be used to add arbitrary HTML content to a page that <em>could break layouts or lead to unexpected situations</em>. Make sure that your active theme support <a href="https://developer.wordpress.org/reference/hooks/wp_body_open/" target="_hook">wp_body_open</a> hook.</p>';
178
+ }
inc/settings.php CHANGED
@@ -117,6 +117,47 @@ function auhfc_settings_init() {
117
'step' => 1,
118
]
119
);
120
add_settings_field(
121
'auhfc_footer_code',
122
__( 'FOOTER Code', 'head-footer-code' ),
@@ -126,7 +167,10 @@ function auhfc_settings_init() {
126
[
127
'field' => 'auhfc_settings[footer]',
128
'value' => $auhfc_settings['footer'],
129
- 'description' => esc_html__( 'Code to enqueue in footer section (before the </body>)', 'head-footer-code' ),
130
'field_class' => 'widefat code',
131
'rows' => 7,
132
]
@@ -201,7 +245,7 @@ function auhfc_settings_init() {
201
'field' => 'auhfc_settings[post_types]',
202
'items' => $clean_post_types,
203
'value' => $auhfc_settings['post_types'],
204
- 'description' => esc_html__( 'Select which post types will have Article specific section. Default is post and page. Please note, even if you have Head/Footer Code set per article and then you disable that post type, article specific code will not be printed but only site-wide code.', 'head-footer-code' ),
205
'class' => 'checkbox',
206
]
207
);
117
'step' => 1,
118
]
119
);
120
+
121
+ $wp52note = version_compare( get_bloginfo( 'version' ),'5.2', '<') ? ' Require WordPress 5.2+' : '';
122
+
123
+ add_settings_field(
124
+ 'auhfc_body_code',
125
+ __( 'BODY Code', 'head-footer-code' ),
126
+ 'auhfc_textarea_field_render',
127
+ 'head_footer_code',
128
+ 'head_footer_code_sitewide_settings',
129
+ [
130
+ 'field' => 'auhfc_settings[body]',
131
+ 'value' => $auhfc_settings['body'],
132
+ 'description' => __(
133
+ auhfc_body_note() . 'Code to enqueue in BODY section.' . $wp52note,
134
+ 'body-footer-code'
135
+ ),
136
+ 'field_class' => 'widefat code',
137
+ 'rows' => 7,
138
+ ]
139
+ );
140
+
141
+ add_settings_field(
142
+ 'auhfc_priority_b',
143
+ __( 'BODY Priority', 'head-footer-code' ),
144
+ 'auhfc_number_field_render',
145
+ 'head_footer_code',
146
+ 'head_footer_code_sitewide_settings',
147
+ [
148
+ 'field' => 'auhfc_settings[priority_b]',
149
+ 'value' => $auhfc_settings['priority_b'],
150
+ 'description' => esc_html__(
151
+ 'Priority for enqueued BODY code. Default is 10. Smaller number inject code closer to <body>.' . $wp52note,
152
+ 'head-footer-code'
153
+ ),
154
+ 'class' => 'num',
155
+ 'min' => 1,
156
+ 'max' => 1000,
157
+ 'step' => 1,
158
+ ]
159
+ );
160
+
161
add_settings_field(
162
'auhfc_footer_code',
163
__( 'FOOTER Code', 'head-footer-code' ),
167
[
168
'field' => 'auhfc_settings[footer]',
169
'value' => $auhfc_settings['footer'],
170
+ 'description' => esc_html__(
171
+ 'Code to enqueue in footer section (before the </body>)',
172
+ 'head-footer-code'
173
+ ),
174
'field_class' => 'widefat code',
175
'rows' => 7,
176
]
245
'field' => 'auhfc_settings[post_types]',
246
'items' => $clean_post_types,
247
'value' => $auhfc_settings['post_types'],
248
+ 'description' => esc_html__( 'Select which post types will have Article specific section. Please note, even if you have Head/Footer Code set per article and then you disable that post type, article specific code will not be printed but only site-wide code.', 'head-footer-code' ),
249
'class' => 'checkbox',
250
]
251
);
inc/update.php CHANGED
@@ -85,3 +85,26 @@ function auhfc_update_2() {
85
update_option( 'auhfc_settings', $defaults );
86
87
} // END function auhfc_update_2()
85
update_option( 'auhfc_settings', $defaults );
86
87
} // END function auhfc_update_2()
88
+
89
+
90
+ /**
91
+ * Initialize updater
92
+ */
93
+ function auhfc_update_3() {
94
+
95
+ // Get options from DB.
96
+ $defaults = get_option( 'auhfc_settings' );
97
+
98
+ // Add empty body field to options.
99
+ if ( ! isset( $defaults['body'] ) ) {
100
+ $defaults['body'] = '';
101
+ }
102
+ // Add body field priority to options.
103
+ if ( ! isset( $defaults['priority_b'] ) ) {
104
+ $defaults['priority_b'] = 10;
105
+ }
106
+
107
+ // Save settings to DB.
108
+ update_option( 'auhfc_settings', $defaults );
109
+
110
+ } // END function auhfc_update_3()
readme.txt CHANGED
@@ -1,27 +1,27 @@
1
=== Head & Footer Code ===
2
Contributors: urkekg
3
Donate link: https://urosevic.net/wordpress/donate/?donate_for=head-footer-code
4
- Tags: wp_head, wp_footer, head footer code, custom head script, custom footer script, google analytics, pixel tracking, tracking code, javascript, scripts, site verification, css
5
Requires at least: 4.9
6
- Tested up to: 5.1.1
7
- Stable tag: 1.0.9.1
8
Requires PHP: 5.6
9
License: GPLv3 or later
10
License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
12
- Easy add site-wide and/or article specific custom code before the &lt;/head&gt; or &lt;/body&gt; by hooking to wp_head and wp_footer. Multisite is supported!
13
14
== Description ==
15
16
- Let we say that you have been told to add some custom code (HTML, JavaScript or CSS style) to page's `<head>` (like site verification code, custom styles, webfont link, etc), or just before `</body>` (like pixel tracking, analytics code, heatmap code, etc), but you are not programmer. Then you can use Head &amp; Footer Code to do that.
17
18
- Simply go to Tools &rarr; Head &amp; Footer Code in your website admin dashboard, and insert custom code to HEAD or FOOTER section (depending what you have to do).
19
20
- If you have to insert some custom code specific for individual article (post, page, custom post type), then you can use Article specific metabox while you editing post/page/custom post type (check out [Screenshots](https://wordpress.org/plugins/head-footer-code/screenshots/)). There you can also set should that specific code be appended to site-wide code defined on **Tools** &rarr; **Head &amp; Footer Code**, or should be overwritten.
21
22
**Works or broken?**
23
24
- Please, consider to vote for this plugin. When you vote for broken, be so kind and tell in the [Forum](https://wordpress.org/support/plugin/head-footer-code) what is broken. Maybe I might be able to fix it to make the plugin also work for you.
25
26
**I need your support**
27
@@ -30,17 +30,19 @@ It is very hard to continue development and support for this and my other free p
30
**Features**
31
32
* Set site-wide custom content for head page section (before the `</head>`)
33
* Set site-wide custom content for footer page section (before the `</body>`)
34
* Set article specific custom code for head page section (before the `</head>`)
35
* Set article specific custom content for footer page section (before the `</body>`)
36
- * Choose priority of printed custom code to head/footer sections (lower number mean far from `</head>` and `</body>`, higher number means closer to `</head>` and `</body>`)
37
- * Choose which post types will have enabled article specific head/footer fields
38
- * Choose should article specific head/footer code be appended to site-wide code, or will replace site-wide code
39
* Site-wide section located under **Tools** > **Head & Footer Code**
40
* If you have set WP_DEBUG constant in `wp-config.php` to `true`, you'll see site-wide and article specific entries in page source code wrapped to comments.
41
42
- General settings, including HEAD, FOOTER global code and priority, have been saved to WordPress option `auhfc_settings`.
43
- Each post/page/custom post type specific HEAD and FOOTER code have been saved to post meta `_auhfc`.
44
On plugin uninstall these data is also deleted from database.
45
46
== Installation ==
@@ -71,13 +73,23 @@ Installation of this plugin is fairly easy as any other WordPress plugin.
71
72
Because all other similar plugins could not satisfy my requirements. In general, they have too much features or lack some features I need.
73
74
== Screenshots ==
75
76
1. Head &amp; Footer Code box in Plugin search results
77
2. Site-wide settings page
78
3. Article specific metabox
79
4. Example of custom code inserted to HEAD section (site-wide with appended article specific)
80
- 5. Example of custom code inserted to FOOTER section (site-wide with appended article specific)
81
82
== Upgrade Notice ==
83
@@ -86,6 +98,15 @@ Initial release of new plugin developed by Aleksandar Urosevic.
86
87
== Changelog ==
88
89
= 1.0.9.1 =
90
* Fix: Fatal Error on Multisite WP's (thanks @kunzemarketing for reporting)
91
* Improve: DRI for front-end debugging
1
=== Head & Footer Code ===
2
Contributors: urkekg
3
Donate link: https://urosevic.net/wordpress/donate/?donate_for=head-footer-code
4
+ Tags: wp_head, wp_footer, head footer code, custom head script, custom body script, custom footer script, google analytics, facebook pixel, pixel tracking, tracking code, javascript, scripts, site verification, css
5
Requires at least: 4.9
6
+ Tested up to: 5.4-beta3
7
+ Stable tag: 1.1.0
8
Requires PHP: 5.6
9
License: GPLv3 or later
10
License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
12
+ Easy add site-wide and/or article specific custom code before the &lt;/head&gt; or &lt;/body&gt; or opening &lt;body&gt; by hooking to wp_head, wp_footer and wp_body_open. Multisite is supported!
13
14
== Description ==
15
16
+ Let we say that you have been told to add some custom code (HTML, JavaScript or CSS style) to page's `<head>` (like site verification code, custom styles, webfont link, etc), just before `</body>` or right after opening `<body>` (like pixel tracking, analytics code, heatmap code, etc), but you are not programmer. Then you can use Head &amp; Footer Code to do that.
17
18
+ Simply go to Tools &rarr; Head &amp; Footer Code in your website admin dashboard, and insert custom code to HEAD, BODY or FOOTER section (depending what you have to do).
19
20
+ If you have to insert some custom code specific for individual article (post, page, custom post type), then you can use Article specific metabox while you editing post/page/custom post type (check out [Screenshots](https://wordpress.org/plugins/head-footer-code/#screenshots)). There you can also set should that specific code be appended to site-wide code defined on **Tools** &rarr; **Head &amp; Footer Code**, or should be overwritten.
21
22
**Works or broken?**
23
24
+ Please, consider to vote for this plugin. When you vote for broken, be so kind and tell in the [Forum](https://wordpress.org/support/plugin/head-footer-code/) what is broken. Maybe I might be able to fix it to make the plugin also work for you.
25
26
**I need your support**
27
30
**Features**
31
32
* Set site-wide custom content for head page section (before the `</head>`)
33
+ * Set site-wide custom content for body section (after the `<body>`) - **Requires WordPress 5.2!**
34
* Set site-wide custom content for footer page section (before the `</body>`)
35
* Set article specific custom code for head page section (before the `</head>`)
36
+ * Set article specific custom code for body section (after the `<body>`) - **Requires WordPress 5.2!**
37
* Set article specific custom content for footer page section (before the `</body>`)
38
+ * Choose priority of printed custom code to head/body/footer sections (lower number mean far from `</head>` and `</body>` and closer to `<body>`, higher number means closer to `</head>` and `</body>` and farther to `<body>`)
39
+ * Choose which post types will have enabled article specific head/body/footer fields
40
+ * Choose should article specific head/body/footer code be appended to site-wide code, or will replace site-wide code
41
* Site-wide section located under **Tools** > **Head & Footer Code**
42
* If you have set WP_DEBUG constant in `wp-config.php` to `true`, you'll see site-wide and article specific entries in page source code wrapped to comments.
43
44
+ General settings, including HEAD, BODY, FOOTER global code and priority, have been saved to WordPress option `auhfc_settings`.
45
+ Each post/page/custom post type specific HEAD, BODY and FOOTER code have been saved to post meta `_auhfc`.
46
On plugin uninstall these data is also deleted from database.
47
48
== Installation ==
73
74
Because all other similar plugins could not satisfy my requirements. In general, they have too much features or lack some features I need.
75
76
+ = I entered code to BODY section but nothing output on front-end =
77
+
78
+ This feature is implemented since WordPress version 5.2, but also require compatibility theme. Make sure that your theme support [wp_body_open](https://developer.wordpress.org/reference/hooks/wp_body_open/) hook.
79
+
80
+ Open in code editor `header.php` file from theme you use, and check if right after opening `<BODY>` tag there is following code (if it does not exists, add it or ask some developer to do that for you):
81
+ ```if ( function_exists( 'wp_body_open' ) ) {
82
+ wp_body_open();
83
+ }```
84
+
85
== Screenshots ==
86
87
1. Head &amp; Footer Code box in Plugin search results
88
2. Site-wide settings page
89
3. Article specific metabox
90
4. Example of custom code inserted to HEAD section (site-wide with appended article specific)
91
+ 5. Example of custom code inserted to BODY section (site-wide with appended article specific)
92
+ 6. Example of custom code inserted to FOOTER section (site-wide with appended article specific)
93
94
== Upgrade Notice ==
95
98
99
== Changelog ==
100
101
+ = 1.1.0 =
102
+ * Tested: on WordPress 5.1.4, 5.3.2 and 5.4-beta3 with PHP 7.2.15 and 7.3.7
103
+ * Fix: Backslashes are removed on post/page update in article specific HEAD/BODY/FOOTER code reported by @asherber (`update_post_meta` pass key and value to `update_metadata` which expect them slashed key and value)
104
+ * Add: Support for `wp_body_open` Body hook introduced in WordPress 5.2
105
+ * Add: Backward compatibility for `wp_body_open` for older WordPress installations
106
+ * Add: FAQ Instructions on how to implement support for `wp_body_open` to any theme
107
+ * Update: Links and wording on plugin settings page
108
+ * Update: Screenshots
109
+
110
= 1.0.9.1 =
111
* Fix: Fatal Error on Multisite WP's (thanks @kunzemarketing for reporting)
112
* Improve: DRI for front-end debugging
templates/settings.php CHANGED
@@ -33,17 +33,18 @@ if ( ! defined( 'WPINC' ) ) {
33
<div class="sidebar_container">
34
<a href="https://urosevic.net/wordpress/donate/?donate_for=head-footer-code" class="auhfc-button paypal_donate" target="_blank">Donate</a>
35
<br />
36
- <a href="https://wordpress.org/plugins/head-footer-code/faq/" class="auhfc-button" target="_blank">FAQ</a>
37
<br />
38
- <a href="https://wordpress.org/support/plugin/head-footer-code" class="auhfc-button" target="_blank">Community Support</a>
39
<br />
40
- <a href="https://wordpress.org/support/view/plugin-reviews/head-footer-code#postform" class="auhfc-button" target="_blank">Review this plugin</a>
41
</div><!-- .sidebar_container -->
42
</div><!-- .head_footer_code_wrapper -->
43
</div>
44
<script type="text/javascript">
45
jQuery(document).ready(function($) {
46
wp.codeEditor.initialize($('#auhfc_settings_head'), cm_settings);
47
wp.codeEditor.initialize($('#auhfc_settings_footer'), cm_settings);
48
});
49
</script>
33
<div class="sidebar_container">
34
<a href="https://urosevic.net/wordpress/donate/?donate_for=head-footer-code" class="auhfc-button paypal_donate" target="_blank">Donate</a>
35
<br />
36
+ <a href="https://wordpress.org/plugins/head-footer-code/#faq" class="auhfc-button" target="_blank">FAQ</a>
37
<br />
38
+ <a href="https://wordpress.org/support/plugin/head-footer-code/" class="auhfc-button" target="_blank">Community Support</a>
39
<br />
40
+ <a href="https://wordpress.org/support/plugin/head-footer-code/reviews/#new-post" class="auhfc-button" target="_blank">Review this plugin</a>
41
</div><!-- .sidebar_container -->
42
</div><!-- .head_footer_code_wrapper -->
43
</div>
44
<script type="text/javascript">
45
jQuery(document).ready(function($) {
46
wp.codeEditor.initialize($('#auhfc_settings_head'), cm_settings);
47
+ wp.codeEditor.initialize($('#auhfc_settings_body'), cm_settings);
48
wp.codeEditor.initialize($('#auhfc_settings_footer'), cm_settings);
49
});
50
</script>