Title: Getting Short Code to with get_page function
Last modified: August 19, 2016

---

# Getting Short Code to with get_page function

 *  Resolved [idkdesign](https://wordpress.org/support/users/idkdesign/)
 * (@idkdesign)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/getting-short-code-to-with-get_page-function/)
 * Hello,
 * I created a page called “About Us” that is also used for the home page intro 
   text with post Loop.The reason for this is so the intro content can be edited
   via the WP admin.
 * I used the following code to include it on the home page:
 * <?php
    $page_id = 2; $page_data = get_page( $page_id ); $content = $page_data-
   >post_content; echo $page_data->post_content; ?>
 * Everything works as intended except for the gallery short code:
 * [gallery link="file"]
 * On the “About Us” page it renders the gallery as intended. See
 * [http://leadershipsports.com/wordpress/?page_id=2](http://leadershipsports.com/wordpress/?page_id=2)
 * However on the home page, it does not render the gallery but renders the short
   code text “[gallery link="file"]” See
 * [http://leadershipsports.com/wordpress/](http://leadershipsports.com/wordpress/)
 * Any suggestions on how to get WP to render it properly in the home page?
 * Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/getting-short-code-to-with-get_page-function/#post-1461222)
 * It’s because you’re using $page_data->post_content which is the raw, unfiltered
   page content. You might be better off using [get_posts()](http://codex.wordpress.org/Function_Reference/get_posts)
   to grab the page data and then using the_content().
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/getting-short-code-to-with-get_page-function/#post-1461223)
 * What about apply_filters to that–see [http://codex.wordpress.org/Template_Tags/the_content#Alternative_Usage](http://codex.wordpress.org/Template_Tags/the_content#Alternative_Usage)
 *  Thread Starter [idkdesign](https://wordpress.org/support/users/idkdesign/)
 * (@idkdesign)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/getting-short-code-to-with-get_page-function/#post-1461281)
 * Not sure if I am doing it right but would the code be:
 * <?php get_posts(‘2’);
    $content = apply_filters(‘the_content’, $content); $content
   = str_replace(‘]]>’, ‘]]>’, $content); echo $content; ?>
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/getting-short-code-to-with-get_page-function/#post-1461283)
 * Version of what esmi recommended…
 *     ```
       <?php
       $args=array(
         'page_id' => 2,
         'post_type' => 'page',
         'post_status' => 'publish',
         'posts_per_page' => 1,
         'caller_get_posts'=> 1
       );
       $my_query = null;
       $my_query = new WP_Query($args);
       if( $my_query->have_posts() ) {
         while ($my_query->have_posts()) : $my_query->the_post(); ?>
           <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
           <?php
           the_content();
         endwhile;
       }
       wp_reset_query();  // Restore global post data stomped by the_post().
       ?>
       ```
   
 *  Thread Starter [idkdesign](https://wordpress.org/support/users/idkdesign/)
 * (@idkdesign)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/getting-short-code-to-with-get_page-function/#post-1461290)
 * Thanks Michael! That did the trick.
 *  [Jack Reichert](https://wordpress.org/support/users/jackreichert/)
 * (@jackreichert)
 * [16 years ago](https://wordpress.org/support/topic/getting-short-code-to-with-get_page-function/#post-1461607)
 * You can also use the do_shortcode() function
 * [http://codex.wordpress.org/Function_Reference/do_shortcode](http://codex.wordpress.org/Function_Reference/do_shortcode)
 *  [radiofranky](https://wordpress.org/support/users/radiofranky/)
 * (@radiofranky)
 * [16 years ago](https://wordpress.org/support/topic/getting-short-code-to-with-get_page-function/#post-1461621)
 * I was wondering how do you limiting the page to display?
    also, limiting display
   no child or grandchild?
 * thanks
 *  [radiofranky](https://wordpress.org/support/users/radiofranky/)
 * (@radiofranky)
 * [16 years ago](https://wordpress.org/support/topic/getting-short-code-to-with-get_page-function/#post-1461622)
 *  [maxemil](https://wordpress.org/support/users/maxemil/)
 * (@maxemil)
 * [16 years ago](https://wordpress.org/support/topic/getting-short-code-to-with-get_page-function/#post-1461623)
 * Thanks for this snippet!
 * Im using it to generate content inside a sub-page list, like
 *     ```
       <?php
       $pages = get_pages('child_of='.$post->ID.'&parent='.$post->ID); $count = 0;
       foreach($pages as $page)
       {
         // the above code
       };
       ```
   
 * After having tried other fancy “list subpages” variations, this seems to be the
   right one.
    Previously I had a filter around the_content, which dident leave 
   me any meta data inside the_content(); In return shortcodes could run, but if
   I did a the_title in the shortcode enabled function, it would return the parent
   title.
 * The MichaelH written piece works a charm 🙂

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Getting Short Code to with get_page function’ is closed to new replies.

## Tags

 * [gallery](https://wordpress.org/support/topic-tag/gallery/)
 * [Short Code](https://wordpress.org/support/topic-tag/short-code/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 9 replies
 * 6 participants
 * Last reply from: [maxemil](https://wordpress.org/support/users/maxemil/)
 * Last activity: [16 years ago](https://wordpress.org/support/topic/getting-short-code-to-with-get_page-function/#post-1461623)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
