Skip to main content
added 162 characters in body
Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

Yes. You can do. Try using ajax, or better? using wordpress rest api

Ajax method: need register your function and action to do

Simple example:

add_action( 'wp_ajax_my_action', 'my_action' );
 
function my_actionadd_action() {
    return'wp_ajax_nopriv_my_action', json_encode('hello'my_action' word');
}
<script>
jQuery(document).ready(function($) {
    var data = {
        'action': 'my_action'
    };
    jQuery.post(ajax_url, data, functionmy_action(response) {
       return alertjson_encode(response);
   'hello }word');
});
</script>
jQuery(document).ready(function() {
    var data = {
        'action': 'my_action'
    };
    jQuery.post(ajax_url, data, function(response) {
        alert(response);
    });
});

More info for ajax: https://codex.wordpress.org/AJAX_in_Plugins

Wordpress rest api: need to register a route

very simple example:

add_action( 'rest_api_init', function () {
  register_rest_route( 'yourName/v1', '/myroute', array(
    'methods' => 'GET''POST',
    'callback' => 'my_function',
  ) );
} );

function my_function( $data ) {
  return 'Hello World';
}
jQuery(document).ready(function() {
    jQuery.post('/wp-json/yourName/v1/myroute', function(response) {
        alert(response);
    });
});

More info: https://developer.wordpress.org/rest-api/

Yes. You can do. Try using ajax, or better? using wordpress rest api

Ajax method: need register your function and action to do

Simple example:

add_action( 'wp_ajax_my_action', 'my_action' );
 
function my_action() {
    return json_encode('hello word');
}
<script>
jQuery(document).ready(function($) {
    var data = {
        'action': 'my_action'
    };
    jQuery.post(ajax_url, data, function(response) {
        alert(response);
    });
});
</script>

More info for ajax: https://codex.wordpress.org/AJAX_in_Plugins

Wordpress rest api: need to register a route

very simple example:

add_action( 'rest_api_init', function () {
  register_rest_route( 'yourName/v1', '/myroute', array(
    'methods' => 'GET',
    'callback' => 'my_function',
  ) );
} );

function my_function( $data ) {
  return 'Hello World';
}

More info: https://developer.wordpress.org/rest-api/

Yes. You can do. Try using ajax, or better? using wordpress rest api

Ajax method: need register your function and action to do

Simple example:

add_action( 'wp_ajax_my_action', 'my_action' );
add_action( 'wp_ajax_nopriv_my_action', 'my_action' );

function my_action() {
    return json_encode('hello word');
}
jQuery(document).ready(function() {
    var data = {
        'action': 'my_action'
    };
    jQuery.post(ajax_url, data, function(response) {
        alert(response);
    });
});

More info for ajax: https://codex.wordpress.org/AJAX_in_Plugins

Wordpress rest api: need to register a route

very simple example:

add_action( 'rest_api_init', function () {
  register_rest_route( 'yourName/v1', '/myroute', array(
    'methods' => 'POST',
    'callback' => 'my_function',
  ) );
} );

function my_function( $data ) {
  return 'Hello World';
}
jQuery(document).ready(function() {
    jQuery.post('/wp-json/yourName/v1/myroute', function(response) {
        alert(response);
    });
});

More info: https://developer.wordpress.org/rest-api/

added 871 characters in body
Source Link

Yes. You can do. TrayTry using ajax, soor better? using wordpress rest api

Ajax method: need register your function and action to do

Read this linkSimple example:

add_action( 'wp_ajax_my_action', 'my_action' );

function my_action() {
    return json_encode('hello word');
}
<script>
jQuery(document).ready(function($) {
    var data = {
        'action': 'my_action'
    };
    jQuery.post(ajax_url, data, function(response) {
        alert(response);
    });
});
</script>

More info for ajax: https://codex.wordpress.org/AJAX_in_Plugins

Wordpress rest api: need to register a route

very simple example:

add_action( 'rest_api_init', function () {
  register_rest_route( 'yourName/v1', '/myroute', array(
    'methods' => 'GET',
    'callback' => 'my_function',
  ) );
} );

function my_function( $data ) {
  return 'Hello World';
}

More info: https://developer.wordpress.org/rest-api/

Yes. You can do. Tray using ajax, so need register your function and action to do

Read this link: https://codex.wordpress.org/AJAX_in_Plugins

Yes. You can do. Try using ajax, or better? using wordpress rest api

Ajax method: need register your function and action to do

Simple example:

add_action( 'wp_ajax_my_action', 'my_action' );

function my_action() {
    return json_encode('hello word');
}
<script>
jQuery(document).ready(function($) {
    var data = {
        'action': 'my_action'
    };
    jQuery.post(ajax_url, data, function(response) {
        alert(response);
    });
});
</script>

More info for ajax: https://codex.wordpress.org/AJAX_in_Plugins

Wordpress rest api: need to register a route

very simple example:

add_action( 'rest_api_init', function () {
  register_rest_route( 'yourName/v1', '/myroute', array(
    'methods' => 'GET',
    'callback' => 'my_function',
  ) );
} );

function my_function( $data ) {
  return 'Hello World';
}

More info: https://developer.wordpress.org/rest-api/

Source Link

Yes. You can do. Tray using ajax, so need register your function and action to do

Read this link: https://codex.wordpress.org/AJAX_in_Plugins