Archived topic
How to change "Blog" to "Reviews" in Url?
5 replies · Started by Stephen on June 30, 2021
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.
Hi there,
what is slug of your Blog page ? Whatever you change that to will be displayed in the URL.
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?
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');
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.
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.