How to hook directly after the body tag in PHP?

How to hook directly after the body tag in PHP?

So basically in your theme, you would go where you want to, right after the tag, and do something like: You can also pass arguments to the action callback, see the linked documentation for information. Then afterwards, you would simply use the add_action function to hook onto it. Hope that helps.

Can you add code to the body tag in WordPress?

But one hook that’s been lacking so far in WordPress, is the ability to add code just after the tag. This is particularly needed when using a tool like the Google Tag Manager. In the absence of this hook, developers have needed to use all kinds of workarounds.

How to add a hook to a function in PHP?

Now hook is ready to use, simply add any actions you need in functions.php: or JavaScript (tracking code etc – this is not the perfect way though, it is a better practice to load JavaScript from .js files, but it is definitely better than adding JavaScript directly to template files): function my_function () { ?>

How do I add code to my footer?

To add code to your site’s footer, you can scroll down to the BEFORE THE CLOSING TAG (FOOTER) option. Again, you have two options, though they’re different from the header section: Desktop – despite the name, this adds code to the footer of both the desktop and mobile version of your site unless you specifically check the box for Mobile.

How to hook or inject into HTML body?

You can now hook or inject into HTML body by doing: Putting this in your functions.php file in your theme might be best for most basic users. Thanks for contributing an answer to Stack Overflow!

Where do I find action hooks in WordPress?

On the front page with both of these debug plugins active, while logged in, your admin bar will have a “Debug” option. Click there and a new screen appears. Here in this new screen, you can click either “Action Hooks” or “Filter Hooks” to see what’s happened in the background of the front page. Then magic should happen.

Do you append custom content before or after the title?

Basically, you append the post content after your custom content, then return the result. Note that, in this case, you append your custom content after the Title. (It doesn’t matter which; I just went with what you specified in your question.)