最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Create a link that calls our custom function in WordPress

programmeradmin4浏览0评论

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 badge
Add a comment  | 

2 Answers 2

Reset to default 0

Try 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();
    }
});
发布评论

评论列表(0)

  1. 暂无评论