Site logo

[Resolved] How to change “Blog” to “Reviews” in Url?

Home Forums Support [Resolved] How to change “Blog” to “Reviews” in Url?

Home Forums Support How to change “Blog” to “Reviews” in Url?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1840341
    Stephen

    My site reviews organizations. Each review is an actual post with user ratings/reviews (in place of comments). How do I change the domain.com/blog/postname to domain.com/reviews/postname? Thanks.

    #1840388
    David
    Staff
    Customer Support

    Hi there,

    what is slug of your Blog page ? Whatever you change that to will be displayed in the URL.

    #1840425
    Stephen

    I assume it’s “blog”. Maybe this is an easy fix, but I’m just returning to wordpress after a hiatus. How do I specify the slug?

    #1840451
    Elvin
    Staff
    Customer Support

    Hi Stephen,

    Are all the posts on your site “reviews”?

    If yes, you can edit the permalink on Admin Dashboard > Settings > Permalinks and set the base permalink to add /reviews/

    Now if only some posts are reviews under the category “Reviews” and you want to change the URL of these reviews posts, you’ll have to go w/ a bit of PHP like this one – https://wordpress.stackexchange.com/questions/276000/post-url-rewriting-for-posts-with-certain-category/276581#276581

    Example:

    function reviews_permalink_post( $permalink, $post, $leavename ) {
        // Get the categories for the post
        $category = get_the_category($post->ID); 
        if (  !empty($category) && $category[0]->cat_name == "Reviews" ) {
            $permalink = trailingslashit( home_url('/reviews/'. $post->post_name . '/' ) );
        }
        return $permalink;
    }
    
    add_filter( 'post_link', 'reviews_permalink_post', 10, 3 );
    
    function reviews_rule($rules)
    {
      $newrules = array();
      $newrules['^reviews/(.*)$'] = 'index.php?name=$matches[1]';
      return $newrules + $rules;
    }
    
    add_filter('rewrite_rules_array','reviews_rule');
    
    function flushRules(){
      global $wp_rewrite;
      $wp_rewrite->flush_rules();
    }
    
    add_filter('init','flushRules'); 
    #1840923
    Stephen

    Thanks.

    All of the posts are reviews, but then split into categories. I see now that if I click on a post, it doesn’t show “blog” in the url. It only shows the category and post name in url. (domain.com/category/post-title)

    So I guess the “blog” portion of url only shows on the main blog page? In that case it’s not necessary to change, as I thought the url for a post would be domain.com/blog/category/post-title.

    #1840946
    David
    Staff
    Customer Support

    Thats correct /blog is only for the blog page.
    If you need to change the permalink structure then its best to use an SEO plugin for that.

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