• Resolved carissawp

    (@carissawp)


    Hi,

    In order to use a certain ad service, install a “comscore beacon” which involves adding some code to the footer of all pages of my blog. I am using a child theme for Customizr.

    Right now I don’t have a footer template in my child theme. Do I need to add one there? Once I do… is it safe to simply paste in the code or do I have to open/close the file a certain way?

    The instructions from my ad service specify to add my code before the </body> tag, but I don’t have a tag like that since I don’t even have a footer file in my child theme at all.

    Could anyone explain to me how to go about adding this?

Viewing 10 replies - 1 through 10 (of 10 total)
  • I think you don’t have a footer file because your child theme didn’t need to change the footer already available in the parent: only your customizations go into the child theme, everything else that you want the same as the parent doesn’t need to be duplicated in the child. If you want some special ad code in the footer, which is not in the parent, you need to create a footer.php file. The best way to go about it is to locate footer.php in the parent theme, copy and paste all of its contents in a new file, name it the same (footer.php), and place this file in the child theme. Now, copy and paste the ad code before the closing body tag </body> as required (now you should see this tag).

    You don’t need that file for this.
    Just use a customizr hook in your child theme functions.php.
    What kind of “code” we’re talking about?
    You can do something like this:

    add_action('__after_footer', 'my_after_footer');
    function my_after_footer(){
    //php code here
    }

    Alternatively, if you really want, copy the file customizr/footer.php in your childtheme dir, so you will have childtheme/footer.php, then edit this file, you will see that </body> tag you’re looking for, put that code before that tag this way:

    <?php
    //code
    ?>

    edit:
    sorry Antonietta, didn’t see you already answered.

    Thread Starter carissawp

    (@carissawp)

    Ok, I went into my file manager and created a footer.php file in my child theme (and copy/pasted the contents of the parent file in there first.)

    First, I tried pasting the ad code in there right before the </body> tag exactly as they provided it to me. When I looked at my site, it didn’t look like anything had changed.

    So next, I tried inserting the code before the </body> but I added
    <?php
    as the first line, and
    ?>
    as the last line. (Is that what you were telling me to do, d4z_c0nf?) Anyway, when I did that and looked my site, the footer was gone altogether.I’m guessing it’s just a matter of me inserting it wrong?

    Also, fyi, the code I’m inserting starts with
    <script>
    and ends with
    <no/script>

    Ok so it’s not php. Then before </body> just past that script
    you’ll have, this (I paste just the relevant part):

    do_action( '__after_footer' );
    ?>
            <script>
                 SOMETHING
            </script>
            <noscript>
                 SOMETHING
            </noscript>
        </body>
    <?php do_action( '__after_body' );  ?>
    </html>

    right?
    edit: missed the noscript part

    Thread Starter carissawp

    (@carissawp)

    Ok, I think that’s what I tried the first time. I just tried it again and I can see my footer, but there is no Comscore Beacon installed in it. I’m assuming I’m supposed to see some sort of logo or something in my footer now that that code is inserted, but there is no change.

    Your code seems to be javascript code, therefore from what I gather you don’t have to add php tags at all. You could copy and paste it as it is before the closing body tag in the footer.php file in the child theme.

    So you did right the first time.
    It’s not weird that you can’t see anything visible in your footer.
    If you look at the source of your page, you can see this at the bottom:

    <script>
      var _comscore = _comscore || [];
      _comscore.push({ c1: "2", c2: "6035233" });
      (function() {
        var s = document.createElement("script"), el = document.getElementsByTagName("script")[0]; s.async = true;
        s.src = (document.location.protocol == "https:" ? "https://sb" : "https://b") + ".scorecardresearch.com/beacon.js";
        el.parentNode.insertBefore(s, el);
      })();
    </script>
    <noscript>
      <img src="https://b.scorecardresearch.com/p?c1=2&c2=6035233&cv=2.0&cj=1" />
    </noscript>

    Which is what you pasted in your footer right?
    Then don’t worry, it works.

    Thread Starter carissawp

    (@carissawp)

    I’ve done that, but it doesn’t result in any change to my footer. It looks just as it did before I inserted any code at all. I would think it would cause some sort of logo to show up down there, wouldn’t it?

    Thread Starter carissawp

    (@carissawp)

    Oh ok! So the ad service should be able to detect it then.

    Thank you so much to you both!

    @carissawp, read my comment above.
    The only image you could see is this:
    <img src=”https://b.scorecardresearch.com/p?c1=2&c2=6035233&cv=2.0&cj=1&#8243; />

    which seems to be a 1px x 1px blank image.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Adding code to footer of all pages on my child theme’ is closed to new replies.