Last active
June 28, 2023 14:27
-
-
Save isuke01/f359d4bbf7e59d090ffcdf5bed5fa3f5 to your computer and use it in GitHub Desktop.
Change wordpress blog poss rewrite rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
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
Missing a ' on line 14
Also, this doesn't work for me. Permalink set to /%postname%/
Nothing gets updated/rewritten~