对于 WordPress 来说,如果是需要调整文章的固定连接那么可以直接修改,但对于 WooCommerce 来说却没有这个选项,需要进行手动操作。
不是英语语系的用户,也就是比如我们中文用户,输入产品标题后显示的链接就是中文字符,而且又长又杂乱,对 SEO 不是很友好。
将下面的代码添加到已激活主题的 `functions.php` 文件中。
add_filter('post_type_link', 'wpse33551_post_type_link', 1, 3);
function wpse33551_post_type_link( $link, $post = 0 ){
if ( $post->post_type == 'product' ){
return home_url( 'product/' . $post->ID );
} else {
return $link;
}
}
add_action( 'init', 'wpse33551_rewrites_init' );
function wpse33551_rewrites_init(){
add_rewrite_rule(
'product/([0-9]+)?$',
'index.php?post_type=product&p=$matches[1]',
'top' );
}
或者使用 Product ID Permalink for WooCommerce 插件 :
两种方式都是看个人喜好,插件测试过可用,代码也是正常的。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。