需要重定向到新结构/%年%/%月%/%日%/%category%/%postname%
看到了以前有用但似乎找不到的代码。更新了主题并丢失了进入函数的代码。php。备份最佳做法非常重要!
UPDATE: 再次找到代码!这是第一次发布@Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
add_filter( \'404_template\', \'t5_redirect_to_category\' );
function t5_redirect_to_category( $template )
{
if ( ! is_404() )
return $template;
global $wp_rewrite, $wp_query;
// change \'yourpermalink\' to your new permalink structure
// my new structure is \'/%year%/%monthnum%/%day%/%category%/%postname%\'
if ( \'yourpermalink\' !== $wp_rewrite->permalink_structure )
return $template;
if ( ! $post = get_page_by_path( $wp_query->query[\'category_name\'], OBJECT, \'post\' ) )
return $template;
$permalink = get_permalink( $post->ID );
wp_redirect( $permalink, 301 );
exit;
}
将此代码粘贴到函数中。php使用主题编辑器。代码可以重定向由于更改而当前以404返回的所有新permalink配置。
Remember to save this code because every time you update the theme it will be removed and you will need to add it to functions.php again.
这真的救了我。谢谢https://wordpress.stackexchange.com/users/73/fuxia!