• Is there a way to selectively hide the “Read More” button on a WP blog home page? For instance, even when I have a very short (maybe one-sentence) post, there is still a “Read More” button for it — when there is no more to read.

    I’m not using excerpts, but just inserting a <!–more–> at some point in a longer post.

    For extremely short posts, I’d like to eliminate (or hide) the “Read More” link, but continue using it for most posts.

    Any suggestions?

    Thanks,
    William
    http://www.thepulp.net/yellowedperils/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter wlampkin

    (@wlampkin)

    There has to be a way to do this or a plugin that can.

    Anybody?

    Thread Starter wlampkin

    (@wlampkin)

    Anybody? Bueller? Bueller?

    Hi
    Please can you post the code surrounding the link in PHP and I’ll show you a modification to place there instead

    Thread Starter wlampkin

    (@wlampkin)

    <a href="<?php the_permalink(); ?>" class="readmore"><span><?php esc_html_e('read more','Chameleon'); ?></span></a>

    Is that the code you were asking for?

    count(explode('.',rtrim($str,'.')))
    Will get you the count of sentences in a string

    get_the_content();
    Will get you the content of the post as a variable

    So if you want to pull in a link only when there are two or more sentences in the post, just do this (untested)

    <?php if (count(explode('.',rtrim(get_the_content(),'.'))) > 2) { ?>
       <a href="<?php the_permalink(); ?>" class="readmore">
          <span><?php esc_html_e('read more','Chameleon'); ?></span>
       </a>
    <?php } ?>

    Does this work, and make sense?

    Thread Starter wlampkin

    (@wlampkin)

    Thanks, Aaron. That make sense. So, if I want to have, say, four sentences, I would change the numeral 2 following the > to 4.

    I’ll give it a try. Many thanks!

    That’s correct.
    If you have any problems, let me know and I’ll look into it for you.
    Aaron

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Selectively hide "Read More" button’ is closed to new replies.