[wp-hackers] apply_filters()

Karl Wångstedt maillist at wangstedt.net
Tue May 26 20:00:55 GMT 2009


Hi all

I'm trying to make a function in my parent theme fiterable (is that a  
correct description?) by apply_filters on the return value.

But now it seems like I can only add_filter() to the result if it gets  
echoed from the function. Now I'd like to just return the result for  
use in PHP, but then the add_filter() isn't applied.

Is it so, or am I doing something wrong?

This is what my functions look like (a bit stripped):
// In the parent theme
function KEW_short_excerpt($text = '', $max_length = 100, $preserve =  
'<p>', $replace = '', $replacement = ''){
	// The function

	echo apply_filters('_short_excerpt',$text);
	//return apply_filters('_short_excerpt',$text);
}

// In the child theme
function KEW_add_cat_name_to_short_excerpt($text=''){
	global $post;
	
	$categories = get_the_category($post->ID);
	$name = $categories[0]->cat_name;
		$text = preg_replace('/<p>/','<p><span class="run-in">â–¸ '.$name.'</ 
span>&nbsp;',$text); // KEW_short_excerpt
		
	return $text;

}
add_filter('_short_excerpt','KEW_add_cat_name_to_short_excerpt');

It's the two last rows in the parent theme function that I toggle  
between. The filter gets applied when I use echo, but not if I use  
return.



Thank you
Karl Wångstedt
----------------------------------
         Wångstedt  nova
        www.wangstedt.net

Karl Wångstedt       0278-61 12 33
Stenhuggarvägen 3g   070-578 13 04
821 41  BOLLNÄS
----------------------------------
Det här brevet skickades med en Macintosh från Apple.
Garanterat virusfri med Mac OS X.


More information about the wp-hackers mailing list