我有一个 WordPress 网站,其帖子的 URL 结构如下:https://www.example.com/post_title,我想创建一个名为“break”的类别,其中该类别中的所有帖子都显示为此 URL 格式:https://www.example.com/breaking/post_title。我尝试过各种插件但遇到了问题。是否可以在functions.php文件中编写一些代码来实现这一点?
当然,之前我写了下面的代码,只改变了URL但不显示页面并返回404错误。
function custom_category_permalink_structure($permalink, $post, $leavename) {
if (in_category('breaking', $post)) {
$permalink = trailingslashit(home_url('/mag/breaking/' . $post->post_name));
}
return $permalink;
}
add_filter('post_link', 'custom_category_permalink_structure', 10, 3);