• Dec 28, 2022

Add html code after body tag in WordPress using functions.php

To add HTML code after the <body> tag in WordPress using the functions.php file, you can use the wp_body_open action hook. This hook is triggered after the <body> tag is opened in the document, and it allows you to insert any content you want at this point in the page.

Here’s an example of how you can use the wp_body_open action hook to add HTML code after the <body> tag:

function my_custom_code() {
  echo '<div>My custom HTML code goes here</div>';
add_action( 'wp_body_open', 'my_custom_code' );

In this example, the my_custom_code() function contains the HTML code that you want to insert. This function is then attached to the wp_body_open action hook using the add_action() function. When the hook is triggered, the HTML code in the my_custom_code() function will be inserted into the page.

Keep in mind that you will need to add this code to your theme’s functions.php file or a custom plugin in order for it to work.

Share on: