1

How I can add a class="" to anchor on the "read more" links of a node. Im use a bootstrap theme and i need add de btn-default class to anchors, thanks

<ul class="links list-inline"> <li class="node-readmore first last"> <<<<<<<< SET A CLASS IN THIS ANCHOR ? >>>>>>>>>> <a title="Noticia 2" rel="tag" href="/jnd/node/13"> Read more <span class="element-invisible"> sobre Noticia 2</span> </a> </li>
</ul>

1 Answer 1

0

Add template.php file to your theme directory if it doesn't exist. Then, add template_preprocess_node() to it like so, replacing template with your theme name.

function template_preprocess_node(&$variables) {

  $variables['links']['node']['#links']['node-readmore']['attributes']['class'][] = 'btn-default';
}
5
  • Thanks for the prompt reply but I is not working
    – Marco.M
    Commented May 9, 2014 at 5:00
  • Im use drupal 7 and drupal bootstrap 3
    – Marco.M
    Commented May 9, 2014 at 13:56
  • Did you clear the cache once you added the function? What is the name of your bootstrap subtheme?
    – Jason
    Commented May 9, 2014 at 14:30
  • function bootstrap_subtheme_preprocess_node(&$variables) { $variables['content']['links']['node']['#links']['node-readmore']['attributes']['class'][] = 'btn btn-default'; } It´s works to me, thanks for the help
    – Marco.M
    Commented May 9, 2014 at 15:15
  • And now I need add class to all links no only node-readmore
    – Marco.M
    Commented May 9, 2014 at 15:36

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.