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.

0

Try this

add_action( 'wp_loaded','data_collection');

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

Try this:

function data_collection() {
    // My coding stuff
}

add_action('wp_loaded', function () {
    if (basename($_SERVER['REQUEST_URI']) == 'mypage') {
        data_collection();
    }
});
| improve this answer | |
  • Thanks, its works. I have a question - Is any other way to achieve this ? – Ranjan May 3 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 – Yash Tiwari May 4 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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