2

I have just set up a new website with Drupal 8. I created a new content with a regular HTML that contains basic text. I promoted it to homepage, I see a "read more" link. But there is no "more" to read.

How can I remove "Read more" link if there is no more content to read?

I found some modules for Drupal 7 but I am following a certain solution for this general problem.

And also I am curious; isn't it obvious that there shouldn't be a "read more" link when there is no more content? Is it a bug or something?

3
  • 1
    I do not believe it is a bug. I think the read more link is just a regular link, Drupal assumes that your content will not be that short. I don't think there is a way unless you use a contrib or custom module.
    – No Sssweat
    Commented Oct 27, 2016 at 13:31
  • 3
    You could change in the view "Frontpage", how the content is displayed from teaser to full content, because the "Read more" link is only put in teasers.
    – 4uk4
    Commented Oct 27, 2016 at 14:31
  • When you promote something to the front page in the form of a teaser, it's going to output the read more, as it's in teaser format and expects you to have full output of that content somewhere.
    – DMAC
    Commented Oct 27, 2016 at 14:57

4 Answers 4

2

Neither of the other answers actually addresses the question, which is how to turn off "read more" selectively depending on whether there is more to read or not.

The standard read more link, as the comments in NodeViewBuilder say, is always displayed on a teaser by default because there is no (easy) way to know how the teaser content differs from the full view. Your content type might have several other text fields apart from the body which are only shown on the full page view.

However, it should be possible to implement a custom "read more" link that has the behaviour you seem to be asking for. I don't think anyone has implemented one yet, but the most fruitful approach would be a modest extension of the "summary or trimmed" field formatter, although you could probably also do something in a preprocess hook in your theme.

Edit: A demonstration module is up on github now. It's not perfect and I would like to refactor it and possibly make it more general-purpose but it works for the simplest case.

0
1

Well, in Drupal 8 it is quite simple to remove "Read more" link for some content type. In this example I took "Article" type.

Just navigate to "Structure" > "Content types" in "OPERATIONS" column select "Manage display" for type you need to hide "Read more" link. Note which dispay type you are editing (Default, RSS, Teaser)...

So your URL will look like: /admin/structure/types/manage/article/display/teaser and from there drag "Links" row to "Disabled" area.

Clear cache. Done.

3
  • Works as expected. Who downvoted for no reason?! Commented Sep 5, 2019 at 10:06
  • This is a good answer but this also removes the comment link, not just the "read more" link. It would be nice if there was a way to remove only the "read more"... but this was a huge step forward for me, thanks! Commented Aug 9, 2022 at 19:34
  • Also removes the number of 'views'
    – Daniel
    Commented Oct 27, 2023 at 0:32
0

To remove the 'Read more' on Drupal 8 click on the following:-

Strucure, Views, Frontpage - edit, change 'Teaser' on dropdown to 'Default'.

Click 'save' = Job done :)

Please note there is no 'Read more module' in Drupal 8 as yet. Drupal 7 has one.

1
  • yes copying a teaser view and calling it something else seems like a good answer, however it is not conditional on the length of the content.
    – Daniel
    Commented Oct 27, 2023 at 1:22
0

In Drupal X there is now a readmore flag in the node.html.twig template e.g.

 * - readmore: Flag for more state. Will be true if the teaser content of the
 *   node cannot hold the main body content.

It still appears to be output by default for the teaser as Alfred Armstrong mentioned. e.g.

/**
   * Build the default links (Read more) for a node.
   *
   * @param \Drupal\node\NodeInterface $entity
   *   The node object.
   * @param string $view_mode
   *   A view mode identifier.
   *
   * @return array
   *   An array that can be processed by drupal_pre_render_links().
   */
  protected static function buildLinks(NodeInterface $entity, $view_mode) {
    $links = [];

    // Always display a read more link on teasers because we have no way
    // to know when a teaser view is different than a full view.
    if ($view_mode == 'teaser') {
      $node_title_stripped = strip_tags($entity->label());
      $links['node-readmore'] = [
        'title' => t('Read more<span class="visually-hidden"> about @title</span>', [
          '@title' => $node_title_stripped,
        ]),
        'url' => $entity->toUrl(),
        'language' => $entity->language(),
        'attributes' => [
          'rel' => 'tag',
          'title' => $node_title_stripped,
        ],
      ];
    }

    return [
      '#theme' => 'links__node__node',
      '#links' => $links,
      '#attributes' => ['class' => ['links', 'inline']],
    ];
  }

Appears to be output as part of {{ content }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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