Tagged: ,

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #433852

    Hi there,
    I have an external script that I need to load on two pages only. I know I can put scripts in a code block, but I actually need the script to load last – in the footer.
    This script is only required on 2x pages, so what is the best way to do this?
    In functions.php?
    I’d rather not have to create a page template for these two pages, that’s probably not the most elegant solution.
    The 2x page id’s are 5257 & 4913, can you help point me in the right direction please?
    Thanks,
    Jason

    #434419

    Hey Jason!

    Please add following code to Functions.php file in Appearance > Editor

    function add_custom_code(){
    if(is_page(array(5257,4913)))
    {
    ?>
    <script type="text/javascript" src="https://apsr.autoplay.co.nz/Content/js/loader.search.min.js"></script>
    <script type="text/javascript">
    // APSR configuration.
    config.ID = "166";
    config.Yard = "217";
    config.Options = "&makesort=52";
    config.Profile = "used";
    config.DetailUrl = "detail";
    </script>
    <?php
    }
    }
    add_action('wp_footer', 'add_custom_code');

    Best regards,
    Yigit

    #435704
    This reply has been marked as private.
    #435936

    Hey!

    Please try this:

    function add_custom_code_1(){
    if(is_page (5257)) {
    ?>
    YOUR SCRIPT GOES HERE
    <?php
    }
    }
    add_action('wp_footer', 'add_custom_code_1');
    
    function add_custom_code_2(){
    if(is_page (4913)) {
    ?>
    YOUR SCRIPT GOES HERE
    <?php
    }
    }
    add_action('wp_footer', 'add_custom_code_2');
    

    Cheers!
    Rikard

    • This reply was modified 9 years, 8 months ago by Rikard.
    #436477

    Brilliant – thank you :)

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Best way to add external script to 2x pages (only)’ is closed to new replies.