1

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;?>
  • 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 Mar 28 '15 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 Mar 28 '15 at 15:42
2

You could just

echo do_shortcode( $content );

Function Reference/do shortcode

  • hhhhhhhhh seriously i don't know with which ink did you write your answer but its work although i have tried this 2 times before i don't know why it doesn't work for me before. Thank you. – Carl Willis Mar 28 '15 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.