Shortcodes in related articles

Posted in: Newsmag
Post count: 17

Hello, i use shortcode [year] in my post titles and it works fine, but not in related articles/more from author when list of posts ajax loaded. For example – http://joxi.ru/xAevy9pSYoMpar. How can i fix it?

Shortcode:

if( !is_admin() ) {
	add_filter( 'the_title', function( $title ) {
		return do_shortcode($title);
	} );
}
  • This topic was modified 9 years by doo.
Post count: 17

UPD: Correct shortcode
if( !is_admin() ) {
add_filter( 'the_title', function( $title ) {
return do_shortcode($title);
} );
}

function year_shortcode() {
$year = date('Y');
return $year;
}
add_shortcode('year', 'year_shortcode');

Post count: 6535

Hi

To run shortcodes it’s required ‘the_content’ hook and on modules that hook is not available. Instead you can use directly date('Y') function on module, it should work fine: http://screencast.com/t/WZrWC1wZoAo

Hope this helps!
Thanks!

Viewing 3 posts - 1 through 3 (of 3 total)
The forum ‘Newsmag’ is closed to new topics and replies.