Titles As Attributes: The Right Way

I’ve reviewed quite a few Themes, since joining the WordPress Theme Review Team a month ago. There are a few issues that keep popping up, like the wrong use of the the_title() template tag in link attributes. But I’m here to help, so let me show you how you can boost your code quality and make Theme Reviewer happy.

Suppose you’re coding your index.php file and you’re about to link the post title to the post’s single view. You want to add a title attribute to the anchor tag, so visitors have an added value. l If you do it like this, you’re _doing_it_wrong():

<a href="" title="<?php the_title(); ?>"><?php the_title(); ?></a>
<a href="" title="<?php echo esc_attr( the_title() ); ?>"><?php the_title(); ?></a>
<a href="" title="<?php echo esc_attr( get_the_title() ); ?>"><?php the_title(); ?></a>