admin管理员组

文章数量:1429567

I created a custom post type, but when I add a shortcode for a slider, it doesn't show the slider it shows just the shortcode in text.

And, when I change get_the_content by the_content, it shows me just a little text like excerpt.

 <?php if ( have_posts() ) : the_post(); ?>
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <header class="singleheader">
        <div class="singlettlpart">
            <h1 class="singlettl"><?php the_title(); ?></h1>
            <?php $post_id = get_the_ID();
            $hotel_data = get_post_meta( $post_id, '_hotel', true );
            $adr = ( empty( $hotel_data['adr'] ) ) ? 'Aucune adresse trouvée' : $hotel_data['adr'];
            echo $adr; ?> <a href="#carte" class="cartelnk">(voir la carte)</a>
        </div>
        <div class="prxpart">
            <h1 class="prxttl">À partir de <br />
                <?php 
                $prx = ( empty( $hotel_data['prx'] ) ) ? '???' : $hotel_data['prx'];
                echo $prx; ?> € / NUIT
            </h1>
        </div>
        </header><a id="pres"></a>
        <div class="singletxt">
            <?php 
                $content = get_the_content();
                echo $content; ?>
                <a id="pho"></a>
                <a id="chm"></a>
                <a id="cprx"></a>
        </div>
    <?php else :
    echo 'Pas de hotels pour l\'instant';
endif;?>

I created a custom post type, but when I add a shortcode for a slider, it doesn't show the slider it shows just the shortcode in text.

And, when I change get_the_content by the_content, it shows me just a little text like excerpt.

 <?php if ( have_posts() ) : the_post(); ?>
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <header class="singleheader">
        <div class="singlettlpart">
            <h1 class="singlettl"><?php the_title(); ?></h1>
            <?php $post_id = get_the_ID();
            $hotel_data = get_post_meta( $post_id, '_hotel', true );
            $adr = ( empty( $hotel_data['adr'] ) ) ? 'Aucune adresse trouvée' : $hotel_data['adr'];
            echo $adr; ?> <a href="#carte" class="cartelnk">(voir la carte)</a>
        </div>
        <div class="prxpart">
            <h1 class="prxttl">À partir de <br />
                <?php 
                $prx = ( empty( $hotel_data['prx'] ) ) ? '???' : $hotel_data['prx'];
                echo $prx; ?> € / NUIT
            </h1>
        </div>
        </header><a id="pres"></a>
        <div class="singletxt">
            <?php 
                $content = get_the_content();
                echo $content; ?>
                <a id="pho"></a>
                <a id="chm"></a>
                <a id="cprx"></a>
        </div>
    <?php else :
    echo 'Pas de hotels pour l\'instant';
endif;?>
Share Improve this question edited Jun 10, 2019 at 17:27 RyanS 1256 bronze badges asked Mar 28, 2015 at 15:14 Carl WillisCarl Willis 3051 gold badge2 silver badges11 bronze badges 2
  • so you're saying using the_content doesn't render shortcodes? shortcodes not working with get_the_content is expected, as is noted in the documentation for that function. – Milo Commented Mar 28, 2015 at 15:35
  • oh ok so with get_the_content i can't make shortcode work. but when i use the_content it shows just a little of text like excerpt, i don't know why. – Carl Willis Commented Mar 28, 2015 at 15:42
Add a comment  | 

1 Answer 1

Reset to default 2

You could just

echo do_shortcode( $content );

Function Reference/do shortcode

本文标签: Shortcode doesn39t display in custom post type