tags:

views:

295

answers:

3

Hello everyone

I'm trying to tweak a tiny bit a wordpress, but i am level 0 in php, so i kinda suck :/

I want to add a custom 'tweet this' button (i know there already is a gazillion of them, i just wanted to do it on my own, for fun)

So, i'm trying this :

<a href="http://twitter.com/home?status=&lt;?php strip_tags(the_excerpt()) ?>" >tweet this</a>

the_excerpt() returns "<p> ... excerpt ... </p>" and the strip_tags function does not strip those <p> tags !

What do i do wrong ?

Thanks, and sorry if it is obvious.

A: 

You need to echo the result from strip_tags()

<a href="http://twitter.com/home?status=&lt;?php echo strip_tags(the_excerpt()) ?>" >tweet this</a>
Ben Rowe
No, the problem is that `the_excerpt()` does a direct `echo` and the result is never returned to `strip_tags`. Echoing it won't help.
Pekka
+2  A: 

Your problem is that the_excerpt() does not return its contents to strip_tags(), but outputs it directly using echo. So strip_tags() (which would need a preceding echo by the way to do any work) can't do anything.

Use get_the_excerpt() instead (line break inserted for clarity, remove when using):

<a href="http://twitter.com/home?status=
<?php echo strip_tags(get_the_excerpt()); ?>" >tweet this</a>

By the way, I would also urlencode() the excerpt, you're bound to run into trouble otherwise if it contains "double quotes or other funny characters.

Pekka
Ah yes, that wasn't immediately clear from the question. However, given the nightmare that is Wordpress's global scoping and function naming scheme, it becomes obvious in retrospect. :D +1
zombat
Great ! Thank you :)
Maxime ARNSTAMM
A: 

This doesn't look right by common sense: <?php strip_tags(the_excerpt()) ?>, then the WP doc explained, the_excerpt's API doc, it said it echoes instead of returning it. Well, use ob_start to workaround.

ob_start("callback");
the_excerpt();
$excerpt = ob_get_contents();

?>
<a href="http://twitter.com/home?status=&lt;?php echo strip_tags($excerpt) ?>" >tweet this</a>
<?php

Note: I don't have any WordPress API experience.

SHiNKiROU