Change the output of something using Add_filter in WordPress

I am using Tim Whitlock’s Latest Tweets plugin to display tweets.

I would like to modify the plugin’s default output. I have found the below in line 137 of the plugin file:

Read More
$final = apply_filters('latest_tweets_render_tweet', $html, $date, $link, $tweet );
            if( $final === $html ){
                $final = '<p class="tweet-text">'.$html.'</p>'.
                         '<p class="tweet-details"><a href="'.$link.'" target="_blank">'.$date.'</a></p>';
            }
            $rendered[] = $final;

And have come up with this filter to attempt to change the output:

add_filter('latest_tweets_render_tweet', 'modified_tweets', 10);

function modified_tweets( $html, $date, $link, $tweet ) {

$final = '<div class="col-sm-4">'.
         '<p class="tweet-text2">'.$html.'</p>'.
         '<p class="tweet-details"><a href="'.$link.'" target="_blank">'.$date.'</a></p>'.
         '</div>';

         $rendered[] = $final;

};

However, the output remains the same. Any ideas what I’m doing wrong?

Related posts

Leave a Reply

2 comments

  1. As DWX mentioned, you’re missing the return. But you don’t need to return an array, the original code is expecting a string:

    $my_final = '<div class="col-sm-4">'. $etcetera;
    return $my_final;
    

    And also add the number of arguments after the priority when adding the filter:

    add_filter('latest_tweets_render_tweet', 'modified_tweets', 10, 4);