0

I am using this code on D7 for my themes template.php to replace default 'Read More' title with 'Read More →' (it just adds arrow):

function theme_preprocess_node(&$vars){
  $vars['content']['links']['node']['#links']['node-readmore']['title'] = str_replace("Read more","Read more →",$vars['content']['links']['node']['#links']['node-readmore']['title']);
}

It all works, but when clearing cache I get this error message:

Notice: Undefined index: node-readmore in theme_preprocess_node()
2
  • wrap the whole thing in an if(!empty($vars['content']['links']['node']['#links']['node-readmore'])) {...} and it will get rid of the notice. But you should be using theme_more_link(). – beth Jan 30 '13 at 21:44
  • You can always dpm($vars) to see what is being available on the page and then adjust your code from there – pal4life Jun 9 '14 at 22:16
1

Probably the page view of the node not including the read more link.

e.g

function theme_preprocess_node(&$vars){
  if(!$vars['page']){
    $vars['content']['links']['node']['#links']['node-readmore']['title'] = t('Read more →'); 
  }
}

or perhaps

function theme_preprocess_node(&$vars){
  if(isset($vars['content']['links']['node']['#links']['node-readmore'])){
    $vars['content']['links']['node']['#links']['node-readmore']['title'] = t('Read more →'); 
  }
}

No need for the str_replace either if just setting the full text string.

Note, an alternative is to translate that text,

e.g with stringoverrides or in settings.php

$conf['locale_custom_strings_en'][''] = array(
  'Read more'      => 'Read more  →',
  'Old text 2'      => 'New text 2',
);
0

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.