AI DIGEST
AI 摘要
LIVE

这段代码用于在WordPress创建分类目录时,自动将分类别名设置为分类ID。需要将代码添加到主题的functions.php文件中。它通过create_term钩子触发,在创建分类时执行自定义函数。函数会调用wp_update_term将分类的slug参数更新为对应的数字ID。这样可以确保分类别名与ID一致,避免重复或冲突。

WordPress分类目录别名创建时自动添改分类ID优化

此代码放在functions.php文件下

add_action( 'create_term', 'my_custom_term_slug', $priority = 10, $accepted_args = 3 );
function my_custom_term_slug($term_id,$tt_id,$taxonomy){
	wp_update_term( $term_id, $taxonomy, $args = array('slug' => $term_id) );
}

© 版权声明
THE END
文章不错?点个赞呗
点赞8 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容