0

I want to create the a link like https://mywordpresssite.com/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.

2 Answers 2

0

Try this

add_action( 'wp_loaded','data_collection');

function data_collection(){
   if ( $_SERVER[REQUEST_URI] == '/mypage' ) {
   //my coding stuff
   }
}
0

Try this:

function data_collection() {
    // My coding stuff
}

add_action('wp_loaded', function () {
    if (basename($_SERVER['REQUEST_URI']) == 'mypage') {
        data_collection();
    }
});
2
  • Thanks, its works. I have a question - Is any other way to achieve this ?
    – Ranjan
    May 3, 2020 at 8:42
  • function data_collection(){ //my coding stuff } function call_custom_function(){ if ( isset($_GET['query_parameter']) ) { data_collection(); } } add_action('wp', 'call_custom_function'); Add above code in theme functions file and hit this URL from browser: mywordpresssite.com/?query_parameter May 4, 2020 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.