How To Add Google Trends Graphs To Pages/Posts

11 August, 20130 Comments
1 Flares Twitter 1 Facebook 0 Google+ 0 Pin It Share 0 StumbleUpon 0 1 Flares ×

 

add google trends graph to posts

 

In this post, i’ll tell you how to add Google Trande graph in your  pages and posts.

Google Trends is a public web facility by Google, based on Google Search which shows how often a particular search-term is entered relative to the total search-volume across various regions of the world, and in various languages. The horizontal axis of the main graph represents time (starting from 2004), and the vertical shows how often a term is searched for relative to the total number of searches globally!

Below the main graph, the popularity is broken down by countries, regions, cities and also language. But that what Google calls “language”, however, does not display the relative results of searches in different languages for the same term/terms. It only displays the relative combined search volumes from all the countrieswhich share a particular language.  It is possible to refine the main graph by region and time period.

Paste the following code to the functions.php file.

Also  add a ” + ” between multiple words which are part of a single query.

function wps_trend($atts){
extract( shortcode_atts( array(
'w' => '500',           // width
'h' => '330',           // height
'q' => '',              // query
'geo' => 'US',          // geolocation
), $atts ) );
//format input
$h=(int)$h;
$w=(int)$w;
$q=esc_attr($q);
$geo=esc_attr($geo);
ob_start();
?>
<script type="text/javascript" src="http://www.google.com/trends/embed.js?hl=en-US&q=<?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>
<?php
return ob_get_clean();
}
add_shortcode("trends","wps_trend");

For displaying  the chart, you would need to place within your post the following shortcode :

 [trends h="450" w="500" q="wpsnipp,wordpress,+wordpress+theme,+wordpress+plugin,+wordpress+snippets" geo="US"] 

You can also change the values for the width, height, query and geolocation as by default the geo location is set to United States!!

Thanks to Kevin Chard for the code!

ALSO SEE:

How To Add Sitemap To Footer Of WordPress

How To Automatically Share Your Blog Posts

Filed in: WordPressWordPress Tutorials
Tagged with:

About the Author ()

I am a Computer engineer from New Delhi with interest in blogging and gaming. I am an aspiring full-time blogger and the founder of Konnecting U , where i blog about the latest tech updates along with info on gadgets, android and other "how to" topics. If you like the articles on my blog, then do subscribe to its RSS Feed . You can also connect with me on Twitter or Facebook

Leave a Reply

Back to Top