-1

How do I add a class the_content();?

<div class="csoporszoveg">
    <h3 class="csoporcim"><?php
        if ($settings['enable_link']) {
            echo '<a href="' . get_permalink($post) . '">';
        }

        the_title();

        if ($settings['enable_link']) {
            echo '</a>';
        }
        ?>
    </h3>
    <?php } ?>  
      <?php
        if ( $content_source == 'excerpt' ) {
            the_excerpt();
        } else {
            the_content();
        }
      ?> 
</div>
1

You don't. You'll need to put an element around it:

<?php if ( $content_source == 'excerpt' ) { ?>
    <div class="excerpt">
        <?php the_excerpt(); ?>
    </div>
<?php } else { ?>
    <div class="content">
        <?php the_content(); ?>
    </div>
<?php } ?> 
  • Are you trying to use a paragraph? It can't be a paragraph because the_content() will contain paragraphs and you can't nest paragraphs. Use a <div>, or if it's semantically correct, a <section>. – Jacob Peattie Aug 29 '17 at 3:06
0
<?php
        if ( $content_source == 'excerpt' ) {
            the_excerpt();
        } else {
        ?>
            <span class="post_content">the_content();<span>
        <?php
        }
?> 

Target p inside span.post_content

  • That will never work, because you are calling the_content(); outside of the PHP scope. – fuxia Nov 29 '19 at 20:10
-3

Like this:

<p class="description"><?php echo  get_the_content();?></p>
  • What if your content has more than 1 paragraph or needs to display embeds? This is not the proper way to display content. – Howdy_McGee Feb 16 '18 at 16:14

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.