Wordpress - Display content before more tag only if tag is used

Viewed 33

I have no idea how to do this.

In single.php, I need to display content before tag in post BUT only if this tag is used in the post. If poest doesn't have the tag, all solutions I have found display full content of the post...

Expected bahavior is:

<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>

<article class="post">
    <h1 class="title">
        <?php the_title();  ?>
    </h1>
    <?php get_template_part( 'part_post_meta') ?>
    <div class="excerpt">
        <!-- Here I need content before more tag or nothing -->
    </div>
    <div class="feature_image">
        <?php 
            if ( has_post_thumbnail() ) 
            {
                the_post_thumbnail('post-thumbnail', ['class' => 'img-fluid', 'title' => 'Feature image']);
            } 
        ?>
    </div>
    <div class="content">
        <!-- Here I need content after more tag or full content -->
    </div>
</article>

<?php endwhile; ?>
<?php endif; ?>

Does anybode have a solution?

1 Answers

You can check if current post has special tag with has_tag function :

if( has_tag( $tag_id ) ) {
  //place your codes
}
Related