Tag Info

New answers tagged

0

wp_ajax_{my-action} action hook is only for admin side. For frontend you must use wp_ajax_nopriv_{my-action}. You can combina both if the ajax action is for both sides. For example: add_action('wp_ajax_filter_search', 'filter_search_result'); add_action('wp_ajax_nopriv_filter_search', 'filter_search_result'); Also, don't forget, never, to die or exit at ...


-1

put this code at the end of functions.php add_action('customize_register', 'customizer'); function defer_parsing_of_js ( $url ) { if ( FALSE === strpos( $url, '.js' ) ) return $url; if ( strpos( $url, 'jquery.js' ) ) return $url; return "$url' defer "; } add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );


0

So, after hours of searching, I finally found where was my problem : another method in my class interfered with my ajax authentication system.


2

One way to do it (which is probably evil) is to select the control by adding a block of javascript using the tr field of $form_fields: function set_image_data( $form_fields, $post ) { $form_fields['text_color'] = array( 'label' => 'Text Color', 'input' => 'text', 'value' => get_post_meta( $post->ID, '_text_color', ...


0

This plugin allows custom JS and custom CSS on a per post/page basis. https://wordpress.org/plugins/art-direction/ If you find that it is not compatible with your WP install, look for other plugins that allow custom JS and CSS. If you're looking for a more robust solution, you can do something like the following: /* overlay-contact-form.css */ ...


1

As per comments try collecting the ids in an array and then setting the text field once: custom_uploader.on('select', function() { var selection = custom_uploader.state().get('selection'); var ids = selection.map( function (attachment) { return attachment.id; }); ...


1

I don't think using React.js without Node.js (or at least V8 or rhino etc) counts as isomorphic, as isomorphic means that you are building JavaScript to run in the browser AND on the server. Specifically, using WordPress certainly means you aren't doing isomorphic javascript (its PHP software). What you could do is use WordPress as a REST API server, and ...


0

If you want to be able to validate server side the easiest option is to use Advanced Custom Fields to define your custom field layouts, and then the Validated Field add-on to set your validation per field in the WordPress Admin.


0

Check the type of the queried object on the page and the post type: function function_that_returns_js_string() { $obj = get_queried_object(); $type = is_a($obj,'WP_Post'); if (true === $type && 'post' == $obj->post_type) { echo 'your string'; } } add_action('wp_head', 'function_that_returns_js_string'); However, I am concerned that ...


1

You gave each each script the same handle/id of 'grid' Try something like this. function banana_scripts() { wp_enqueue_script('grid', get_stylesheet_directory_uri() . '/js/jquery.min.js', null, null); wp_enqueue_script('grid2', get_stylesheet_directory_uri() . '/js/main.js', null, null); } add_action('wp_enqueue_scripts', ...


1

I found a nice way to do this using the preview_post_link filter, which allows you to rewrite the URL used by the preview operation. In my case I did something like: add_filter( 'preview_post_link', function ( $link ) { return 'http://domain.com/mobile-preview/?src=' . urlencode($link) . '%26admin_bar=false'; } ); When I click my preview button ...


3

Have you tried returning an array instead? wp_send_json($an_array_of_your_vals); And then parse the array in the success function? success: function( data ) { var obj = jQuery.parseJSON(data); if( obj.arg_1 ) { $('selector').append( obj.content ); } else if( obj.arg_2 ) { $('other_selector').append( obj.content ); } ...


0

You could use .ajaxComplete, as mentioned by @onetrickpony in http://wordpress.stackexchange.com/a/36597/57034, except do it globally on document, as mentioned in http://api.jquery.com/ajaxcomplete/, then filter based on action: add_action( 'admin_print_footer_scripts', function () { ?> <script type="text/javascript"> jQuery(function ...


0

You should be able to dequeue like normal. Despite the complexity of the function, it is really just enqueueing scripts and styles. Tested with the admin bar script on the front end: add_action( 'wp_enqueue_scripts', function() { wp_dequeue_script('admin-bar'); } ); You just want admin_enqueue_scripts and set-post-thumbnail: add_action( ...


0

You should try this plugin, this worked best when I needed similar on one of the blogs. Ajax Load More: It's available on WordPress repo.


1

Allowing user to control code is explicitly unsafe operation. As you note the purpose of sanitization is pretty much to not let user slip in anything executable and/or with malicious intent. To "sanitize" executable code you would need programmatic understanding of it (code parser) and criteria engine to distinguish what is safe and what is not. For such ...


0

If you think about switching the Plugin: I did used "WP REST API" Plugin (wich implements WP API) and then $http.get('WPURL/wp-json/posts', function (data, ...) {...}), that worked perfect. You get the Posts featured image for example via data[post-index].featured_image.source, see all properties via console.log(data[0]).


0

Doublecheck if there’s a “nobase” error in your console. If so, according to the AngularJS documentation, and fix.io (credits for this answer go to the author of that post) the base tag is to the rescue. <html ng-app="app"> <head> <base href="/angular-wp/"> <title>AngularJS Demo Theme</title> <?php wp_head(); ?> ...


0

Use the old button method: <input type="button" value="Download" onClick="download('file.ext')" > and then write down some JS to activate the download; <script> function download(file) { window.location=file; } </script> This should work.


1

Your first attempt does not work because get_template_directory_uri returns the URL to your theme directory. Your second attempt will work, but if you don't want to hard code the domain you could either try using a root relative path or fetching the domain portion of your site url. Relative path: wp_register_script('circle-bounce', '/js/general.js', ...


0

I supposed that you are trying to set defer for every JS exclude jquery.min and jquery.ui.core.min. Based on that I have made some changes into your code and this will set defer for all JS exclude given example files jquery.min and jquery.ui.core.min. function add_defer_to_cf7( $url ) { //If not js file OR js file with 'jquery.ui.core.min' OR ...



Top 50 recent answers are included