Home / functions.php / Shortcode to embed google trends graph in posts and pages
  • Shortcode to embed google trends graph in posts and pages


    This Google trends shortcode will embed a graph of any comma separated query you enter to display a trend over time. Make sure to add a + between multiple words that are part of a single query. By default the geolocation is set to United States so change geo praram for another location.

    wordpress snippet : PHP - functions.php

    function wps_trend($atts){
            extract( shortcode_atts( array(
                    'w' => '500',           // width
                    'h' => '330',           // height
                    'q' => '',              // query
                    'geo' => 'US',          // geolocation
            ), $atts ) );
            //format input
    <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>
    return ob_get_clean();

    wordpress snippet : SHORTCODE

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

    ( WordPress codex functions, hooks, in this snippet. )

    query, add_shortcode, shortcode_atts, esc_attr, wp,

Build a better with wpsnipp.com

Weekly snippets, themes, deals coupons roundup.

x No Thanks