ajax, right way to do it and make it works?

In your functions.php file you should add an action to enqueue your scripts. <?php function my_enqueue_scripts() { wp_enqueue_script( ‘load_post’, get_template_directory_uri() . ‘/js/load_post.js’, array( ‘jquery’ ), ‘1.0’, 1 ); wp_localize_script( ‘load_post’, ‘wp_ajax’, array( ‘url’ => admin_url( ‘admin-ajax.php’ ), ‘nonce’ => wp_create_nonce( ‘ajax_nonce’ ) ) ); } add_action( ‘wp_enqueue_scripts’, ‘my_enqueue_scripts’ );

Best approach to fetch data from wp options to js file or php file

Assuming you’re not using AJAX for form submission, you can use wp_localize_script(). Here’s a simplified version: In your plugin file: function wpse105919_add_scripts(){ wp_enqueue_script( ‘myjs’, plugins_url( ‘/myjs.js’, __FILE__ ) ); wp_localize_script( ‘myjs’, ‘jsLocalizedObject’, ‘hello world’); } add_action(‘wp_enqueue_scripts’, ‘wpse105919_add_scripts’); contents of myjs.js file: alert( jsLocalizedObject ); wp_localize_script() will add a global variable called jsLocalizedObject to your document’s … Read more

Dealing with a library that depends on jQuery

First of all if you investigate PikaChoose source code, then you will see that it wraps the code with self invoking closure: (function($) { // … })(jQuery); It means that they use short form properly. In the same time it means that all you need to do is to enqueue jQuery and PikaChoose scripts and … Read more

Ajax load more button in Recent posts widget

Look at WordPress’s documentation on AJAX In your theme or plugin, you’ll want to have code like: add_action(‘wp_ajax_my_load_recent’, ‘my_load_recent_posts’); add_action(‘wp_ajax_nopriv_my_load_recent’, ‘my_load_recent_posts’); function my_load_recent_posts() { $args = array( /* Arguments go here, i.e. how many posts to get */ ); query_posts($args); /* [1] */ /* Header wrap output */ if (have_posts()) : while (have_posts()) : the_post(); … Read more

`wp_editor()` CSS messing up the jQuery Dialog

Yeah this is a fun one had to make some mods to make this one work…. add this to your theme stylesheet (style.css): .ui-front { z-index: 1001 !important; } .ui-widget-overlay { background: none repeat scroll 0 0 #000000 !important; opacity: .6 !important; filter: Alpha(Opacity = 60) !important; } This should override the editor.css. Let me … Read more

Masonry and Jetpack Infinite Scroll – overlap issue

I have now solved point (2), the overlapping posts problem; maybe this will help someone else. I changed wrapper to true in the mytheme_jetpack_setup function in my PHP (so that the new posts are wrapped in their own div) And I changed the jQuery to: $(‘#content’).masonry({ columnWidth: ‘.grid-sizer’, itemSelector: ‘article’, gutter: ‘.gutter-sizer’ }); var infiniteCount … Read more