Blog Permalinks Dilemma
-
Hello fellow WordPress Folks,
I’ve got a problem.
I’m working on a new website.
The root directory had WP installed.
The “blog” was installed in a sub-directory called site.com/blog
(This is the way it was set up so please don’t scold me)I am now working on combining both into one directory, as one website.
PROBLEM: The old blog permalink
I have not been able to figure out how to get my new blog permalinks to display the following path as on the old website:
site.com/blog/category/interviews/
I have a few categories such as: Weekly Roundup, Quotes, Concepts… plus others…
The permalink I get for all of my blog posts on the new website are:
site.com/post-name
I found a rewrite rule online (code below) that will allow me to insert ‘/blog/’ after my url like:
site.com/blog/
But I get a 404 when I try to get to one of my blog pages like:
site.com/blog/category/interviews/post-name
I am not even remotely skilled with PHP to fix this, and I was fortunate not to bring down my website when I added the rewrite rule to my functions.php file… so I am asking anyone who has the time and the generosity to show me a way to get my blog posts working again like…
site.com/blog/category/interviews/post-name
I would appreciate it so very much… Thanks!
p.s. here is the rewrite code I found online and am currently using.
function add_rewrite_rules( $wp_rewrite ) { $new_rules = array( 'blog/page/(.+?)/?$' => 'index.php?post_type=post&paged='. $wp_rewrite->preg_index(1), 'blog/(.+?)/?$' => 'index.php?post_type=post&name='. $wp_rewrite->preg_index(1), ); $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; } add_action('generate_rewrite_rules', 'add_rewrite_rules'); function change_blog_links($post_link, $id=0){ $post = get_post($id); if( is_object($post) && $post->post_type == 'post'){ return home_url('/blog/'. $post->post_name.'/'); } return $post_link; } add_filter('post_link', 'change_blog_links', 1, 3);
- The topic ‘Blog Permalinks Dilemma’ is closed to new replies.