你不应该在你的短代码中重复任何内容。the_weekday()
函数回显日期。您可以使用输出缓冲或直接获取日期:
输出缓冲:
function custom_shortcode() {
ob_start();
the_weekday();
$week = ob_get_contents();
ob_end_clean();
return \'<img src="/wp-content/themes/coworker/images/daily-social-image-\' . $week . \'.gif" width="100%" />\';
}
add_shortcode( \'weekday\', \'custom_shortcode\' );
或使用全局
$wp_locale
要筛选帖子的日期,请执行以下操作:
通过使用全局变量:
这是原始函数获取其内容的方式:
function custom_shortcode() {
global $wp_locale;
$weekday = $wp_locale->get_weekday( mysql2date( \'w\', get_post()->post_date, false ) );
$week = apply_filters( \'the_weekday\', $weekday );
return \'<img src="/wp-content/themes/coworker/images/daily-social-image-\' . $week . \'.gif" width="100%" />\';
}
add_shortcode( \'weekday\', \'custom_shortcode\' );