Why do I get the PHP warning "no suitable wrapper" for file_get_contents in this shortcode? It's probably more a PHP issue than WordPress.

The shortcode works fine and outputs in a page/post. But my error log is filling up with the warnings. I know PHP warnings are not serious, but I still want to fix the code that throws the warning.

// Wikipedia Last Edit Date

function wikipedia_article_date() {

$url = "https://en.wikipedia.org/w/api.php?action=query&titles=Test_article&prop=revisions&rvlimit=1&format=json";

$data = json_decode(file_get_contents($url), true);
$date = $data['query']['pages']['746140638']['revisions'][0]['timestamp'];

$date = new DateTime($date);
return $date->format('m-d-Y'); 


Use the HTTP API:

$http = wp_remote_get( 'https://en.wikipedia.org/w/api.php?action=query&titles=Test_article&prop=revisions&rvlimit=1&format=json' );

if ( ! $body = wp_remote_retrieve_body( $http ) )

if ( ! $data = json_decode( $body, true ) )

$date = new DateTime( $data['query']['pages']['746140638']['revisions'][0]['timestamp'] );

return $date->format( 'm-d-Y' ); 
| improve this answer | |
  • Thanks! Works great, with no need for allow_url_fopen or allow_url_include. – BlueDogRanch Dec 4 '16 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.