当您的WordPress固定链接使用/%category%/时,如果您发布嵌套在几个类别中的文章,网址可能会变得太长和混乱。
例如:http://www .* * * * * *.com/wordpress/theme/Zing-pro . html,WordPress是父类别,Theme是子类别。
如果您想从WordPress的链接结构中删除父类别,只需将以下代码粘贴到您正在使用的WordPress主题的functions.php文件中:
add_filter( 'post_link', 'dahuzi_remove_parent_cats_from_link', 10, 3 );
    function dahuzi_remove_parent_cats_from_link( $permalink, $post, $leavename ){
        $cats = get_the_category( $post->ID );
        if ( $cats ) {
            usort( $cats, '_usort_terms_by_ID' );
            $category = $cats[0]->slug;
        if ( $parent = $cats[0]->parent ) {
            $parentcats = get_category_parents( $parent, false, '/', true );
            $permalink = str_replace( $parentcats, '', $permalink );
        }
    }
    return $permalink;
}
 
    		 
            

 
    		 
            	 
             
                     
    	 
    	 
    	 
    	 
         
				 
				![[WordPress网站构建教程]在WordPress文本的顶部或末尾插入固定内容](https://www.zhanceo.com/wp-content/themes/ceomax/timthumb.php?src=http://www.zhanceo.com/wp-content/uploads/2022/01/2022010202125919.jpg&h=200&w=300&zc=1&a=t&q=100&s=1) 
				 
				 
				 
						 
						 
						 
						 
						 
		 
        
 
 
        