dscqrkvr9562034621 2017-09-04 20:49
浏览 186
已采纳

将基于自定义URL的控制器添加到WordPress

How can I add a custom controller to WordPress?

For example If I enter http://my-wp.com/custom_route in url bar and my custom function gets executed.

  • 写回答

1条回答 默认 最新

  • douci2516 2017-09-04 21:07
    关注

    You can use something like this for example, using $_SERVER['REQUEST_URI'] to get the url path and then you will process it to find 'custom_route'.

    If 'custom_route' is found, it will trigger something, like a function or some custom code:

    $found = false;
    $data = $_SERVER['REQUEST_URI'];
    $data = explode( '/', $data );
    foreach($data as $value)
        if( 'custom_route' == $value ) ){
            $found = true;
            break;
        }
    if( !empty($value) && $found ){
        // Do something here (add a function or some code
        // exec_my_custom_function();
    }
    

    Tested and works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部