Community Forums › Forums › Archived Forums › General Discussion › Adding a script to homepage in Essence Pro
Tagged: Essence Pro
- This topic has 7 replies, 2 voices, and was last updated 6 years, 3 months ago by
citilife.
-
AuthorPosts
-
November 27, 2018 at 6:40 am #224622
citilife
MemberI have just moved my site to the Essence Pro theme and I am using LatestPosts/widgets option to create the front page with Essence widgets. The issue I have is that previously the front page was a static page and I was able to very simply add a script to just the front page of the site using header scripts for that particular page.
I am not certain how to do that when the front page is not a page/post, but created using widgets as I have done in Essence pro.
How do I add a script, not globally in the Genesis settings, but specifically just to show on the front page of the website.
The website is pureread.com
November 27, 2018 at 6:52 am #224623Victor Font
ModeratorYou can add (wp_enqueue) the script in the theme's front-page.php.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?November 27, 2018 at 9:16 am #224627citilife
Memberhi Victor, thanks for that. Not being a techie the idea is a bit foreign to me. is there a simple way to accomplish this, or dummies instructions I can follow somewhere?
I dont suppose anyone knows a plugin that might do the lifting for me?
November 27, 2018 at 11:46 am #224629Victor Font
ModeratorEven with a plugin, you'd have to write code.
In the front-page.php file for Essence Pro, the front page scripts are loaded at line 29. Line 29 calls a function found at line 78. This is where you add your script. Assuming the script is jQuery, you would do the following:
- Save the script to a file. Name it whatever you want but make sure it has a .js extension. Make sure the file is in the theme's js directory
- If the script is wrapped in the script tags, remove the script tags.
- Add the following to the function at line 78:
wp_enqueue_script( 'my-front-script', get_stylesheet_directory_uri() . '/js/my-front-script.js', array( 'jquery' ), CHILD_THEME_VERSION, true );
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?November 27, 2018 at 11:54 am #224630citilife
Memberthank you so much!
November 27, 2018 at 11:57 am #224632citilife
MemberSo if my script is
<script type="text/javascript" src="https://quriobot.com/qb/widget/Owj0M8mVYLbRW4qY/vK8WdbwW4PbJlzN5" async defer></script>
what would I paste into a text doc and save (you mention removing script tags)
sorry for being so slow.....
November 27, 2018 at 12:14 pm #224634Victor Font
ModeratorThat script won't work with wp_enqueue_script. You'll have to go about this in a completely different way. This snippet will do it for you if you add it to the bottom of functions.php:
add_action( 'wp_head', 'add_front_page_script' ); function add_front_page_script() { if( is_home() || is_front_page() ) { echo '<script type="text/javascript" src="https://quriobot.com/qb/widget/Owj0M8mVYLbRW4qY/vK8WdbwW4PbJlzN5" async defer></script>' . PHP_EOL; } }
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?November 27, 2018 at 12:32 pm #224635citilife
MemberVictor, I hope you know how amazing you are!
-
AuthorPosts
- The topic ‘Adding a script to homepage in Essence Pro’ is closed to new replies.