SyndeoLabs

innovation recreation.

Appending the title of the post in Read More links for Wordpress

One of the guidelines in usability is that you should provide only one way that will lead them to a certain action. For example, if someone sees 2 option buttons, chances are that they might think that each option button does separate tasks when in fact their functions are the same. Also, we have to make sure that the links are descriptive enough and if not, then we should provide a title for the link so when a user hovers over it then they’ll know where the link will take them.

On a similar note, accessibility advocates encourages people to use unique name for every link that we use on a page (kinda like what I was saying before only have a different reason), meaning countless “Read more of this entry” is not really the best practice because you’re using the same text over and over and these texts are leading the user to different pages.

I was looking for a way to add that in <?php the_content(); ?> tag in wordpress before but I couldn’t do it. What I did then was append the the_title(); within the_content(); so it looked like this –

<?php the_content('Read more of ' . the_title() . ' & raquo;' ?>

The problem though is that it does echo the “Read more of” but the title is no where in sight! I was so ready to find a way to make it show by hacking away through function.php, thankfully I remembered to check the_content page in the codex first.

What I should’ve done in the first place is to add parameters to the the_title() tag so it will show like this –

<?php the_content('Read more of ' . the_title('', '', false)) ?>

This follows the same parameter as the the_title(); template tag.

Parameters

before
(string) Text to place before the title. Defaults to ”.

after
(string) Text to place after the title. Defaults to ”.

display
(Boolean) Display the title (TRUE) or return it for use in PHP (FALSE). Defaults to TRUE.

So you may use it like this:

<?php the_content('Read more of ' . the_title('&ldquo ;', '&rdquo ; &raquo ;', false)) ?>

So it will echo as Read more of “Title of the Post” ».

If you’re reading this feed from another site other than Tech Hive then this content is scraped.

blog comments powered by Disqus

syndeo::media syndeo::media is a social software lab operating out of Manila, Philippines and Sydney, Australia