實用的 WordPress ICP 備案許可管理器

如何將 WooCommerce 的產品連結改成 ID 數字形式。

對於 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 外掛 :

Product ID Permalink for WooCommerce

兩種方式都是看個人喜好,外掛測試過可用,程式碼也是正常的。

文章沒看懂?程式碼不會用?需要幫助您可以

小新 的頭像