Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-10-2012, 04:14 AM   PM User | #1
efhx
New Coder

 
Join Date: Apr 2006
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
efhx is an unknown quantity at this point
Forcing Function to Return instead of Echo?

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?

PHP Code:
    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'); 

Last edited by efhx; 08-10-2012 at 04:17 AM..
efhx is offline   Reply With Quote
Old 08-10-2012, 04:24 AM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Post the getCustomField() function's source code.
Inigoesdr is offline   Reply With Quote
Old 08-10-2012, 11:23 AM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,513
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Use output buffering would be a cheap and dirty fix.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 08-10-2012, 01:56 PM   PM User | #4
efhx
New Coder

 
Join Date: Apr 2006
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
efhx is an unknown quantity at this point
Quote:
Originally Posted by Inigoesdr View Post
Post the getCustomField() function's source code.
not sure where I get the source code from
efhx is offline   Reply With Quote
Old 08-10-2012, 02:01 PM   PM User | #5
efhx
New Coder

 
Join Date: Apr 2006
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
efhx is an unknown quantity at this point
Quote:
Originally Posted by tangoforce View Post
Use output buffering would be a cheap and dirty fix.
how would that be done?
efhx is offline   Reply With Quote
Old 08-10-2012, 03:35 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by efhx View Post
how would that be done?
PHP Code:
function func()
{
    
ob_start();
    
printf("This is a string within %s"__FUNCTION__);
    
$cont ob_get_contents();
    
ob_end_clean();
    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.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:26 AM.


Advertisement
Log in to turn off these ads.