admin管理员组文章数量:1122832
Since my website has a lot of pages with similar slugs, I need to add some code to the WordPress functions.php file to enable parentheses in slugs, for example: example/article/slug_(explanation).
However, when I added the following code, it allowed me to save special slugs but I cannot access them (404 error).
function disable_yada_wiki_slug_sanitization($slug, $raw_slug, $context) {
if ($context === 'save' && isset($_POST['post_type']) && $_POST['post_type'] === 'exp_articles') {
$slug = str_replace(' ', '_', $raw_slug);
}
return $slug;
}
add_filter('sanitize_title', 'disable_exp_articles_slug_sanitization', 10, 3);
In addition, my code have another issue. When I try to access an article with a slug that ends in parentheses, WordPress automatically performs a 301 redirect to an address without the ending parentheses ')'.
For example: example/article/slug_(explanation) => 301 redirect to => example/article/slug_(explanation
How can I modify my code or the WordPress settings to allow parentheses at the end of slugs and prevent this automatic redirect?
本文标签:
版权声明:本文标题:urls - How can I add codes to functions.php in WordPress to allow parentheses in slugs, similar to Wikipedia? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309987a1934216.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论