• Resolved ctuxboy

    (@ctuxboy)


    Hello,

    I trying adding Javascript in the footer.

    I’m adding this code in my functions.php:

    function locatie_winkel($pid){
       if (is_single()) {
           global $post;
           if($post->ID=="624"){ // only for post Id = 624
                echo "<script>alert('hello world');</script>";
           }
       }
    }
    add_action( 'wp_footer', 'locatie_winkel' );

    And this is the id of the page:
    ../wp-admin/post.php?post=624&action=edit

    But when i look in the frontend to this page, then i don’t see the script in the source code.

    What doing wrong??

    Regards,
    Christophe

Viewing 6 replies - 1 through 6 (of 6 total)
  • Topher

    (@topher1kenobe)

    Hi Christophe, I tried your code exactly as it is, and it worked for me. Check for caching to make sure you’re getting the freshest version of your page.

    Thread Starter ctuxboy

    (@ctuxboy)

    Hi Topher,

    Thanks for your answer, but i have no caching plugin :-/
    You mean that the code is correct.

    Christophe

    Topher

    (@topher1kenobe)

    Yep, the code is correct. Can I see the url for post number 624?

    Thread Starter ctuxboy

    (@ctuxboy)

    Hi Topher,

    I find it

    The id 624 is correct.

    I remove this line:

    if (is_single()) {

    and of course the curly bracket at the end.

    Now it works 🙂

    Thank you for testing the code.

    Regards,
    Christophe

    Topher

    (@topher1kenobe)

    That makes lots of sense, the docs for is_single say:

    Works for any post type, except attachments and pages

    If you were looking at a page you should use is_page()

    Thread Starter ctuxboy

    (@ctuxboy)

    Topher,

    Thanks for the useful info.
    Indeed, now it works well.

    Good to know 🙂

    Regards,
    Christophe

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘JavaScript snippet in footer specific page’ is closed to new replies.