You should not echo any content in your shortcode. the_weekday()
function echos the date. You can use output buffering or directly get the date:
Output buffering:
function custom_shortcode() {
ob_start();
the_weekday();
$week = ob_get_contents();
ob_end_clean();
return '<img src="https://wordpress.stackexchange.com/wp-content/themes/coworker/images/daily-social-image-" . $week . '.gif" width="100%" />';
}
add_shortcode( 'weekday', 'custom_shortcode' );
Or use the global $wp_locale
to filter the post’s date:
By using globals:
This is the way the original function gets its contents:
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="https://wordpress.stackexchange.com/wp-content/themes/coworker/images/daily-social-image-" . $week . '.gif" width="100%" />';
}
add_shortcode( 'weekday', 'custom_shortcode' );