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.
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.
收起
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.
报告相同问题?