Force redirect single.php to index
put this code in functions.php file add_action(‘wp’, ‘myfun’); function myfun(){ if(is_single()){ wp_redirect( home_url() ); exit; } } hope this trick solve your problem. all the best 😉
put this code in functions.php file add_action(‘wp’, ‘myfun’); function myfun(){ if(is_single()){ wp_redirect( home_url() ); exit; } } hope this trick solve your problem. all the best 😉
You have a space in your function name on the action call, add_action( ‘wp_ajax_nopriv_ MyAjaxFunction’, ‘MyAjaxFunction’ ); add_action( ‘wp_ajax_ MyAjaxFunction’, ‘MyAjaxFunction’ ); …should be, add_action( ‘wp_ajax_nopriv_MyAjaxFunction’, ‘MyAjaxFunction’ ); add_action( ‘wp_ajax_MyAjaxFunction’, ‘MyAjaxFunction’ );
You need to send the var through your ajax request: $.post( //be suer that this var is pointing to wp-admin/admin-ajax.php WPaAjax.ajaxurl, { action : ‘my_php_action_to_do’, //here your var and its value my_var : ‘the_value’ }, function( response ) { response = jQuery.parseJSON(response); alert(response.message); } ); In your my_php_action_to_do function: function my_php_action_to_do(){ $var[‘message’] = $_POST[‘my_var’]; //Send … Read more
If you add the script inline you don’t need to use wp_localize_script. All you have to do is directly print your inline script exactly as you need it dinamically. For example, in your template: <?php // The PHP code of the template here ?> <script> jQuery(document).ready(function($){ var s=1; $(‘button’).on(‘click’,function() { //wfire the ajax call jQuery.ajax({ … Read more
Here is a short plugin that adds the interim-login lightbox on every frontend page: <?php /* Plugin Name: Interim Login Everywhere Version: 1.0.1 Plugin URI: http://nowhere.com Description: Provide interim login screens on all pages. Author: S Valentine */ function ile_enqueue_scripts() { // we only care to add scripts and styles if the user is logged … Read more
The ajax_url should be admin_url( ‘admin-ajax.php’ ) and not plugins_url( ‘plugin.php’, __FILE__ ) when you localize your js variables.
You need to follow these steps to properly call ajax function in WordPress, Register and localize your script, eg. wp_register_script( ‘*handle_name*’ , *js_file_path* , array( *dependency_name* ) , true , true ); It will load your script at page footer. Refer to the following link: https://developer.wordpress.org/reference/functions/wp_register_script/ wp_localize_script( ‘*handle_name*’ , ‘*a_unique_name_to_call_this_object*’ , array( ‘ajaxurl’ => admin_url( … Read more
I tested your code and got it to work by removing the following line as it is unnessacary. options.data = JSON.stringify(options.data); You can also safely remove the following lines in your AJAX call. contentType: ‘application/json’, // tried without it too dataType: ‘json’, // tried without it too Please check out AJAX in Plugins on the … Read more
The data you send from jQuey to PHP is in the $_POST variable. So you can use $_POST[‘projectid’] inside your PHP function to get the data.
As mentioned in the documentation: When the handler has finished all of its tasks, it needs to die. If you are using the WP_Ajax_Response or wp_send_json* functions, this is automatically handled for you. If not, simply use the WordPress wp_die() function. wp_die(); // That’s all folks! So you either need to use: $result[‘success’] = false; … Read more