How to Add Google Trends Graph in Post/Page via Shortcode

x theme
(Last Updated On: July 10, 2014)

Google Trends is a service provided by Google Inc. This service shows the most searched term, based on Google Search. Google also provides an API to display Google trends in any website. But we’ll implement Google Trends in WordPress by creating a shortcut for Google Trends.

Paste the following code in functions.php. The code will generate a WordPress shortcut for Google Trends to use the shortcut in your post or page.

function wps_trend($atts){
extract( shortcode_atts( array(
'w' => '500', // width
'h' => '330',// height
'q' => '',// query
'geo' => 'UK',// geolocation
), $atts ) );
//format input
<script type="text/javascript" src="<?php echo $q;?>&geo=<?php echo $geo;?>&cmpt=q&content=1&cid=TIMESERIES_GRAPH_0&export=5&w=<?php echo $w;?>&h=<?php echo $h;?>"></script>
return ob_get_clean();

Now use shortcode as:

[trends h="450" w="500" q="wpulti,wordpress,+wordpress+theme,+wordpress+plugin,+wordpress+tutorials" geo="UK"]

About the author


Leave a Reply

Your email address will not be published. Required fields are marked *