Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the rocket domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/teamikci/subdomain/apsaraaruna.dev/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/teamikci/subdomain/apsaraaruna.dev/wp-includes/functions.php on line 6114
Add html code after body tag in Wordpress using functions.php - Apsara Aruna
  • 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: