admin管理员组

文章数量:1415119

I am trying to insert a post/page into one of my themes files and it won't display shortcodes or PHP.

I have created a page called home in the wordpress admin-paned and inserted into my code the following:

<div id="home_page"> <!-- echos the content from the page "home" id:43 -->
            <?php $home_id = 43;
            $home_page = get_page( $home_id );
            ?>  
            <?php echo $home_page->post_content; ?>
    </div> <!-- end #home_page -->

and non of the shortcodes that I have in the page work. I installed a php in post or page and tried using php and it doesn't work.

when I insert

echo do_shortcode('[youtube_sc url=]');

directly into the code it works.

does anyone know y this happens?

thank you.

I am trying to insert a post/page into one of my themes files and it won't display shortcodes or PHP.

I have created a page called home in the wordpress admin-paned and inserted into my code the following:

<div id="home_page"> <!-- echos the content from the page "home" id:43 -->
            <?php $home_id = 43;
            $home_page = get_page( $home_id );
            ?>  
            <?php echo $home_page->post_content; ?>
    </div> <!-- end #home_page -->

and non of the shortcodes that I have in the page work. I installed a php in post or page and tried using php and it doesn't work.

when I insert

echo do_shortcode('[youtube_sc url=http://www.youtube/watch?v=Db3XGpt6nNU]');

directly into the code it works.

does anyone know y this happens?

thank you.

Share Improve this question edited Aug 24, 2019 at 17:34 Lazar Momcilovic 1831 silver badge6 bronze badges asked Apr 4, 2012 at 14:59 Dvir LevyDvir Levy 1151 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You need to apply the filter the_content e.g.:

<?php echo apply_filters('the_content',$home_page->post_content); ?>

Also, you don't need custom shortcodes for youtube, just put the URL in the content (but not a hyperlink), and it'll be swapped out for a youtube player at runtime. No plugins or extra code needed thanks to oembed.

本文标签: postpage content