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
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
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
Brilliant – thank you :)