• Hi there,

    We are looking at reporting for blog posts, and I was wondering if it’s possible to add /blog/ into all of the URLs for the blog posts? Here is an example of our currently blog post URL, [ redundant link deleted ]/at-the-first-sign-of-a-cold/. We want to change to [ redundant link deleted ]/blog/at-the-first-sign-of-a-cold/

    Please advise.

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You can include “/blog” in your permalink settings. It’ll affect all blog posts, but not pages. However, if you have custom post types, it may affect them as well.

    You could instead add the “/blog” via “post_link” filter hook so any desired permalinks have it, except WP will redirect such requests back to the canonical URL that’s without it. But the canonical redirect can be suppressed through the “redirect_canonical” filter.

    Yet another way would be to convert all blog posts to a custom post type which has “blog” as its rewrite rule value (or simply name this post type “blog”). Converting existing posts would involve a custom one time SQL UPDATE query.

    Thread Starter tphamdev12

    (@tphamdev12)

    Thanks for that suggestion. Regarding the last option, how can we do it?

    Moderator bcworkz

    (@bcworkz)

    Please see https://developer.www.ads-software.com/plugins/post-types/registering-custom-post-types/
    I believe there are plugins available that will help you create custom post types if you’re not up for writing your own code.

    I’m not sure about the precise UPDATE query. You want it to change all blog post “post_type” fields from “post” to “blog”. You should make a backup of the posts table before changing anything. I suggest using the phpMyAdmin app to both backup and execute the update.

    This is my best guess at the query:
    UPDATE 'wp_posts' SET 'post_type' = 'blog' WHERE 'post_type' = 'post' LIMIT 2;
    The table and column names should be demarcated with backticks, not quotes as shown here. Backticks used here mess up the formatting. The LIMIT clause is only so you can verify the query is working correctly before turning it loose on the entire table. It can be removed if you’re sure it’s OK. Your actual table prefix might be different than the “wp_” usd here. If you have posts that should not be converted, you’ll need a more elaborate WHERE clause, or manually change them back afterwards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.