Make the_title work inside a filter
-
I was trying to implement Google event tracking (analytics.js) in a filter that alters the WP default next_post_link.
Filter looks like this:
function custom_next_post_link($link) {
add_filter(‘next_post_link’, ‘custom_next_post_link’);
function custom_next_post_link($link) {
$link = str_replace(‘rel=’, “onclick=\”ga(‘send’, ‘event’, ‘EventCategory’, ‘EventActionType’, ‘EventLabel’)\” rel=”, $link);
return $link;
}Problem is that if I replace label with <?php the_title(); ?> it won’t display the post title.
Any idea why and how to work around this? Thanks in advance for ideas.
- The topic ‘Make the_title work inside a filter’ is closed to new replies.