Skip to content

Instantly share code, notes, and snippets.

@asadaly111
Created March 5, 2018 14:55
Show Gist options
  • Save asadaly111/a51e00e1b7e94a09471b420335984c8f to your computer and use it in GitHub Desktop.
Save asadaly111/a51e00e1b7e94a09471b420335984c8f to your computer and use it in GitHub Desktop.
ESPN News feed Shortcode in Wordpress - ESPN News feed in Wordpress
//add this is function.php
function cs_shortcode_by_asad(){
$data = file_get_contents('https://newsapi.org/v2/top-headlines?sources=espn&apiKey=d0261b1877794a6085b66c81714f273f');
$data = json_decode($data);
$content = '';
$content .= '<ul class="newsfeedsgoese">';
foreach ($data->articles as $key):
$content .= '<li><a target="_blank" href="'.$key->url.'"><img src="'.$key->urlToImage.'" alt=""><h3>'.$key->title.'</h3></a></li>';
endforeach;
$content .= '</ul>';
return $content;
}
add_shortcode( 'news-feeds-by-dev-team', 'cs_shortcode_by_asad');
//add this shorcode whereever you want to add[news-feeds-by-dev-team]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment