我这里也有同样的问题,我只是尝试一下
add_action( \'init\', \'my_function_name\'); or add_action( \'wp_head\', \'my_function_name\'); but it\'s not working
最后,我得到了一个可以完美重定向的钩子,下面是我的完整代码
functions.phpfunction redirect_homepage(){
ob_clean();
ob_start();
$args = array(
\'public\' => true,
\'_builtin\' => false,
);
$output = \'names\'; // names or objects, note names is the default
$operator = \'and\'; // \'and\' or \'or\'
$post_types = get_post_types( $args, $output, $operator );
if(is_singular($post_types)){
$url = get_bloginfo(\'url\');
wp_redirect($url, \'301\');
exit();
}
}
add_action( \'template_redirect\', \'redirect_homepage\');
使用挂钩即可
add_action( \'template_redirect\', \'my_function_name\');Nb: i use child-theme