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?

本文标签: