• 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);
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hey Torahboy,

    Firstly, It’ll help you if you can leave the site URL here.
    Secondly, I don’t think you should use any rewrite rules to solve this.
    I believe you’ve exported the posts from the second blog and have imported them in the new one. You can follow these steps:

    1. Create a new page – Give it the title Blog.
    2. Give it a page template – Probably called “Blog template or something similar” (I hope your theme allows this)
    3. Publish this page – without adding any content.
    4. Go to Settings->Reading
    5. Specify the homepage & blog page.

    Save it.

    Hopefully this should solve your problem.

    Regards,
    Mayank

    Thread Starter Kevin

    (@torahboy)

    Hey mayankgupta,

    I really appreciate the time you took to answer my post.

    Your steps above gave me the following:

    site.com/blog/post-name

    but not the category of the post

    site.com/blog/category/interviews/post-name

    I can’t list the site URL because it is someone else’s membership site in staging.

    ok, that’s good.
    now you should go to Settings->Permalinks
    Select custom option and put this in the input box /%category%/%postname%/
    this should solve the issue ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Blog Permalinks Dilemma’ is closed to new replies.