View Full Version : Forcing Function to Return instead of Echo?

08-10-2012, 05:14 AM
I'm trying to add a link to the bottom of my wordpress RSS Feed but my getCustomField('Affiliate Link') function is echoing the value instead of returning it so its appearing at the very top of the post.. how do I get it to return instead?

function modRSS($content) {
global $post;

if ( has_post_thumbnail( $post->ID ) ){
$content = '<div>' . get_the_post_thumbnail( $post->ID, 'full', array( 'style' => 'margin-bottom: 15px;' ) ) . '</div>' . $content;

$content = $content . '<a href="' . getCustomField('Affiliate Link') . '">Peek</a>';

return $content;

add_filter('the_excerpt_rss', 'modRSS');
add_filter('the_content_feed', 'modRSS');

08-10-2012, 05:24 AM
Post the getCustomField() function's source code.

08-10-2012, 12:23 PM
Use output buffering would be a cheap and dirty fix.

08-10-2012, 02:56 PM
Post the getCustomField() function's source code.

not sure where I get the source code from

08-10-2012, 03:01 PM
Use output buffering would be a cheap and dirty fix.

how would that be done?

08-10-2012, 04:35 PM
how would that be done?

function func()
printf("This is a string within %s", __FUNCTION__);
$cont = ob_get_contents();
return $cont;

$s = func();
printf("Calling func resulted in: %s", $s);

If the content is before the capture, this is an indication that a result is printed before the capture. I wouldn't recommend that you actually use output buffering, instead you should track down where it creates the output in the first place.
If you didn't write the code and don't know where to find it, the easiest thing I can think of is to reflect it instead using: ReflectionFunction::export('getCustomField'); and looking where its @@ for its file (required 5.0+). But if you didn't write the function in the first place, you should not change how it's handled. Chances are though, if you have an output based method, there is also a captured one that can be called instead.