Hello - how do I add a custom script to the blog page?
This is the script that I would like to appear on my blog page only:
Summary
Thanks for your help!
Hello - how do I add a custom script to the blog page?
This is the script that I would like to appear on my blog page only:
Thanks for your help!
Hello @ccwadsworth,
Thanks for asking.
You can take a look at SOGO Add Script to Individual Pages Header Footer plugin to add script specific page like blog. Please use following URL to download the plugin.
Thanks.
Thanks for your response and the link.
I was hoping to do this without adding another pluginâŚ
Is that possible?
Appreciate your help, thank you!
Hi,
In that case, you may add it using wp-footer hook
Add the code below in your child themeâs functions.php
function add_my_script() {
?>
<script>
window.sugarwod_options = {
id: "dAtRc5gEz6",
color: "#f79646",
position: "bottom-right"
}
</script>
<script src="//cdn.sugarwod.com/plugin/v1/sugarwod-plugin.js" async></script>
<?php
}
add_action( 'wp_footer', 'add_my_script' );
Additional Info:
https://codex.wordpress.org/Plugin_API/Action_Reference/wp_footer
Hope this helps
Thank you! Will this show up on my blog page only?
Hi @ccwadsworth,
It will be displayed everywhere, you can change it to this to make sure itâs only displayed on blog page.
function add_my_script() {
if ( is_home() ) : ?>
<script>
window.sugarwod_options = {
id: "dAtRc5gEz6",
color: "#f79646",
position: "bottom-right"
}
</script>
<script src="//cdn.sugarwod.com/plugin/v1/sugarwod-plugin.js" async></script>
<?php endif;
}
add_action( 'wp_footer', 'add_my_script' );
Hope this helps.
Thanks Rad â but itâs not showing up on my blog page⌠should the if statement be âis_blogâ ?
It isnât showing up on my home page either, by the wayâŚ
Appreciate your help!
Thank you!
Hello @ccwadsworth,
The code should have work and display the code in your blog index.
is_home()
will return true/false if the page is your blog index. There isnât is_blog()
condition.
I have check all the site urls associated with your licenses. I am not sure I have looked into the correct url. To assist you with this issue, weâll first need you to provide us with your URL. This is to ensure that we can provide you with a tailored answer to your situation.
Please let us know how it goes.
Thanks RueNel
The site license is for cynergycrossfit.com, the page is https://www.cynergycrossfit.com/blog/
I have the script loaded on the contact page so you can see how it works: https://www.cynergycrossfit.com/contact/
An orange button appears in the lower right corner.
Thanks for your help!
Hello @ccwadsworth,
Thank you for providing the site information. As I have checked it, I found out that you have installed a caching plugin WP Super Cache. Always keep in mind that after making any site changes, you must clear your plugin cache before testing your site. This can cause the changes to not take place on the front end. It will eventually show up when the cache regenerates, but itâs not ideal if youâre looking to see your changes immediately. Caching plugins are best to turn on only when youâve finished building the site.
Hope this helps. Kindly let us know.
Hi RueNel
Thank you for your response. Yes, I am aware of the caching plugin and used it after I made the changes. I am still unable to see the script on the page.
I deleted cache again this morning and checked the page on 3 different browsers and still donât see the updates.
Thanks so much for your help, I appreciate it!
Hi @ccwadsworth,
Please activate your child theme first, the reason itâs not working is because itâs not active.
Thanks!
Rad, thank you for pointing that out. I have no idea why the child theme wasnât activated. I never used the main theme⌠the script is now working. I appreciate your help, thank you very much!
Glad itâs working now, cheers! And youâre most welcome!
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.