• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Adding a script to homepage in Essence Pro

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Adding a script to homepage in Essence Pro

This topic is: resolved

Tagged: Essence Pro

  • This topic has 7 replies, 2 voices, and was last updated 4 years, 2 months ago by citilife.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • November 27, 2018 at 6:40 am #224622
    citilife
    Member

    I 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 #224623
    Victor Font
    Moderator

    You 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 #224627
    citilife
    Member

    hi 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 #224629
    Victor Font
    Moderator

    Even 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:

    1. 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
    2. If the script is wrapped in the script tags, remove the script tags.
    3. 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 #224630
    citilife
    Member

    thank you so much!

    November 27, 2018 at 11:57 am #224632
    citilife
    Member

    So 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 #224634
    Victor Font
    Moderator

    That 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 #224635
    citilife
    Member

    Victor, I hope you know how amazing you are!

  • Author
    Posts
Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Adding a script to homepage in Essence Pro’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble