go to header.php and you will find <head> & <body> tag
Hi @momadvisorblog,
Unfortunately, there isn’t a standard way in WordPress for adding code just after the <body>
tag. The means for doing so really depends on what theme you are using. Some themes will provide a filter that you can hook to similar to wp_head
; for others you will need to add a line of code yourself.
But @sanwal is correct that to find out, you should take a look at your theme’s header.php file.
Thank you!
This is what I found in the header.php file.
<!DOCTYPE html>
<html <?php language_attributes(); ?> class=”no-js”>
<head>
<meta charset=”<?php bloginfo( ‘charset’ ); ?>”>
<meta name=”viewport” content=”width=device-width”>
<link rel=”profile” href=”http://gmpg.org/xfn/11″>
<link rel=”pingback” href=”<?php bloginfo( ‘pingback_url’ ); ?>”>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div id=”ds-container” >
<?php do_action(‘dt_before_header’); ?>
<?php
$enable_header_top = esc_attr(get_theme_mod(‘dt_enable_header_top’, DT_ENABLE_HEADER_TOP));
if ($enable_header_top == ‘1’) {
$extra_class = ‘dt-header-top-enabled’;
} else {
$extra_class = ”;
}
?>
I added this but there´s an error:
add_action( ‘body_class’, function () { ?>
<!– Google Tag Manager (noscript) –> etc
I think it´s adding it before instead of after the <body> tag.
And now I´m getting this line:
class=”home-page bp-legacy geodir_advance_search geodir_custom_posts geodir-page sd-common sd sd-homepage wpb-js-composer js-comp-ver-5.1 vc_responsive elementor-default no-js gd-map-auto”>
Help please 🙂
Hi @momadvisorblog,
You shouldn’t really be using the body_class
filter hook for this purpose.
Instead, I’d recommend using the dt_before_header
action:
add_action( 'dt_before_header', function () { ?>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<?php } );