Header Footer Code Manager Shortcode

Below, you’ll find a detailed guide on how to add the Header Footer Code Manager Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Header Footer Code Manager Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Header Footer Code Manager Plugin and the shortcodes it provides:

Plugin Icon
Header Footer Code Manager

"Header Footer Code Manager is a WordPress plugin that enables precise control over where and when codes are placed on your site. Perfect for managing scripts and styles!"

★★★★☆ (263) Active Installs: 500000+ Tested with: 6.3.2 PHP Version: 5.6.20
Included Shortcodes:
  • [hfcm]

Header Footer Code Manager [hfcm] Shortcode

The ‘hfcm’ shortcode from the Header-Footer-Code-Manager plugin is designed to retrieve and display specific scripts. It uses the ‘id’ attribute to identify the desired script from the database. The function checks the device type and excludes scripts not suitable for the current device. If the script is active and valid for the device, it’s rendered on the page.

Shortcode: [hfcm]

Parameters

Here is a list of all possible hfcm shortcode parameters and attributes:

  • id – The unique identifier of the specific script to be displayed

Examples and Usage

Basic example – A simple usage of the hfcm shortcode to display a script with a specific ID on your WordPress site.

[hfcm id=1 /]

Advanced examples

Using the hfcm shortcode to display a script with a specific ID, and also specify the device type. This example will display the script only on desktop devices. If the specified ID is not found, the shortcode will not render anything.

[hfcm id=1 device_type='desktop' /]

Another advanced usage of the hfcm shortcode, this time to display a script with a specific ID, but only on mobile devices. If the specified ID is not found, the shortcode will not render anything.

[hfcm id=1 device_type='mobile' /]

Please note that the ‘device_type’ parameter is not explicitly supported by the hfcm shortcode function, but it’s used here for illustrative purposes. In real usage, you would need to modify the hfcm_shortcode function to support this parameter.

PHP Function Code

In case you have difficulties debugging what causing issues with [hfcm] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'hfcm', array( 'NNR_HFCM', 'hfcm_shortcode' ) );

Shortcode PHP function:

function hfcm_shortcode( $atts )
        {
            global $wpdb;
            $table_name = $wpdb->prefix . self::$nnr_hfcm_table;
            if ( !empty( $atts['id'] ) ) {
                $id          = absint( $atts['id'] );
                $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
                $script      = $wpdb->get_results(
                    $wpdb->prepare(
                        "SELECT * FROM `{$table_name}` WHERE status='active' AND device_type!=%s AND script_id=%d",
                        $hide_device,
                        $id
                    )
                );
                if ( !empty( $script ) ) {
                    return self::hfcm_render_snippet( $script[0] );
                }
            }
        }

Code file location:

header-footer-code-manager/header-footer-code-manager/99robots-header-footer-code-manager.php

Conclusion

Now that you’ve learned how to embed the Header Footer Code Manager Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *