Function to rewrite blog page slugs and catgo
-
Hi guys,
I have been using the following script to help me out with managing blog slugs without messing categories or permalinks. For example, if I don’t use the script, I get the blog slug to prepend on each URL, like:
- https://www.domain.com/insights/ (blog list page – ok)
- https://www.domain.com/insights/single-post/ (single post – ok)
The above I don’t have issues with. I have issues with the following:
- https://www.domain.com//insights/category/category-1/ (I don’t want blog name on category)
- And other areas as well…
The script below allows me to stop out the blog slug on category pages, etc. It’s working, however, I suddenly cannot change the blog URL in the dashboard. Once it’s published, it’s a done deal. I used to be able to make changes, I’m not sure what changed. Please have a look point me in the right direction or see if you can pick anything up that I can’t pick up.
function sle_slug_posts_add_rewrite_rules( $wp_rewrite ) { $new_rules = [ 'insights/page/([0-9]{1,})/?$' => 'index.php?post_type=post&paged='. $wp_rewrite->preg_index(1), 'insights/(.+?)/?$' => 'index.php?post_type=post&name='. $wp_rewrite->preg_index(1), ]; $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; return $wp_rewrite->rules; } add_action('generate_rewrite_rules', 'sle_slug_posts_add_rewrite_rules'); function sle_slug_posts_change_blog_links($post_link, $id=0) { $post = get_post($id); if( is_object($post) && $post->post_type == 'post'){ return home_url('/insights/'. $post->post_name.'/'); } return $post_link; } add_filter('post_link', 'sle_slug_posts_change_blog_links', 1, 3);
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Function to rewrite blog page slugs and catgo’ is closed to new replies.