Help please with the correct syntax for this permalink..?

Hi Guys,

I’m sure this is only a quick one for someone clued up on php coding, but no matter what I try, I cannot get it to work ! I have the following php code in my theme functions.php code sheet;

[php] echo " <a href=’"; the_permalink();

  echo "'>"."...Read More On ";

  the_title_shorten(45,'...');

  echo "</a>";[/php]

I know that this creates a link to the full article from an excerpt on the home page, but the problem is, it is including the words “Read More On” in the hyperlink, which I feel is not good from a SEO point of view !
Therefore I would be very grateful if someone could show me how to rewrite this piece of code so that the “Read More On” would come before the hyperlink & not be included in it.

Cheers Guys

It may sound obvious and you may already have done it but make sure that it is all inside of <?php ?> tags.

I am making the assumption that your ‘the_permalink()’ function actually returns something, so for the first line I see you have a semicolon seperating the echo command to the second function. Semicolon denotes the end of a ‘command’ and thus the end of the echo statement, so the following ‘the_permalink()’ function is probably not being included in the output string. Use a period (aka full stop) to join the echo string text and the function together.

On the second line you are using a period to join a string of text to another sting of text ("’>"."…Read More On "), you can remove that, and looking at the 3rd line, I suspect that you may wish it to be joined to the second, so you can use a period here instead and they will join all the way up to the semicolon in spite of the fact that they are on different lines.

this may work better:

<?php
echo "&nbsp;<a href='" . the_permalink();

echo "'>...Read More On " .

the_title_shorten(45,'...');

echo "</a>";

?>

if so, you may want to join it all together so it looks like this:

<?php

echo "&nbsp;<a href='" . the_permalink() . "'>...Read More On " . the_title_shorten(45,'...') . "</a>";

?>

Hi Nasty, thanks for the response, but I don’t think I explained it very well as you seem to have missed my point !
The code I posted does work in as far as it does create this;
Read More On Penn 114 Senator Big Game 6/0 Reel”.
This is how it was originally set up in my Wordpress theme & although it does provide a working link to the full article, I felt that it was less than optimal for SEO.

So what I wanted to create was this;
“Read More On Penn 114 Senator Big Game 6/0 Reel

In effect only wrapping the title in the hyperlink & not the “Read More On”, as it was originally doing.

Anyway I have it all sorted and working correctly now thanks

Sponsor our Newsletter | Privacy Policy | Terms of Service