WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this twitter share button that pulls 100 characters from the content of the post and its URL for the twitter share.

<a class="popup"
        echo urlencode(get_permalink($post->ID));
    ?>&amp;text=<?php the_content_limit(100, "");?>">
    <img src="http://zitatezumnachdenken.com/wp-content/uploads/2013/04/twittersmall.png" alt="twitter">

It's working but I always get the following validation error Error

Can someone help me?

share|improve this question
up vote 1 down vote accepted

You are sending text unencoded. urlencode that just like you do the permalink.

<a class="popup" href="http://twitter.com/share?url=<?php echo urlencode(get_permalink($post->ID)); ?>&amp;text=<?php echo urlencode(the_content_limit(100, ""));?>"><img src="http://zitatezumnachdenken.com/wp-content/uploads/2013/04/twittersmall.png" alt="twitter"></a>

Although, the_content_limit looks like it probably echos (based on your usage) instead of returning a string, which you will need. So I expect you will have to find that function and alter it or duplicate it or find some other alternative to get a string that you can encode.

share|improve this answer
thanks, I'd upvote you if I had enough reputation. I used <?php $content = get_the_content(); $content = strip_tags($content); echo urlencode(substr($content, 0, 100)); ?>..."> now – nzo Apr 19 '13 at 16:01
@onz FYI: Why use a variable that you don't need at all? You can shorten this a bit like the following: echo urlencode(substr(strip_tags(get_the_content()), 0, 100));. – tfrommen Apr 19 '13 at 16:15
@tf thanks, that will work even better. I don't really have a clue about PHP and I'm just googling and copying code together until it works ;) – nzo Apr 19 '13 at 16:47
@tf is there a way to add "..." if the string is longer than 100 characters? – nzo Apr 19 '13 at 17:51

Regarding your comment:

    $text = strip_tags(get_the_content());
    if (strlen($text) > 100)
        $text = substr($text, 0, 100).'...';
<a class="popup"
        echo urlencode(get_permalink());
    ?>&amp;text=<?php echo urlencode($text); ?>">
    <img src="http://zitatezumnachdenken.com/wp-content/uploads/2013/04/twittersmall.png"
        alt="twitter" />
share|improve this answer
working fine :) – nzo Apr 20 '13 at 11:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.