Adding a after_body Action to WordPress


So there are times that you would like to be able to add code directly after the body tag of a site.  WordPress unfortunately does not have this capability built into it.  So by modifying the the header.php file of your child theme you can easily give you the ability to add a code directly in that spot.

  //add this directly after the body tag in all header files

Then either in your plugin or within your functions file you can do the following.

//in this instance I am using it to output the noscript version of Google's Tag Manager
function output_custom() {
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src=""
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->



Posted on

May 17, 2018

Submit a Comment

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