每次更新主題都要對(duì)woocommerce添加固定鏈接!有沒有辦法下次更新主題添加在里面!
- $posttypes = array(
- 'product' => 'product',//Woocommerce產(chǎn)品自定義文章類型
- 'portfolio' => 'portfolio'//作品集自定義文章類型
- );
- add_filter('post_type_link', 'custom_book_link', 1, 3);
- function custom_book_link( $link, $post = 0 ){
- global $posttypes;
- if ( in_array( $post->post_type,array_keys($posttypes) ) ){
- return home_url( $posttypes[$post->post_type].'/' . $post->ID .'.html' );
- } else {
- return $link;
- }
- }
- add_action( 'init', 'custom_book_rewrites_init' );
- function custom_book_rewrites_init(){
- global $posttypes;
- foreach( $posttypes as $k => $v ) {
- add_rewrite_rule(
- $v.'/([0-9]+)?.html$',
- 'index.php?post_type='.$k.'&p=$matches[1]',
- 'top' );
- }
- }