Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #877007

    Todd K.
    Participant

    Greetings.

    My company is an insurance agency. We are an authorized agent for Progressive Insurance. Our site is http://www.kmkinsure.com, and is currently under construction.

    To use many of Progressive’s artwork on our site, I need to add separate scripts to exact target locations on my page. The .js artwork adds our company name to the graphic.

    I’m having one heck of a time trying to figure out how to add the following to my Progressive page:

    In the Head section: (for all artwork)

    <script language="javascript" type="text/javascript">function getDriveCode() {return '37794'}</script>
    <script language="javascript" type="text/javascript" src="http://www.progressiveagent.com/include/p_drive_banner_util.js"></script>

    In the Body section (at a specific place on the page):
    <script language="javascript" type="text/javascript" src="http://www.progressiveagent.com/include/p_drive_ols_banner3.js"></script>

    There are other scripts that go in the Body section as well, so the Body example above is actually one of three scripts.

    Can anyone lend a poor guy a hand with this. I’ve already wasted a couple of hours trying different things that do not work.

    Thank you, and blessings!

    Todd

    #877755

    Lely
    Moderator

    Hi Todd,

    Because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

    Then add the following code on your child theme’s functions.php file:

    add_action( 'wp_head', 'x_custom_head_js' );
    function x_custom_head_js(){
    
    	?>
    <script language="javascript" type="text/javascript">function getDriveCode() {return '37794'}</script>
    <script language="javascript" type="text/javascript" src="http://www.progressiveagent.com/include/p_drive_banner_util.js"></script>
    	<?php
    }
    add_action( 'wp_footer', 'x_custom_body_js' );
    
    function x_custom_body_js(){
    	?>
    <script language="javascript" type="text/javascript" src="http://www.progressiveagent.com/include/p_drive_ols_banner3.js"></script>
    	<?php
    
    }

    Hope this helps.

    #879225

    Todd K.
    Participant

    Thank you so much for your help.

    I have added the code straight into the child theme’s functions.php.

    When I add the shortcodes, presumably [wp_head] and [wp_footer] in a Text Element, the only thing that appears is the shortcode text.

    Am I overlooking something?

    Thank you, thank you, thank you!

    Todd

    #879823

    Christopher
    Moderator

    Hi there,

    I’m not sure what you’re trying to achieve at this point. The provided function adds code to header and footer, you can’t add code to wp_head or wp_footer using shortcodes.

    Thanks.

    #880515

    Todd K.
    Participant

    Hello!

    I understand your point. Here’s my overall ultimate goal:

    1) Have the “Head section” code (see top of page) in the header, and lastly
    2) Have the ability to put the “Body section” code in specific spots. This code will actually show/reveal a custom Progressive Insurance logo with our company name. So, I need the flexibility to specify the exact location where the logo (i.e. the Body section code) will be.

    Make sense? 🙂 Thank you again for your assistance.

    Todd

    #880521

    Todd K.
    Participant

    (Correction: under #1 in the previous reply [4/13/2016 @12:58pm], I typed “in the header”. What I actually meant is that this code needs to be placed between the <head></head> tags.

    My bad.)

    #881365

    Rad
    Moderator

    Hi there,

    1. Yes, the purpose of this code

    add_action( 'wp_head', 'x_custom_head_js' );

    is to add your code between the <head></head> tags

    2. While this code,

    add_action( 'wp_footer', 'x_custom_body_js' );

    is to place your code before </body>

    The given is the exact solution to your requests. There is another one by using WordPress’s enqueue. But your code is just embed then the above code/solution is enough 🙂

    Thanks!

    #882339

    Todd K.
    Participant

    Greetings! I’ve created a short video through my ScreenCast account to show you what is happening on my end. If you could take a peek at this, that would be awesome as things are not working too good.

    Thank you, thank you, thank you!

    Todd

    #883321

    Lely
    Moderator

    Hi Todd,

    Thank you for the video. I think we do have a misunderstanding. We don’t have a [wp_footer] shortcode. The last code for wp_footer is just to include the script at the end of the page before body closing and intended to display anything. To achieve what you want please change above code to this:

    add_action( 'wp_head', 'x_custom_head_js' );
    function x_custom_head_js(){
    
    	?>
    <script language="javascript" type="text/javascript">function getDriveCode() {return '37794'}</script>
    <script language="javascript" type="text/javascript" src="http://www.progressiveagent.com/include/p_drive_banner_util.js"></script>
    	<?php
    }
    
    function load_script_content() {
    	return '<script language="javascript" type="text/javascript" src="http://www.progressiveagent.com/include/p_drive_ols_banner3.js"></script>';
    }
    
    add_shortcode('custom_script_shortcode', 'load_script_content');
    
    

    Then on a raw content element add this shortcode [custom_script_shortcode] to display the content.
    Hope this helps.

    #888856

    Todd K.
    Participant

    Greetings!

    I really appreciate the help. Unfortunately, this solution is not working as well. There is simply nothing being displayed when I put the [custom_script_shortcode] shortcode in a Raw Content element.

    Your code was successfully saved to the functions.php under the x-child theme. (/wp-content/themes/x-child/functions.php).

    What could be happening to cause this from not working?

    I thank you kindly.

    Todd

    #889602

    Jack
    Keymaster

    Hi there Todd,

    Thanks for writing back!

    Would it be possible to provide us WP login details and FTP details in a private reply please? We can then login and check why this isn’t working, as it definitely should be.

    Thank you!

    #890504

    Todd K.
    Participant
    This reply has been marked as private.
    #890505

    Todd K.
    Participant
    This reply has been marked as private.
    #891309

    Paul R
    Moderator

    Hi,

    We can’t access your site due to wordfence.

    http://screencast.com/t/z55oGGHmv47

    Can you disable it for a while until we can check.

    Thanks

    #892140

    Todd K.
    Participant
    This reply has been marked as private.