Skip to content

Instantly share code, notes, and snippets.

@isuke01
Last active Apr 14, 2021
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@greg-thrive greg-thrive commented Apr 14, 2021

Missing a ' on line 14

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

Nothing gets updated/rewritten~

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