Skip to content

Instantly share code, notes, and snippets.

@isuke01
Last active June 28, 2023 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isuke01/f359d4bbf7e59d090ffcdf5bed5fa3f5 to your computer and use it in GitHub Desktop.
Save isuke01/f359d4bbf7e59d090ffcdf5bed5fa3f5 to your computer and use it in GitHub Desktop.
Change wordpress blog poss rewrite rules
<?php
/*
|--------------------------------------------------------------------------
| Fix for blog links
|--------------------------------------------------------------------------
| Add post type before single post name (fix post link on backend)
*/
function fix_blog_links($post_link, $post, $leavename) {
if($post->post_status === 'draft') return $post_link;
// We're adding this rule to only posts, you can ofc maniplutate it as you wish :)
if($post->post_type !== 'post') return $post_link;
$configSlugs = 'blog;
// without %postname% edit permalink will not appear in backend
if($leavename){
return home_url('/'.$post_page_slug.'/%postname%/');
}else{
return home_url('/'.$post_page_slug.'/'.$post->post_name);
}
}
add_filter('post_link', 'fix_blog_links', 1, 3);
@greg-thrive
Copy link

Missing a ' on line 14

Also, this doesn't work for me. Permalink set to /%postname%/

Nothing gets updated/rewritten~

@johnpuddephatt
Copy link

Line 14 should read $post_page_slug = 'blog';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment