当网站的 URL 结构如下所示时,是否可以在 WordPress 中创建自定义 slug:https://www.example.com/post_title?

问题描述 投票:0回答:1

我有一个 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);
wordpress
1个回答
0
投票

在此处输入图像描述我认为您应该在 WordPress 管理中进行设置。 在此输入图片描述

© www.soinside.com 2019 - 2024. All rights reserved.