0

I am getting an "Undefined variable: output in" error referencing the line: "$content = $content.$output;" in the function below. Any help would be greatly appreciated.

            function ld_advanced_custom_field_in_feed($content) {  
                if(is_feed()) {  
                    $post_id = get_the_ID();  
                    
                    $rssimage = get_field('daily_image');
            
                        if( !empty($rssimage) ): 
                            $imgurl = $rssimage['url'];
                            $imgalt = $rssimage['alt'];
                            $imgtitle = $rssimage['title'];
            
                            $output =  '';
                            $output .= '<daily_vibe_image><img src="';
                            $output .=  $imgurl;
                            $output .= '" alt="';
                            $output .= $imgalt;
                            $output .= '" title="';
                            $output .= $imgtitle;
                            $output .= '</daily_vibe_image>'; 
                        endif; 

                    $content = $content.$output;  
                }  
                return $content;  
                }  
                add_filter('the_content','ld_advanced_custom_field_in_feed');
jimj
  • 11
  • 5
  • 2
    `$rssimage` is obviously empty. You have no default value for `$output` but try to use it anyway. As a result you get this error. – John Conde May 03 '21 at 23:05
  • You're doing the same thing with `$content` by the way. And don't use alternative syntax structures (`if`/`endif`) outside of HTML templates. – miken32 May 03 '21 at 23:15
  • you have to define $output outside the if condition and also set $content = '' in function ld_advanced_custom_field_in_feed($content) so if the values not passed to those two variables then they have blank value instead of undefined values. – nikhil borikar May 04 '21 at 06:56

0 Answers0