我的旧网站结构曾经是example.com/wp
。我已经搬到example.com
重定向Wordpress媒体附件页面到根位置
所以现在我正在试图用wp_redirect
重定向301个我所有的媒体附件页面(1500页)是这样的:
example.com/wp/image1 ====> example.com/image1
我用这个钩子
add_action('template_redirect', 'wpsites_attachment_redirect');
function wpsites_attachment_redirect(){
global $post;
if (is_attachment() && isset($post->post_parent) && is_numeric($post->post_parent) && ($post->post_parent != 0)) :
wp_redirect(get_permalink($post->post_parent), 301);
exit();
wp_reset_postdata();
endif;
}
这个想法是让wp_redirect(example.com/>Any attachment link here<, 301);
问题是我有超过1500个附件重定向,这将带我永远。一个钩子会很好。 –
Mrjack @hope这会帮助你 –