Last active
May 11, 2017 09:41
-
-
Save vovadocent/dc6a657dda08772f959741581f5903c1 to your computer and use it in GitHub Desktop.
Add "blog" (or other uri segment) only for post_type = "post" permalink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* add /blog segment to blog posts permalinks */ | |
function filter_post_link($permalink, $post) { | |
if ($post->post_type != 'post') | |
return $permalink; | |
return 'blog'.$permalink; | |
} | |
add_filter('pre_post_link', 'filter_post_link', 10, 2); | |
add_action( 'generate_rewrite_rules', 'add_blog_rewrites' ); | |
function add_blog_rewrites( $wp_rewrite ) { | |
$wp_rewrite->rules = array( | |
'blog/([^/]+)/?$' => 'index.php?name=$matches[1]', | |
'blog/[^/]+/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]', | |
'blog/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', | |
'blog/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', | |
'blog/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', | |
'blog/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]', | |
'blog/([^/]+)/trackback/?$' => 'index.php?name=$matches[1]&tb=1', | |
'blog/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?name=$matches[1]&feed=$matches[2]', | |
'blog/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?name=$matches[1]&feed=$matches[2]', | |
'blog/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?name=$matches[1]&paged=$matches[2]', | |
'blog/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?name=$matches[1]&cpage=$matches[2]', | |
'blog/([^/]+)(/[0-9]+)?/?$' => 'index.php?name=$matches[1]&page=$matches[2]', | |
'blog/[^/]+/([^/]+)/?$' => 'index.php?attachment=$matches[1]', | |
'blog/[^/]+/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', | |
'blog/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', | |
'blog/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', | |
'blog/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]', | |
) + $wp_rewrite->rules; | |
} | |
/* end add /blog segment to blog posts permalinks */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment