• Resolved brucemacg

    (@brucemacg)


    I would like to use your plugin if possible to add code to my header.php. I’ve searched around but cannot get this to work. I’m using Storefront theme, and I do have a child theme.

    I add this code at the very end of my functions.php to show rankmath breadcrumbs on my site (but not on the front page)

    if (function_exists(‘rank_math_the_breadcrumbs’) && !is_front_page()) rank_math_the_breadcrumbs(); ?>

    I tried this code on Snippets.

    add_action( ‘wp_head’, function () { ?>

    if (function_exists(‘rank_math_the_breadcrumbs’) && !is_front_page()) rank_math_the_breadcrumbs(); ?>

    <?php } );

    This doesn’t work…

    I’d like to add the Google GTM tag to header.php.

    Currently I have added this piece of code straight after the <body> in header.php

    <?php if ( function_exists( ‘gtm4wp_the_gtm_tag’ ) ) { gtm4wp_the_gtm_tag(); } ?>

    I haven’t tried to add this yet, as I’m unsure how to test to ensure that it works…

    Can I use your plugin to add these 2 pieces or code, or do I need another. (or just to add the code as it is, in header.php. It works there..??

    Regards, Bruce

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Looks like you have some malformed PHP code in that breadcrumb function. Try this instead:

    add_action( 'after_setup_theme', function () {
    
    	if ( function_exists( 'rank_math_the_breadcrumbs' ) && ! is_front_page() ) {
    		rank_math_the_breadcrumbs();
    	}
    } );

    You should be able to add the Google GTM tag with wp_body_open, as long as your theme supports it:

    add_action( 'wp_body_open', function () {
    
    	if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) {
    		gtm4wp_the_gtm_tag();
    	}
    } );
Viewing 1 replies (of 1 total)

The topic ‘adding code to header.php’ is closed to new replies.