简体   繁体   English

为什么我的动作钩在function.php上不能执行?

[英]Why my action hook on function.php not excute?

I have a action hook on function.php in order to redirect url based on current day. 我在function.php上有一个动作挂钩,以便根据当前日期重定向url。 Please see my code below. 请在下面查看我的代码。 I tried with init hook/after_theme_setup hook but this code not execute. 我尝试使用init hook / after_theme_setup hook,但是此代码无法执行。 Please give me reason for this error. 请给我这个错误的原因。

<?php


function load_category_by_day(){
if( is_home() && ! is_front_page() ){
$current_day = strtolower( date('N') ); // 'monday', 'sunday', etc.

wp_safe_redirect( site_url( "/category/$current_day/" ) ); 
}
} 
add_action( 'init', 'load_category_by_day' );
?>

Try this: 尝试这个:

function load_category_by_day(){

if( is_home() && ! is_front_page() ){
$current_day = strtolower( date('N') ); // 'monday', 'sunday', etc.

wp_safe_redirect( site_url( "/category/$current_day/" ) ); 

exit;
}
} 
add_action( 'template_redirect', 'load_category_by_day' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM