I am newbie to php, just starting learning it, while working with wordpress.
I want to add html code to a php variable, a anchor tag link actually. First i splitted the text using substr(), and now i want to append a anchor tag at the end of post.
$json['timeline']['date'][$i]['text'] = substr(strip_tags($post->post_content), 0, 400)+"<a href='#'>Read more..</";
Well, I believe this is not the right way. Can anyone please guide me?
Use
.to append strings in PHP. And don’t forget to close that tag:Note an exception is
echo, which allows you to pass it arguments separated by commas:This has a marginal time advantage, but don’t do it because of that (to avoid premature optimisation). In fact, use
.everywhere in case you end up changing thatechoto areturn.And finally, there’s an easier way to add a custom link to an excerpt in WordPress you might want to look at:
http://codex.wordpress.org/Customizing_the_Read_More