Back to Community

How to Handle Scripts That Require Placement in the Body Tag with Header Footer Code Manager

24 threads Sep 16, 2025 PluginHeader footer code manager

Content

A common challenge for users of the Header Footer Code Manager (HFCM) plugin is the need to insert scripts, like those for Google Tag Manager (GTM) or specific tracking codes, directly after the opening <body> tag. Many third-party services provide explicit instructions for this placement to ensure their scripts function correctly. This article explains why this can be difficult with the standard plugin and outlines the most common workarounds and solutions.

Why Can't I Insert Code Directly After the <body> Tag?

The core limitation stems from how WordPress functions. The HFCM plugin relies on specific WordPress hooks to inject code. The standard free version primarily uses the wp_head hook for the header and the wp_footer hook for the footer.

Historically, WordPress has not provided a standardized, reliable hook for the space immediately after the opening <body> tag that works across all themes and page types. As noted in several support threads, the 'Header Footer Code Manager' team has acknowledged this is a highly requested feature but has been hesitant to implement a solution that might not work universally or could break on many sites.

Common Solutions and Workarounds

Based on community discussions, here are the most frequently suggested approaches:

1. Use the "Before Content" Option (For Specific Pages/Posts)

The HFCM plugin does offer "Before Content" and "After Content" location options, but these are typically only available when you select a specific page, post, or category—not for a sitewide insertion. This is because these options depend on the the_content hook, which is only present on singular post and page views in most themes. It will not work on archive, category, or homepage templates.

How to use it: When creating a new snippet, set the Display On option to a specific page or post. The Location dropdown should then update to include "Before Content." Be aware that this places the code at the top of the post/page content area, which is not the same as immediately after the <body> tag but is often the closest available option in the free version.

2. Consider a Theme Widget or Alternative Plugin

If your goal is to place an visual element like an ad banner below the header but within the body, your theme might offer a solution. Many themes have widget areas (like "Below Header" or "Above Content") that you can use. You can often add a Custom HTML widget to this area and paste your code there.

For code that must be right after the <body> tag, you may need a different plugin specifically designed for that purpose. Some users on the forums reported using a second plugin alongside HFCM to handle this specific placement.

3. Check for a Pro Version Feature

Some user threads indicate that a "Pro" version of the plugin may exist which includes a "Body Open" or similar insertion feature. If this functionality is critical for your site, you may want to investigate whether the official 'Header Footer Code Manager' team offers a premium version that includes this capability. The sample threads suggest this feature might be implemented there to handle the technical challenges more robustly.

Important Note on Google Tag Manager (GTM)

GTM requires two code snippets: one for the <head> and one for the <body>. You can successfully insert the <head> portion using HFCM's Header location. For the <body> portion, you will need to employ one of the workarounds listed above. Some users have reported placing the second snippet in the footer as a temporary measure, though this is not ideal and goes against Google's instructions.

Conclusion

The inability to insert code sitewide directly after the <body> tag is a known constraint of the free Header Footer Code Manager plugin, rooted in WordPress's architecture. The most practical solutions involve using the "Before Content" option for specific pages, leveraging theme features, or exploring a premium version of the plugin if one is available. Always test any code placement thoroughly to ensure it works as expected across your entire site.

Related Support Threads Support