Fix the "Read more" link in Drupal 7

Drupal 7 has limitations that can be fairly funny, the "Read more" link always appears in the "Teaser" although the "Teaser" content is already the entire contents of the article, this problem does not exist in Drupal 6.

To fix this I simply use the template.php and make the function as follows:

function template_preprocess_node(&$variables) {

  $node = $variables['node'];
 
  // Check first the "body field" exists or not.
  $field = field_get_items('node', $node, 'body');

  // If available do execution ..  
  if($field){
    $body = $node->body['und'][0]['safe_value'];
    if ($variables['content']['body'][0]['#markup'] == $body){
      unset($variables['content']['links']['node']['#links']['node-readmore']);
    }
  }

  // And if not available ..
  else{
    // Do nothing ..
  }

}

Note: Replace the word template on template_preprocess_node with the name of your theme.

At least this solution can be used for a while and waiting for the problem is fixed in Drupal 7.


Author: danpros

A self-proclaimed geek, business owner, and part-time blogger.

Comments on “Fix the "Read more" link in Drupal 7”