我需要在插件激活后将永久链接设置为不同于默认值 我使用 get_option('permalink_structure') 检查永久链接是否已经设置...
这里是插件激活函数使用的代码块,我用的是类结构
if (get_option('permalink_structure'))
{
$this->setRewriteRules();
global $wp_rewrite;
$wp_rewrite->flush_rules(true);
}
这是 serRewriteRules 函数
function setRewriteRules()
{
add_rewrite_rule('plugin-url/$', '/wp-content/plugins/my-plugin/page.php', 'top');
}
我搜索了很多次并更新了我的代码很多次,但仍然不适合我....
最佳答案
您可以使用 WP 永久链接功能生成链接,而不是动态更改永久链接
例如
get_the_permalink()
the_permalink()
get_post_type_archive_link()
关于php - 如果在插件激活时未设置,则更新永久链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20040677/