I'm having some issues registering jQuery scripts. I'm a designer who is fairly new to coding, rather proficient in HTML and CSS, but Java is still new to me.
I am trying to properly register a few Js scripts in a client site:
The first is a simple jQuery call to action bar for the header:
(documentation and code is there)
It seems the theme has a custom functions-header.php file that .functions.php call .js from as well as the standard functions.php calling scripts. However, I am going nuts as to where/how to setup and reference the code(s). The functions-header.php is located in the theme/includes file.
I'd also like to call a separate .css file for the plugin as opposed to putting it all in style.css.
I know how to call stylesheets via:
<link href="http://www.mydomain.com/css/mainstyles.css" rel="stylesheet" type="text/css" />
but according to WP codex it should also be done using the enqueue script, so I'd like to register that as well. I am lost.
Here's the functions.php
[[LINK href="http://pastebin.com/20R780R9"]]and functions-header.php[[/LINK]]
add the following to line 170 of your theme's functions.php or header functions for enqueueing the required js scripts first, upload the Woahbar js to the /js/ folder.
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', false, '1.9.1');
wp_register_script('jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js', array('jquery'), '1.10.1');
wp_register_script( 'woahbar', get_template_directory_uri() . '/js/WOAHbar.js', array( 'jquery' ), false, true );
As for the styles, I would suggest you add it to the main style as it reduces the http requests, meaning that the page loads faster, you can check at gtmetrix or pingdomtools to see your website load speed and http requests number.
<strong>more information about en-queueing scripts and registering them:</strong>
<strong>If you need particular version of the google cdn js scripts go here and change the version accordingly</strong>
I updated functions.php as above, added WHOAbar.js to /js but not working. Css has been added to bottom of style.css. From the documentation:
<blockquote>STEP 1 - CALL MAIN JS SCRIPTS:
You will need to add the following scripts BEFORE the </head> tag of your webpage for any of the following to work properly:
As you posted, do I need to call a specific version of java for each plugin? Is that what the _register_script & _deregister_script do?
<strong>Do I need to 'register' (via the helpful Google library link) version 1.7.1 or 1.8.16 to get this to work? Is Jquery not backwards compatible w/ previous versions?</strong>
Believe me, I read both those codex articles about 5 times each, as well as countless articles online. I have no problem with Java in HTML, but adding new scripts into WP is a fairly new endeavor for me.
rray( 'jquery' ), false, true );
<blockquote>array( 'jquery' )</blockquote>
the array means that the file requires jquery to run, 'false' is the parameter for an array and true means that it should load the js file in the footer.
I would recommend to read the listed codex links, they clear things out and explain these parameters in depth.
sorry i didnt read the rest of your message, basically wordpress by default loads jquery, however the versions on google cdn are always uptodate, you can disable the code for that if you want to use local file.
most plugins work with default version of jquery so there is no need for a specific version for each plugin, however some may use new functions available in newer versions.
If you want to grant me access, I will check what the issue is, please provide credentials via PM
You can check the following jsfile to see it working (note, looks messy no images)
Get rid of the "display:none" style in the following <div class="woahbar" style="display: none;">