I wanted to rename "Read more" in teaser (node--blog--teaser.html.twig) to something like "Continue" or anything else.

How can I achieve this?


In your theme open file THEMENAME.theme, example in my case THEMENAME is bartik and file is bartik.theme add code below:

 * Implements hook_preprocess_links().
function bartik_preprocess_links(&$variables) {
    if (isset($variables['links']['node-readmore'])) {
      $variables['links']['node-readmore']['link']['#title'] = t('Read more custom text');

Clear all cache and see result.

About add custom class to readmore link you can check here: Add custom classes to node links

  • Only issue is that you don't have access to the node that the links are for, meaning that you can't change it conditionally based on the node type. – Matt Fletcher Aug 29 '18 at 15:22
  • Another issue would be that Bartik is a core theme. And it actually should be considered a crime changing core files. See Why don't we hack core?. – leymannx Sep 21 '18 at 7:50
  • 1
    @MattFletcher, you can use hook_node_links_alter, which provides the node (to get the content type) and the view mode as context. This hook only works in a module. – 4k4 Sep 21 '18 at 9:00

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.