WordPress分类页url链接添加html后缀+移除链接中的 category代码分享

918次阅读
没有评论

今天接到一个任务,wordpress 给分类url加上.html结尾 ,我看了一下,之前没有做过,看来十个挑战,然后果断接下来,半条烟的任务,安排~~

代码版:

function custom_page_rules() {
    global $wp_rewrite;

    $wp_rewrite->page_structure = $wp_rewrite->root . 'page/%pagename%.html';

    $wp_rewrite->extra_permastructs['post_tag']['with_front'] = '';
    $wp_rewrite->extra_permastructs['post_tag']['struct'] = $wp_rewrite->extra_permastructs['post_tag']['with_front'] . 'tag/%post_tag%.html';
    $wp_rewrite->extra_permastructs['category']['with_front'] = false;
    $wp_rewrite->extra_permastructs['category']['struct'] = '%category%.html';
}

add_action('init', 'custom_page_rules');

将下面的代码添加至当前使用的WordPress主题的functions.php中即可。

特别注意:添加代码后,到WordPress后台》设置》固定连接,重新保存一下设置。

如果你设置没有效果,可能跟主题不兼容导致,代码100%有效。可付费联系我们处理。微信:wxmbxzb

插件版:

wp-url-extension

在 WordPress 中为分类添加 .html 后缀可以对 SEO 产生一些影响

众所周知,WordPress的页面默认链接结构通常不带html后缀,有时甚至没有斜杠/。然而,搜索引擎更喜欢包含斜杠/或以html结尾的页面链接。尽管并不是说添加html后缀就会立即提高收录速度,但的确可以加速收录的过程。为了优化网站的搜索引擎排名,我们不能忽视这一点,即使这意味着需要额外的努力。

正文完
 0
评论(没有评论)

觅站网

Posts

Sed cras ornare arcu dui vivamus arcu felis. Cursus euismod quis viverra nibh cras pulvinar mattis nunc.

Melissa Meiers