Tag Info

Hot answers tagged

6

Yes, jQuery is part of WordPress core. But--it can become outdated, because jQuery updates can happen in between WP releases. The recent release of WordPress does use a very recent version of jQuery. By default, wp_enqueue_script('jquery') grabs jQuery from the core at /wp-includes/js/jquery/jquery.js. The "correct" way to add jQuery to your WP site ...


5

Custom implementation vs. Standard API usage Using the WP AJAX API is the way to go. First off, you get access to the complete set of WP APIs, you can leverage standard jQuery $.ajax() and similar API calls and you are running standard conform, gaining access to all knowledge spread around the web with articles or for e.g. in answers on this site. In the ...


3

This is an add on to @kaiser answer, read that before. To be honest wp_localize_script, add_action are the best part of Ajax API, and really, they are an help, not a problem. Let's imagine you have 120 ajax functions. Even if you don't use admin-ajax.php see again your workflow: Check user is authenticated, if not, return a 403 header and exit(); ...


3

The normal behavior of wp_enqueue_script is to put the script output into the head section, the parameter $in_footer is optional and defaults to false. So, you can load jQuery with your plugin into the head and, assumed your dealing with well programmed themes/plugins, it won't load again, because wp_enqueue_script prevents this by default - additional ...


2

The third parameter of wp_enqueue_script() allows you declare dependencies for the script you're enqueueing, i.e. what other scripts are required for them to run. add_action( 'wp_enqueue_scripts', 'include_script_that_depends_on_jquery' ); function include_script_that_depends_on_jquery() { wp_enqueue_script( 'my_script.js', '/path/to/my_scripts.js', ...


2

You should first load your scripts with a hook on wp_enqueue_scripts like this for example : add_action( 'wp_enqueue_scripts', 'load_my_scripts' ); function load_my_scripts() { wp_enqueue_script( 'jquery' ); } What I like to do is, register my script with a hook on init and then enqueue them with a hook on wp_enqueue_scripts: // Register Scripts ...


2

Scripts and stylesheets should always be loaded in the head or in the footer via the wp_enqueue_scripts action hook. wp_enqueue_scripts is the proper hook to use when enqueuing items that are meant to appear on the front end The init hook executes before wp_head which is to early for script to load in the header. The wp_enqueue_scripts action hook is ...


1

The way you suggest doing this, it won't ever be secure. If I understand you, just disabling Javascript would spoil the security. What you'd need to do is run a script that uses an AJAX request to query for and then add data to the page, but only if the user is logged in. That would fail safe if Javascript were disabled. However, that is also a very ...


1

For example, if I wanted a simple jQuery("body").css("background-color","red"); executed from within a shortcode in the body, I can't do it. Let's say my shortcode is [body color=red] but jquery isn't loaded till the footer, then my code won't work. In your shortcode handler You could return an HTML placeholder element or JavaScript variable, ...


1

If you read the documentation for locate_template you'll see the problem. locate_template( $template_names, $load, $require_once ); $require_once (boolean) (optional) If true, the template file will be loaded with the php require_once function. If false, the template file will be loaded with the php require function. This parameter has no effect if ...


1

This is just a similar example that would do something you have question about. Every time the user clicks a button it would load random posts. HTML: <input type="button" id="load" value="Load random posts" /> <div id="posts"></div> JQuery: <script type="text/javascript"> $(document).ready(function(e) { ...


1

I've been playing with ajax for the past couple days - I like to go the hook route so first lets set up our ajax call: $('#buttonID').click(function(){ $.ajax({ url: '/wp-admin/admin-ajax.php', type: 'GET', data: { 'action' : 'implement_ajax' }, dataType: 'html' }) .success(function(results){ ...


1

To be honest I think you can just use some custom css to get the job done. Wordpress gives the homepage a custom body class of home. so if we use that and dig down in the css to the first menu and move it over into view you should be good. .home .menu > li > ul { left: 0; } and to get the hover state on the 'Data' link just use .home #header .menu ...


1

WordPress makes number of typographical replacements, related to dashes. You can read through the How WordPress Handles Dashes and Hyphens for full details, but in short your specific case is [space][hyphen][space] getting replaced with [space][en-dash][space]. You will have to step through your code to make sense at which point it goes wrong and turns into ...


1

This is an Ajax thing. One solution to make your script work again when you save the widget: jQuery(document).ajaxSuccess(function(event, xhr, settings) { var widget_id_base = 'your-widget-id-base'; if(settings.data.search('action=save-widget') != -1 && settings.data.search('id_base=' + widget_id_base) != -1) { // Do you stuff again ...


1

Your jQuery code is using the $ symbol without accounting for noConflict mode. More information: http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers



Only top voted, non community-wiki answers of a minimum length are eligible