Jump to content
Sign in to follow this  
MissT

Adding javascript to Headerscripts Code

Recommended Posts

MissT

Hi there,

 

I've been given a bit of javascript code to add to my Pagelines Framework (v 2.0.0.) WP v 3.3.1 website which I thought would go in the Headerscripts Code area...

 

Query(document).ready(function() {

                        var elm = jQuery('#'+document.location.hash.replace('#',''));

                        if (elm.attr('href')) {

                                                elm.addClass('highlighted');

                        }

});

 

I don't know javascript - do I have to put something round the code to add it or save it as a file somewhere else then call it from the Headerscripts code area with something like the following?...

 

<script type="text/javascript" src="/scripts/emailpage.js"></script>

 

Many thanks in advance! :)

Share this post


Link to post
Share on other sites
Danny

Hi,

 

Adding this to your Header Scripts should work, just remember to use the full URL.

 

<script type="text/javascript" src="/scripts/emailpage.js"></script>

Also, PageLines 2.0.0 ?

I recommend you perform a backup and upgrade to the latest version which is version 2.4.1


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
MissT

Hi,

 

There is no url at the moment - that is what I was asking... do I need to save the code I've been given...

 

Query(document).ready(function() {

                        var elm = jQuery('#'+document.location.hash.replace('#',''));

                        if (elm.attr('href')) {

                                                elm.addClass('highlighted');

                        }

});

 

into a file? If so how do I do this?  I take it I can't just paste the code above directly into the Headerscripts Code area?

 

The site is a copy of another site created ages ago so I'm not planning to upgrade at this point in time.

 

Thanks again.

Share this post


Link to post
Share on other sites
Danny

Well you should be able to add the code either way, by adding the code itself to the header scripts or add it to a file, upload that file to your server and then link it like I mentioned above.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
MissT

I added the code itself directly to the headerscript area as it looked like the quickest / most obvious option but when I looked at the site the code was appearing at the very top of the website on screen - so I thought perhaps I need to wrap some code round it.

 

So you are saying the following placed directly in the Headerscript Code should work?...

 

Query(document).ready(function() {

                        var elm = jQuery('#'+document.location.hash.replace('#',''));

                        if (elm.attr('href')) {

                                                elm.addClass('highlighted');

                        }

});

Share this post


Link to post
Share on other sites
MissT

I've just tried putting <script> and </script> round the code in the Headscripts area and that seems to have done the trick, well no error anyway - now to see if the code added works!

 

Thanks.

Share this post


Link to post
Share on other sites
Danny

No problem, happy to help! :D


Please search our forums, before posting!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • gstrahle
      By gstrahle+
      Hi,
      Is there anything that can possible be done to improve the loading performance of PageLines Platform and Elements?
      https://goldenstategreens.com/wp-content/plugins/pl-platform/engine/ui/js/common.js?ver=946207(180.5KiB) https://maps.gstatic.com/maps-api-v3/embed/js/36/11/init_embed.js(146.6KiB) https://maps.googleapis.com/maps/api/js?client=google-maps-embed&paint_origin=&libraries=geometry,search&v=3.exp&language=en_US®ion=us(99.3KiB) https://goldenstategreens.com/wp-includes/js/jquery/jquery.js?ver=1.12.4(87.0KiB) https://goldenstategreens.com/wp-content/plugins/pl-section-slider/flickity.js?ver=946207(48.2KiB) https://goldenstategreens.com/wp-content/plugins/pl-section-impulse/owl.js?ver=946207(35.3KiB) https://goldenstategreens.com/wp-content/plugins/pl-platform/engine/ui/js/site.js?ver=946207(18.8KiB) https://goldenstategreens.com/(17.5KiB of inline JavaScript) https://secure.gravatar.com/js/gprofiles.js?ver=2019Apraa(15.9KiB) https://goldenstategreens.com/wp-includes/js/jquery/ui/effect.min.js?ver=1.11.4(11.6KiB) https://goldenstategreens.com/wp-includes/js/jquery/ui/tabs.min.js?ver=1.11.4(9.6KiB) https://s0.wp.com/wp-content/js/devicepx-jetpack.js?ver=201917(9.4KiB) https://goldenstategreens.com/wp-content/plugins/pl-section-lax/parallax.min.js?ver=946207(7.8KiB) https://goldenstategreens.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1(7.7KiB) https://goldenstategreens.com/wp-includes/js/jquery/ui/accordion.min.js?ver=1.11.4(6.4KiB) https://goldenstategreens.com/wp-includes/js/jquery/ui/widget.min.js?ver=1.11.4(6.1KiB) https://goldenstategreens.com/wp-content/plugins/pl-section-meganav/superfish.js?ver=946207(4.4KiB) https://goldenstategreens.com/wp-includes/js/jquery/ui/core.min.js?ver=1.11.4(3.3KiB) https://goldenstategreens.com/wp-content/plugins/pl-section-meganav/meganav.js?ver=946207(2.2KiB) https://goldenstategreens.com/wp-content/plugins/pl-section-meganav/sticky.js?ver=946207(2.2KiB) https://goldenstategreens.com/wp-content/plugins/pl-section-impulse/impulse.js?ver=946207(1.7KiB) https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3355.356766011451!2d-117.21045368481853!3d32.75626678097826!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x80deaaeffa185a7f:0x6613dd77eb86c21!2sGolden+State+Greens!5e0!3m2!1sen!2sus!4v1552542527201(1.5KiB of inline JavaScript) https://goldenstategreens.com/wp-includes/js/wp-embed.min.js?ver=5.1.1(1.2KiB) https://goldenstategreens.com/wp-content/plugins/google-analyticator/external-tracking.min.js?ver=6.5.4(975B) https://goldenstategreens.com/wp-content/plugins/jetpack/modules/wpgroho.js?ver=5.1.1(716B) https://goldenstategreens.com/wp-content/plugins/jetpack/_inc/build/widgets/milestone/milestone.min.js?ver=20160520(488B) https://goldenstategreens.com/wp-content/plugins/pl-section-flicky-posts/js/script.js?ver=946207(469B) https://goldenstategreens.com/wp-content/plugins/jetpack/_inc/build/photon/photon.min.js?ver=20130122(395B) https://goldenstategreens.com/wp-content/plugins/pl-section-lax/lax.js?ver=946207(352B) https://goldenstategreens.com/wp-content/plugins/pl-section-slider/slider.js?ver=946207(319B)  
      We are working on site loading performance and would like to get a passing grade, and our load time down to 3 seconds.  We will be making updates to the content size to bring it down as well. Please let me know if there is anything that can be done to address the loading issues found here within PageLines Plugins.
      https://gtmetrix.com/reports/goldenstategreens.com/5rnupbNu
       
      Thanks
    • IDdigital
      By IDdigital+
      Hi,
      A site of ours irregularly does not finish loading. The page in question is https://rw360.org/grievance-process/
      In Safari, I'll occasionally get the following error:
      [Error] TypeError: undefined is not an object (evaluating 'a.plModel.init')
          (anonymous function) (site.js:5:91)
          i (jquery.js:2:27455)
          add (jquery.js:2:27750)
          ready (jquery.js:2:29819)
          (anonymous function) (site.js:5)
          Global Code (site.js:5:3421)
      This seems to be a bug in PageLines as far as I can tell. Any suggestions or a fix coming?
      Thanks,
    • Michael Kummer
      By Michael Kummer+
      Hi guys!
      I am using a plugin called Speed Booster Pack to speed up the load time of michaelkummer.com. One of the plugin settings, Minimize HTML and JavaScript causes an error that I only get with Pagelines. With other themes, such as WordPress' Twenty Seventeen, I do not get that error.
      I have reproduced the problem on my staging site and if you look at the JavaScript console, you will see the following error:
      SyntaxError: Unexpected end of script
      Any clue what PageLines may be doing differently to be contributing to this issue? I contacted the plugin developer and they, of course, pointed me to the theme developer
      Thanks
      Michael
    • flourishdesignstudio
      By flourishdesignstudio+
      Hello,
      We are working on a site and the customers are complaining that the site loads too slowly. They contacted their host who mentioned that the Java Script is all loading at the beginning. Is it possible to delay the load of the less important Java Script until after the initial load to speed up the site? The goal is to load the page faster by minimizing the initial javascript calls.
      Are there any preferred plugins that you would recommend or does this end up causing excessive problems with plugins, etc.?
      Thanks for the help!
    • chamois_blanc
      By chamois_blanc+
      I am trying to clone a container on a page. It throws the following javascript error:
      function l(b, c, e, f) { var g = m.a.f.get(b, p); if (!c) { if (g) throw Error("You cannot apply bindings multiple times to the same element."); m.a.f.set(b, p, !0) } I would appreciate guidance and a fix. Thank you
×