自定义文章的URL重写

add_filter('post_type_link', function ($url, $post) {

  if ('movie' === get_post_type($post)) {
    return home_url('/vod/' . get_the_ID() . '.html');
  }
  return $url;

}, 10, 2);

add_action('init', function () {
  add_rewrite_rule(
    'vod/([0-9]+)?.html$', //带.html后缀
    'index.php?post_type=movie&p=$matches[1]',
    'top');
});
评论
:broken_heart: :confounded: :flushed: :frowning: :grinning: :heart: :kissing_heart: :mask: :pensive: :rage: :relaxed: :scream: :smile: :smirk: :sob: :stuck_out_tongue_closed_eyes: :stuck_out_tongue_winking_eye: :wink: