need to create and return string not echo everything
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 3 Mar 2016 21:47:32 +0000 (16:47 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 3 Mar 2016 21:47:32 +0000 (16:47 -0500)
functions.php

index c547244..748adf3 100644 (file)
@@ -166,29 +166,31 @@ add_action('thematic_searchloop', 'mytheme_search_loop');
 // add shortcode for the landing page blocks
 function landing_page_blocks( $atts )
 {
+    $out = '';
     extract(shortcode_atts(
         array('category' => '-1'), $atts, 'glm-blocks')
     );
     if(function_exists('fetch_all_glm_blocks')):
         $category = filter_var($atts['category'], FILTER_VALIDATE_INT);
         $blocks = fetch_all_glm_blocks($category);
-        echo '<ul id="quick-sub_pages" class="small-block-grid-1 medium-block-grid-3">';
+        $out .= '<ul id="quick-sub_pages" class="small-block-grid-1 medium-block-grid-3">';
         foreach ($blocks as $block):
             $post_image_id = get_post_thumbnail_id($block->ID);
             $thumbnail = wp_get_attachment_image_src( $post_image_id, 'landing_page');
-            echo '<li class="small-text-center medium-text-left landing-item">';
+            $out .= '<li class="small-text-center medium-text-left landing-item">';
             if($block->url):
-                echo '<a href="'.$block->url.'"'.(($block->externalUrl)? ' target="_blank"':'').'>';
+                $out .= '<a href="'.$block->url.'"'.(($block->externalUrl)? ' target="_blank"':'').'>';
             endif;
-            echo '<img src="'.$thumbnail[0].'"/>';
-            echo '<h5>'.$block->post_title.'</h5>';
+            $out .= '<img src="'.$thumbnail[0].'"/>';
+            $out .= '<h5>'.$block->post_title.'</h5>';
             if($block->url):
-                echo '</a>';
+                $out .= '</a>';
             endif;
-            echo '</li>';
+            $out .= '</li>';
         endforeach;
-        echo '</ul>';
+        $out .= '</ul>';
     endif;
+    return $out;
 }
 add_shortcode('glm-blocks', 'landing_page_blocks');
 ?>