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,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Post the getCustomField() function's source code.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Use output buffering would be a cheap and dirty fix.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #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,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 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
    •