如何创建调用特定功能
问题描述:
WordPress的自定义网址,我想对我的WordPress的这样一个自定义的网址为如何创建调用特定功能
http://mywordpress.com/index.php?act=doit
,这将调用一个特定的功能。
这样做的最佳做法是什么?
感谢
答
你可以做这样的事情:
add_action('init', 'init_url_custom_function');
function init_url_custom_function() {
add_rewrite_rule('^YOUR_CUSTOM_URL/?', 'index.php?is_custom_function=yes', 'top');
add_rewrite_tag('%is_custom_function%', '([^&]+)');
}
add_action('wp', 'check_url_custom_function');
function check_url_custom_function() {
global $is_custom_function;
if (isset($is_custom_function) && $is_custom_function == "yes")
custom_function();
}
function custom_function() {
// do something
die();
}
PS:你需要重新生成您的永久链接
+0
完美,这就是我正在寻找..谢谢: –
你需要给为您试图acheive什么更多的信息,显示代码示例等 –