Head & Footer Code - Version 1.2.3

Version Description

(2021-07-19) = * Tested: on WordPress 5.8-RC4 and PHP 8.0.8 * (2021-05-04) Fix: Notice errors Trying to get property 'post_type' of non-object in inc/front.php (thanks to @tekgirlymama) * Improve: DRY for getting post type.

Download this release

Release Info

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

Code changes from version 1.2.2 to 1.2.3

Files changed (4) hide show
  1. head-footer-code.php +2 -2
  2. inc/front.php +3 -18
  3. inc/helpers.php +13 -0
  4. readme.txt +12 -4
head-footer-code.php CHANGED
@@ -8,7 +8,7 @@
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.2.2
12
  * Author: Aleksandar Urosevic
13
  * Author URI: https://urosevic.net/
14
  * License: GPLv3
@@ -21,7 +21,7 @@ if ( ! defined( 'WPINC' ) ) {
21
  die;
22
  }
23
 
24
- define( 'WPAU_HEAD_FOOTER_CODE_VER', '1.2.2' );
25
  define( 'WPAU_HEAD_FOOTER_CODE_DB_VER', '6' );
26
  define( 'WPAU_HEAD_FOOTER_CODE_FILE', __FILE__ );
27
  define( 'WPAU_HEAD_FOOTER_CODE_DIR', dirname( WPAU_HEAD_FOOTER_CODE_FILE ) . '/');
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.2.3
12
  * Author: Aleksandar Urosevic
13
  * Author URI: https://urosevic.net/
14
  * License: GPLv3
21
  die;
22
  }
23
 
24
+ define( 'WPAU_HEAD_FOOTER_CODE_VER', '1.2.3' );
25
  define( 'WPAU_HEAD_FOOTER_CODE_DB_VER', '6' );
26
  define( 'WPAU_HEAD_FOOTER_CODE_FILE', __FILE__ );
27
  define( 'WPAU_HEAD_FOOTER_CODE_DIR', dirname( WPAU_HEAD_FOOTER_CODE_FILE ) . '/');
inc/front.php CHANGED
@@ -29,12 +29,7 @@ add_action( 'wp_footer', 'auhfc_wp_footer', $auhfc_settings['sitewide']['priorit
29
  function auhfc_wp_head() {
30
 
31
  // Get post type.
32
- if ( is_singular() ) {
33
- global $wp_the_query;
34
- $auhfc_post_type = $wp_the_query->get_queried_object()->post_type;
35
- } else {
36
- $auhfc_post_type = 'not singular';
37
- }
38
 
39
  // Get variables to test.
40
  $auhfc_settings = auhfc_settings();
@@ -94,12 +89,7 @@ function auhfc_wp_head() {
94
  function auhfc_wp_body() {
95
 
96
  // Get post type.
97
- if ( is_singular() ) {
98
- global $wp_the_query;
99
- $auhfc_post_type = $wp_the_query->get_queried_object()->post_type;
100
- } else {
101
- $auhfc_post_type = 'not singular';
102
- }
103
 
104
  // Get variables to test.
105
  $auhfc_settings = auhfc_settings();
@@ -159,12 +149,7 @@ function auhfc_wp_body() {
159
  function auhfc_wp_footer() {
160
 
161
  // Get post type.
162
- if ( is_singular() ) {
163
- global $wp_the_query;
164
- $auhfc_post_type = $wp_the_query->get_queried_object()->post_type;
165
- } else {
166
- $auhfc_post_type = 'not singular';
167
- }
168
 
169
  // Get variables to test.
170
  $auhfc_settings = auhfc_settings();
29
  function auhfc_wp_head() {
30
 
31
  // Get post type.
32
+ $auhfc_post_type = auhfc_get_post_type();
 
 
 
 
 
33
 
34
  // Get variables to test.
35
  $auhfc_settings = auhfc_settings();
89
  function auhfc_wp_body() {
90
 
91
  // Get post type.
92
+ $auhfc_post_type = auhfc_get_post_type();
 
 
 
 
 
93
 
94
  // Get variables to test.
95
  $auhfc_settings = auhfc_settings();
149
  function auhfc_wp_footer() {
150
 
151
  // Get post type.
152
+ $auhfc_post_type = auhfc_get_post_type();
 
 
 
 
 
153
 
154
  // Get variables to test.
155
  $auhfc_settings = auhfc_settings();
inc/helpers.php CHANGED
@@ -228,6 +228,19 @@ function auhfc_out( $scope = null, $location = null, $message = null, $code = nu
228
  );
229
  } // END function auhfc_out( $scope = null, $location = null, $message = null, $code = null )
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  function auhfc_is_homepage_blog_posts() {
232
  if ( is_home() && 'posts' == get_option( 'show_on_front', false ) ) {
233
  return true;
228
  );
229
  } // END function auhfc_out( $scope = null, $location = null, $message = null, $code = null )
230
 
231
+ function auhfc_get_post_type() {
232
+ $auhfc_post_type = 'not singular';
233
+ // Get post type.
234
+ if ( is_singular() ) {
235
+ global $wp_the_query;
236
+ $auhfc_query = $wp_the_query->get_queried_object();
237
+ if (is_object($auhfc_query)) {
238
+ $auhfc_post_type = $auhfc_query->post_type;
239
+ }
240
+ }
241
+ return $auhfc_post_type;
242
+ } // END function auhfc_get_post_type()
243
+
244
  function auhfc_is_homepage_blog_posts() {
245
  if ( is_home() && 'posts' == get_option( 'show_on_front', false ) ) {
246
  return true;
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: urkekg, techwebux
3
  Donate link: https://urosevic.net/wordpress/donate/?donate_for=head-footer-code
4
  Tags: head, header, footer, body, scripts, wp_head, wp_footer, wp_body_open, head footer code, custom script
5
  Requires at least: 4.9
6
- Tested up to: 5.7
7
- Stable tag: 1.2.2
8
  Requires PHP: 5.6
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -62,6 +62,7 @@ If you find **Head &amp; Footer Code** useful for your project, please [review p
62
  * Site-wide section located under **Tools** > **Head & Footer Code**
63
  * 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.
64
  * Multisite is supported.
 
65
 
66
  General settings (HEAD, BODY, FOOTER global code and priority, Homepage code and behaviour) saves in WordPress option `auhfc_settings`.
67
  Each post/page/custom post type specific HEAD, BODY and FOOTER code and behaviour saves to post meta `_auhfc`.
@@ -103,9 +104,11 @@ This feature is implemented since WordPress version 5.2 and requires theme compa
103
 
104
  To make sure if theme you use supports [wp_body_open](https://developer.wordpress.org/reference/hooks/wp_body_open/) hook, 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):
105
 
106
- ```if ( function_exists( 'wp_body_open' ) ) {
 
107
  wp_body_open();
108
- }```
 
109
 
110
  == Screenshots ==
111
 
@@ -123,6 +126,11 @@ To make sure if theme you use supports [wp_body_open](https://developer.wordpres
123
  Initial release of new plugin developed by Aleksandar Urosevic.
124
 
125
  == Changelog ==
 
 
 
 
 
126
  = 1.2.2 (2021-04-24) =
127
  * Tested: on WordPress 5.7.1
128
  * (2021-02-01) Fix: Noice errors in update script (thanks to @swinggraphics)
3
  Donate link: https://urosevic.net/wordpress/donate/?donate_for=head-footer-code
4
  Tags: head, header, footer, body, scripts, wp_head, wp_footer, wp_body_open, head footer code, custom script
5
  Requires at least: 4.9
6
+ Tested up to: 5.8
7
+ Stable tag: 1.2.3
8
  Requires PHP: 5.6
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
62
  * Site-wide section located under **Tools** > **Head & Footer Code**
63
  * 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.
64
  * Multisite is supported.
65
+ * PHP 8 ready!
66
 
67
  General settings (HEAD, BODY, FOOTER global code and priority, Homepage code and behaviour) saves in WordPress option `auhfc_settings`.
68
  Each post/page/custom post type specific HEAD, BODY and FOOTER code and behaviour saves to post meta `_auhfc`.
104
 
105
  To make sure if theme you use supports [wp_body_open](https://developer.wordpress.org/reference/hooks/wp_body_open/) hook, 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):
106
 
107
+ ```
108
+ if ( function_exists( 'wp_body_open' ) ) {
109
  wp_body_open();
110
+ }
111
+ ```
112
 
113
  == Screenshots ==
114
 
126
  Initial release of new plugin developed by Aleksandar Urosevic.
127
 
128
  == Changelog ==
129
+ = 1.2.3 (2021-07-19) =
130
+ * Tested: on WordPress 5.8-RC4 and PHP 8.0.8
131
+ * (2021-05-04) Fix: Notice errors Trying to get property 'post_type' of non-object in inc/front.php (thanks to @tekgirlymama)
132
+ * Improve: DRY for getting post type.
133
+
134
  = 1.2.2 (2021-04-24) =
135
  * Tested: on WordPress 5.7.1
136
  * (2021-02-01) Fix: Noice errors in update script (thanks to @swinggraphics)