How to Add Javascript Only When a Function Exists?

Hi @Denis Belousov: Okay, based on your responses I’m going to ask why tie it to the function existing, why not just test the return value of get_option(‘src_switcher’) like this? function my_scripts() { if (!is_admin()) { wp_enqueue_script(‘jquery’); wp_enqueue_script( ‘custom’, get_bloginfo(‘template_directory’).’/js/custom.js’, array( ‘jquery’ ), ”, true ); if (is_front_page()) { $sliders = get_option(‘src_switcher’); if ($sliders == … Read more

AJAX Contact Form Issue

are you logged-in with all browsers? since add_action(‘wp_ajax_contact_form’, ‘ajax_contact’); only works for logged in users, so to fix it you need to change it: add_action(‘wp_ajax_nopriv_contact_form’, ‘ajax_contact’); if you want your function to work for visitors as well as users.

Script will not print in head if path to file is correct

How about using locate_template() for the inclusion and wp_enqueue_script() for the scripts? There’s also content_url() to target /wp-content/. Also: How did you inspect it? Sourcecode? FireBug? Try to open source in FF and then click the link. If you get a “file not found”, you know what it’s about, else it should be loaded. The … Read more

Run JS after widget settings are saved?

Put your javascript code inside the widget form, and it will be triggered whenever the widget is refreshed. If you’re tabs are hooked on a click event, a better way would be to use $.delegate on the widget instance wrapper. That way you don’t need to include the js inside every widget instance…

Add a Fancybox automatically to post type “post” images

Here is the code i use in my site, which loads all images under an anchor tag to fancybox add_action(‘wp_footer’,’auto_fancy_box’); function auto_fancy_box(){ if (!is_single() && !is_page()) return; ?> <SCRIPT TYPE=”text/javascript”> jQuery(document).ready(function(){ jQuery(“.post_content”).find(“a:has(img)”).addClass(‘group’); jQuery(“.post_content”).find(“a:has(img)”).attr(‘rel’,’group1′); jQuery(“a.group”).fancybox({‘transitionIn’:’elastic’,’transitionOut’:’elastic’,’speedIn’:600,’speedOut’:200,’overlayShow’:false}); }); </SCRIPT> <?php } just change the .post_content to your post content container jQuery selector.