Title: Problem with shortcode
Last modified: August 20, 2016

---

# Problem with shortcode

 *  Resolved [LucasMorato](https://wordpress.org/support/users/lucasmorato/)
 * (@lucasmorato)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/problem-with-shortcode/)
 * I got this code to show my thumbnails images and videos on my blog page, but 
   when i try to use to show the thumbs in another page, it dont work.
 * Function to display images and videos thumbs:
 *     ```
       function show_blog_posts() {
       global $post, $posts;
       $first_vid = '';
       ob_start();
       ob_end_clean();
       $output = preg_match_all('/<iframe.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
       $first_vid = $matches [1] [0];
   
       if ($output == '1') {
           echo '<iframe width="100%" height="400" src="';
           echo $first_vid;
           echo '" frameborder="0" allowfullscreen></iframe>';
       } else { ?>
                   <?php the_post_thumbnail('large');?>
   
        <?php }
       ```
   
 * My shortcode
 *     ```
       add_shortcode('recent_blog_posts', 'shortcode_recent_blog_posts');
   
       function shortcode_recent_blog_posts($atts) {
   
               $str = '';
               $args = array( 'numberposts' => 3, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
               $postslist = get_posts( $args );
   
               foreach ($postslist as $post) : setup_postdata($post);
                   $str .= '<div id ="article-section-box2" class="span3">';
                                   $str .= '<div id= "image1" class="image-arcticle">';
                                   $str .= show_blog_posts();
                                   $str .= '</div>';
                                   $str .='<p class="article_text">'.excerpt(18).'</p>';
                                   $str .='</div>';
               endforeach; 
   
               return $str;
       ```
   
 * Is there anything wrong? Thanks

The topic ‘Problem with shortcode’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [LucasMorato](https://wordpress.org/support/users/lucasmorato/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/problem-with-shortcode/)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
