Guest User

Untitled

a guest
May 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <?php
  2. /**
  3. * Change permalink structure of the post_type post
  4. */
  5. add_filter('pre_post_link', 'filter_post_link', 10, 2);
  6. function filter_post_link($permalink, $post) {
  7. if ($post->post_type != 'post')
  8. return $permalink;
  9. return 'blog'.$permalink;
  10. }
  11.  
  12. add_action( 'generate_rewrite_rules', 'add_blog_rewrites' );
  13. function add_blog_rewrites( $wp_rewrite ) {
  14. $wp_rewrite->rules = array(
  15. 'blog/([^/]+)/?$' => 'index.php?name=$matches[1]',
  16. 'blog/[^/]+/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]',
  17. 'blog/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1',
  18. 'blog/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
  19. 'blog/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
  20. 'blog/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]',
  21. 'blog/([^/]+)/trackback/?$' => 'index.php?name=$matches[1]&tb=1',
  22. 'blog/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?name=$matches[1]&feed=$matches[2]',
  23. 'blog/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?name=$matches[1]&feed=$matches[2]',
  24. 'blog/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?name=$matches[1]&paged=$matches[2]',
  25. 'blog/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?name=$matches[1]&cpage=$matches[2]',
  26. 'blog/([^/]+)(/[0-9]+)?/?$' => 'index.php?name=$matches[1]&page=$matches[2]',
  27. 'blog/[^/]+/([^/]+)/?$' => 'index.php?attachment=$matches[1]',
  28. 'blog/[^/]+/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1',
  29. 'blog/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
  30. 'blog/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
  31. 'blog/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]',
  32. ) + $wp_rewrite->rules;
  33. }
  34. ?>
Add Comment
Please, Sign In to add comment