【问题标题】:How to change specific category slug in wordpress?如何更改 wordpress 中的特定类别 slug?
【发布时间】:2022-12-30 01:50:54
【问题描述】:

对于特定类别的帖子 slug,请在类别名称前添加自定义文本,例如“博客”。像

之前:https://shiphero.com/article/how-to-stay-on-top-of-warehouse-storage-and-organization/ 之后:https://shiphero.com/blog/article/how-to-stay-on-top-of-warehouse-storage-and-organization/

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    add_filter( 'post_link', 'custom_permalink', 'author_link', 10, 3 ); function custom_permalink( $permalink, $post, $leavename ) { $category = get_the_category($post->ID); } if ( !empty($category) && $category[0]->cat_name == "从列表中排除") { $cat_name = strtolower($category[0]->cat_name); $authordata = get_userdata( $post->post_author ); $author = $authordata->user_nicename; $permalink = trailingslashit( home_url('/blog/article/'. $post->post_name .'/' ) ); } 返回$永久链接; }

    【讨论】:

      猜你喜欢
      • 2018-11-15
      • 2019-02-16
      • 2013-02-16
      • 2020-02-15
      • 1970-01-01
      • 1970-01-01
      • 2017-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多