• Resolved tamirg

    (@tamirg)


    Hey,
    I want to add a script to the body of the site, but i dont see that option.
    I can add only to the head or the footer.
    I need to add the google tag manager and it asking me to add one script on the head of the site and one on the body…
    This plugin dont support it?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support 99robotsteam

    (@99robotsteam)

    Hello @tamirg – Unfortunately currently the plugin does not allow code to be added to the body of the site, as there is no hook in WordPress for that yet. We are looking into other methods to help users add code directly to the body tag (especially for the purpose of the Google Tag Manager Snippet) of the site.

    The plugin allows you to add code in the Header, Footer, Before the content (of a post / page) and After the content (of a post/page).

    Hope this helps,

    Hi!

    There is a way around this “no hook issue”, though it needs a tiny bit of theme editing (and plugin for the time being).

    1. First, edit you child theme header.php by finding the <body openning. This will show the plugin where to put the code.

    
    <body <?php body_class(); ?>>
    <?php do_action('hfcm_after_body_tag'); ?>
    
    

    2. Now, edit the plugin’s main file — 99robots-header-footer-code-manager.php by adding the following code past line 387

    
    // Function to add snippets after BODY tag
    function hfcm_body_scripts() {
      hfcm_add_snippets( 'body' );
    }
    add_action( 'hfcm_after_body_tag', 'hfcm_body_scripts' );
    
    

    3. Next enable the option in plugin panel by editing includes/hfcm-add-edit.php at line 250

    
    250: $larray = array( 'header' => 'Header', 'body' => 'After BODY openning tag', 'before_content' => 'Before Content', 'after_content' => 'After Content', 'footer' => 'Footer' );
    
    

    and line 252

    
    252: $larray = array( 'header' => 'Header', 'body' => 'After BODY opening tag', 'footer' => 'Footer' );
    
    

    4. And finally in includes/hfcm-list.php add the following after line 173 so you can see the location in the list view.

    
    'body' => esc_html__( 'After BODY openning tag', '99robots-header-footer-code-manager' ),
    
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add a script to the body of a page’ is closed to new replies.