Below, you’ll find a detailed guide on how to add the Custom Twitter Feeds (Tweets Widget) Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Custom Twitter Feeds (Tweets Widget) Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Custom Twitter Feeds (Tweets Widget) Plugin and the shortcodes it provides:
"Custom Twitter Feeds (Tweets Widget) is a dynamic WordPress plugin that allows users to display and customize live Twitter feeds on their websites, enhancing user engagement and social media presence."
- [custom-twitter-feed]
Custom Twitter Feeds [custom-twitter-feed] Shortcode
The Custom Twitter Feeds shortcode is a powerful tool that embeds a Twitter feed into a WordPress page. It initializes with ‘ctf_init’ function, enqueues necessary scripts, and handles potential errors. In function ‘ctf_init’, it checks for feed errors and displays a message if found. If no errors, it retrieves the tweets, caches them, and generates the HTML for the feed.
Shortcode: [custom-twitter-feed]
Examples and Usage
Basic example – Display a custom Twitter feed using the default settings
[custom-twitter-feed /]
PHP Function Code
In case you have difficulties debugging what causing issues with [custom-twitter-feed]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'custom-twitter-feed', 'ctf_init' );
Shortcode PHP function:
function ctf_init( $atts, $preview_settings = false ) {
wp_enqueue_script( 'ctf_scripts' );
$twitter_feed = TwitterFeed\CtfFeed::init( $atts, null, 0, array(), 1, $preview_settings);
if ( isset( $twitter_feed->feed_options['feederror'] ) && ! empty( $twitter_feed->feed_options['feederror'] ) ) {
return "<span id='ctf-no-id'>" . sprintf( __( 'No feed found with the ID %1$s. Go to the %2$sAll Feeds page%3$s and select an ID from an existing feed.', 'custom-twitter-feeds' ), esc_html( $twitter_feed->feed_options['feed'] ), '<a href="' . esc_url( admin_url( 'admin.php?page=ctf-feed-builder' ) ) . '">', '</a>' ) . '</span><br /><br />';
} else {
// if there is an error, display the error html, otherwise the feed
if ( ! $twitter_feed->tweet_set || ($twitter_feed->missing_credentials && ! CTF_DOING_SMASH_TWITTER) || ! isset( $twitter_feed->tweet_set[0]['created_at'] ) ) {
if ( ! empty( $twitter_feed->tweet_set['errors'] ) ) {
$twitter_feed->maybeCacheTweets();
} else {
$twitter_feed->maybeCacheTweets(true);
}
$feed_html = '';
$feed_html .= $twitter_feed->getTweetSetHtml();
return $feed_html;
} else {
if ( ! $twitter_feed->feed_options['persistentcache'] ) {
$twitter_feed->maybeCacheTweets();
}
$feed_html = '';
$feed_html .= $twitter_feed->getTweetSetHtml();
return $feed_html;
}
}
}
Code file location:
custom-twitter-feeds/custom-twitter-feeds/custom-twitter-feed.php
Conclusion
Now that you’ve learned how to embed the Custom Twitter Feeds (Tweets Widget) Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply