• Resolved Bobbutterfly

    (@bobbutterfly)


    Hello everyone!

    My problem’s pretty simple. I’m currently trying to add Quantcast to my website but I’m asked to put a html code in all my pages.

    So, is there any way to add this code in one time rather than in one page at a time?

    Thank you in advance!

Viewing 6 replies - 1 through 6 (of 6 total)
  • There certainly is. I am not familiar with Quantcast but it depends on where you would like the code to load in your markup. For example, if you wanted the code to stay within <head></head> you could echo it out in the wp_head hook via functions.php or a standalone plugin like so:

    function quantcast_code(){
    echo 'your code snippet can go here';
    }
    add_action( 'wp_head', 'quantcast_code' );

    If you are using a child theme, you could also just drop the Quantcast code in your header.php.

    Thread Starter Bobbutterfly

    (@bobbutterfly)

    Firstly, thank you for your quick answer!

    I took Quantcast as a example but in fact my question is general to all things where we need to put code to a page ^^ (such as Google Analytics without plugin)
    What I understood of your words is that I need to place the code in a specific fil, right?

    It said on Quantcast site that I need to put the code “before the </body> tag and any other measurement tags”

    In this case what should I write in my functions.php precisely?

    You can use the code above but switch out the hook wp_head with wp_footer

    Thread Starter Bobbutterfly

    (@bobbutterfly)

    Well, okay!

    What’s the difference anyway? And will it put my code in all pages?

    The wp_head hook will echo it out near </head> and wp_footer hook will echo it out near </body>.

    Assuming your theme properly calls wp_head and wp_footer, then yes, it should add whatever you put in that echo to all of your pages. You could use conditionals to narrow it down further, for example, if you only wanted to add the code to your contact page, you could do something like this:

    function quantcast_code(){
        if ( is_page( 'Contact' ) ) {
            echo 'your code snippet can go here';
        }
    }
    add_action( 'wp_head', 'quantcast_code' );
    Thread Starter Bobbutterfly

    (@bobbutterfly)

    Oh, hell!

    I forgot to thank you Craig Ralston. Shame on me.

    I’m okay now with header and footer code, thank you a lot for your help! ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to add html code in all pages in a row’ is closed to new replies.