Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Post the getCustomField() function's source code.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Use output buffering would be a cheap and dirty fix.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #4
    New Coder
    Join Date
    Apr 2006
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Inigoesdr View Post
    Post the getCustomField() function's source code.
    not sure where I get the source code from

  • #5
    New Coder
    Join Date
    Apr 2006
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    Use output buffering would be a cheap and dirty fix.
    how would that be done?

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •