I want to create the a link like , that should call my function and execute the code. I am doing this for my backend script call that link and send some parameters to save data in database, I want to create that link by plugin only so it will use any of other wordpress websites
I tried this by searching-
add_action( 'wp_loaded', function() {
if ( $_SERVER[REQUEST_URI] == '/mypage' ) {
data_collection();
}
});
function data_collection(){
//my coding stuff
}
But this showing me error and not worked as expected.
I want to create the a link like https://mywordpresssite/mypage, that should call my function and execute the code. I am doing this for my backend script call that link and send some parameters to save data in database, I want to create that link by plugin only so it will use any of other wordpress websites
I tried this by searching-
add_action( 'wp_loaded', function() {
if ( $_SERVER[REQUEST_URI] == '/mypage' ) {
data_collection();
}
});
function data_collection(){
//my coding stuff
}
But this showing me error and not worked as expected.
Share Improve this question asked May 1, 2020 at 5:35 RanjanRanjan 1011 bronze badge2 Answers
Reset to default 0Try this
add_action( 'wp_loaded','data_collection');
function data_collection(){
if ( $_SERVER[REQUEST_URI] == '/mypage' ) {
//my coding stuff
}
}
Try this:
function data_collection() {
// My coding stuff
}
add_action('wp_loaded', function () {
if (basename($_SERVER['REQUEST_URI']) == 'mypage') {
data_collection();
}
});