i just want this code to be added in my functions.php, so that it will directly display after my post ends
currently i am adding this code to my single.php,
but i want to add this is in functions.php, this code is use to fetch all the tweets of the respective account,
the code is here
<?php
function parse_twitter_feed($feed, $prefix, $tweetprefix, $tweetsuffix, $suffix) {
$feed = str_replace("<", "<", $feed);
$feed = str_replace(">", ">", $feed);
$clean = explode("<content type="html">", $feed);
$amount = count($clean) - 1;
echo $prefix;
for ($i = 1; $i <= $amount; $i++) {
$cleaner = explode("</content>", $clean[$i]);
echo $tweetprefix;
echo $cleaner[0];
echo $tweetsuffix;
}
echo $suffix;
}
function the_twitter_feed($username) {
// $username = "Mba_"; // Your twitter username.
$limit = "5"; // Number of tweets to pull in.
/* These prefixes and suffixes will display before and after the entire block of tweets. */
$prefix = ""; // Prefix - some text you want displayed before all your tweets.
$suffix = ""; // Suffix - some text you want displayed after all your tweets.
$tweetprefix = ""; // Tweet Prefix - some text you want displayed before each tweet.
$tweetsuffix = "<br>"; // Tweet Suffix - some text you want displayed after each tweet.
$feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=" . $limit;
$twitterFeed = get_transient($feed);
if (!$twitterFeed) {
$twitterFeed = wp_remote_fopen($feed);
set_transient($feed, $twitterFeed, 3600); // cache for an hour
}
if ($twitterFeed)
parse_feed($twitterFeed, $prefix, $tweetprefix, $tweetsuffix, $suffix);
}
?>
I’m not sure why you don’t just insert the code in the single.php, or use Denis’s solution, but if you want to hook into
the_content
you can do so by putting the following in your functions.php file:This will add directly to the end of
the_content
.You can call your Twitter function above this and it should work. You’d be better off using a theme framework with some custom hooks because hooking into
the_content
in this way can get very buggy very fast depending on what other filters/hooks your theme and plugins are using to modifythe_content
. I don’t know why it happens, I just know that it does.Using FTP, grab your theme’s functions.php, and add the above code within it, minus the leading
<?php
and the trailing?>
, towards the latter file’s end (before the?>
, which terminates php).I’ve edited your function so it can then be used in a template: