• 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

How to add inline javascript in a template

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 › How to add inline javascript in a template

This topic is: not resolved

Tagged: javascript, php

  • This topic has 4 replies, 2 voices, and was last updated 10 years, 6 months ago by Brad Dalton.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • January 16, 2016 at 12:13 pm #176698
    Toon61
    Member

    Hi all,

    I want to include a small javascript snippet in my template.
    How to 'echo' just generic HTML tags, I know how to do that:
    echo '<div class="something">';
    etc. etc.
    But now I want, in a similar fashion, include a small piece of javascript.
    I just don't know how to 'echo' this, or use another way to include this.
    At the moment I try to include a Caldera Form in my template that has a javascript snippet like this:

    
    	jQuery( function($){
    		$(document).on('click dblclick', '#fld_8704063_1', function( e ){
    			$('#fld_8704063_1_btn').val( e.type ).trigger('change');
    		});
    	});
    

    or this one:

    
    	jQuery(function($){
    
    		function init_rangeslider(){
    			var el = $('#fld_774416_1'),
    				rangeslider;
    						if (el.is(':visible')) {
    				if( !el.data( 'plugin_rangeslider' ) ){
    					rangeslider = el.rangeslider({
    						onSlide: function(position, value) {
    														$('#fld_774416_1_value').html(value);
    						},
    						polyfill: false					});
    					rangeslider.parent().find('.rangeslider').css('backgroundColor', rangeslider.data('trackcolor'));
    					rangeslider.parent().find('.rangeslider__fill').css('backgroundColor', rangeslider.data('color'));
    					rangeslider.parent().find('.rangeslider__handle').css('backgroundColor', rangeslider.data('handle')).css('borderColor', rangeslider.data('handleborder'));
    				}
    			}else{
    				el.rangeslider('destroy');
    			}
    					}
    				// setup tabs
    		$(document).on('cf.pagenav cf.add cf.disable', function(){
    			init_rangeslider();
    		});
    				// init slider
    		init_rangeslider();
    
    	});
    

    How can i 'echo' this one out to get it working, and no. I don't want to use a shortcode to include the form because I want to be able to adjust some parameters in the different input fields based on variables I use.

    Any help would be appreciated.

    January 16, 2016 at 12:24 pm #176701
    Brad Dalton
    Participant

    1. Wrap it in script tags like this:

     
    <script>
      $(function() {
    
    $(document).on('click dblclick', '#fld_8704063_1', function( e ){
    			$('#fld_8704063_1_btn').val( e.type ).trigger('change');
    		});
    
      });
      </script>

    2. And close the php before the script and open it again after.

    3. You'll also need to load jQuery

    add_action( 'wp_enqueue_scripts', 'child_add_scripts' );
    function child_add_scripts() {
        wp_enqueue_script( 'google-analytics' );
    }
    

    Tutorials for StudioPress Themes.

    January 16, 2016 at 12:31 pm #176702
    Brad Dalton
    Participant

    3. Should be

    add_action( 'wp_enqueue_scripts', 'load_jquery_wpsites' );
    function load_jquery_wpsites() {
        wp_enqueue_script( 'jquery' );
    }
    

    Tutorials for StudioPress Themes.

    January 17, 2016 at 11:28 am #176758
    Toon61
    Member

    Thanks Brad,

    I'll give it a try.

    January 17, 2016 at 11:33 am #176759
    Brad Dalton
    Participant

    I think i missed something!


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

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

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 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