Created
June 16, 2014 16:11
-
-
Save abhilash0001/703f416d2a351f05e4d9 to your computer and use it in GitHub Desktop.
Wordpress | Blog re-write url
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
/* ========================================================================== | |
If you want to utilize post types for blog and want blog to be | |
under a parent page about Ex: "/about/blog/". | |
Place the code below in your functions.php and change the paths | |
accordingly | |
========================================================================== */ | |
function filter_post_link($permalink, $post) { | |
if ($post->post_type != 'post') | |
return $permalink; | |
return 'about/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( | |
'about/blog/([^/]+)/?$' => 'index.php?name=$matches[1]', | |
'about/blog/[^/]+/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]', | |
'about/blog/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', | |
'about/blog/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', | |
'about/blog/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', | |
'about/blog/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]', | |
'about/blog/([^/]+)/trackback/?$' => 'index.php?name=$matches[1]&tb=1', | |
'about/blog/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?name=$matches[1]&feed=$matches[2]', | |
'about/blog/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?name=$matches[1]&feed=$matches[2]', | |
'about/blog/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?name=$matches[1]&paged=$matches[2]', | |
'about/blog/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?name=$matches[1]&cpage=$matches[2]', | |
'about/blog/([^/]+)(/[0-9]+)?/?$' => 'index.php?name=$matches[1]&page=$matches[2]', | |
'about/blog/[^/]+/([^/]+)/?$' => 'index.php?attachment=$matches[1]', | |
'about/blog/[^/]+/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', | |
'about/blog/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', | |
'about/blog/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', | |
'about/blog/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]', | |
) + $wp_rewrite->rules; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment