Posts Tagged ‘javascript’

Adding Scripts Properly to WordPress Part 3 – Page Detection

12
responses
by
on
May 8th, 2010
in
HOW-TO, WordPress FAQs

You might find yourself in the situation where you only want a script to run on a certain page. In fact, it’s good practice to only load your JavaScript files when absolutely necessary; loading the files on every single page is a big no-no (I’ve been chastised before for this). While on the blog’s front-end, WordPress makes it super-easy with its conditional tags. I’m not going to go over the conditional tags here, but here are a few you can take advantage of: is_home() is_front_page() is_single() is_page() And much more. While being selective on the front-end is relatively straightforward, the admin-panel is another monster. Sure, there’s the is_admin() conditional, but what if you only want to run a script in a certain section within the admin panel? One technique is to use the PHP reserved variable called $_GET. Say you have a plugin options page with a URL of: http://www.mydomain.com/wp-admin/options-general.php?page=my-plugin-file.php […]

[Continue Reading...]

Adding Scripts Properly to WordPress Part 2 – JavaScript Localization

9
responses
by
on
May 7th, 2010
in
HOW-TO, WordPress FAQs

When adding scripts to WordPress, you will inevitably run into a small, but painful, issue of localization. Localizing a plugin or theme is relatively straightforward, but JavaScript presents its own difficulties since we can’t easily call the PHP functions necessary (which is one reason authors embed JavaScript in PHP files). Since embedding JavaScript in PHP files is never a good technique, we use localization to save the day. With JavaScript localization, you can use PHP magic to build your localized strings, and then use JavaScript to read/parse those strings. What you do with them is only limited to your imagination. Furthermore, if you display anything with JavaScript, chances are your users will want the strings to be localized. Fortunately, WordPress provides the ultra-handy wp_localize_script function. wp_localize_script The wp_localize_script takes three arguments: handle object_name l10n Handle The handle argument will be the same handle you use for your script name. For […]

[Continue Reading...]

How To Include CSS and JavaScript Conditionally

38
responses
by
on
January 15th, 2010
in
LinkyLoo

This post written on the WeblogToolsCollection.com forums as a news submission has been well received by plugin developers that have taken notice. The article explains how to include CSS and JavaScript conditionally so that the code is not loaded on every page of the site. If you think about it, there are many plugins that only do something once in a blue moon. Table of contents, text manipulators, galleries, sliders, etc, etc. If only they loaded their frontend code strictly when necessary, most page loads would suddenly become much lighter. This technique if implemented by plugin authors sounds like it could have a significant impact on end users websites, especially when it comes to loading times. I’m always impressed with the speed of WordPress when I install a fresh copy without any plugins. WordPress loads very quickly both on the front and back ends. However, once I activate 30 or […]

[Continue Reading...]

How to Highlight Search Terms with jQuery

70
responses
by
on
April 10th, 2009
in
HOW-TO, WordPress FAQs

A neat way to spice up your WordPress search page is to highlight search terms within your search results. I’ve seen some tutorials on the net on how to do this, but I haven’t found one that highlights both title and post content and is a drop-in modification for WordPress. Today I will bring you this drop-in hack for highlighting search terms on your WordPress blog. Installation 1. Copy and paste the following code into your theme’s functions.php file: function hls_set_query() { $query = attribute_escape(get_search_query()); if(strlen($query) > 0){ echo ‘ <script type=”text/javascript”> var hls_query = “‘.$query.'”; </script> ‘; } } function hls_init_jquery() { wp_enqueue_script(‘jquery’); } add_action(‘init’, ‘hls_init_jquery’); add_action(‘wp_print_scripts’, ‘hls_set_query’); If you are having issues with copy-paste from this blog, here is a link to the same code in a txt file: Code to insert into functions.php 2. Copy and paste the following code into your theme’s header.php file (just before […]

[Continue Reading...]

Mouseover Transparent Dock

No
responses
by
on
July 14th, 2006
in
Cool Scripts, LinkyLoo

Mouseover Transparent Dock: Create a transparent (semi) dock-like menu on your page/blog with Javascript. I can see this becoming common on newer themes. Pretty cool if you are into this kind of thing. The only issue I see with this is that you have to let the user know that this exists, otherwise it would never occur to me know mouse over the header to get a new menu. Thanks Javascript Weblog

[Continue Reading...]

JSLint, The JavaScript Verifier

No
responses
by
on
April 12th, 2006
in
Code, LinkyLoo

JSLint, The JavaScript Verifier: Online implementation of a Javascript verifier that not only finds javascript bugs, it can also suggest improvements. Could be useful for debugging though I find that the default settings are a little too strict for my tastes.

[Continue Reading...]



Obviously Powered by WordPress. © 2003-2013

page counter
css.php