I am looking for the best way to create a button that I attach to each node's page that directs to an outside site. The url of the button will information that is in one of the node's fields. I know this should be easy, but I am still new at drupal....

Thanks in advance

//btw, it's drupal 7.

  • J.Reynolds is correct - I would add using a tpl (node, or page) probably has less overhead than perhaps multiple modules with dedicated hooks. You can find template naming information here (drupal.org/node/1089656) – Geoff Jul 25 '14 at 20:24

There are many ways to do it, depending on the field type you are using. The easiest is with the Link or Url field type (link is better as url field is lightweight). You can just set the display formatter correctly, and style it in CSS as a button. If it is in a text field, then you have to output the field in anchor tags setting it as the href attribute value. You can do it in a preprocess node template function in your theme's template file where you rewrite or replace the field value to be an anchor or if you are more of a site builder than a coder then you should look at Display Suite module and use the code field option.

Another easy option is to override the node.tpl.php file for your node type (use the proper override in the naming) and in the template file output the link using the url() function. Depending on the order of your fields you might have to then also hide the field if the content variable is rendered before you need the anchor.

My personal preference is to use Display Suite as it is such a versatile module.


I would use the Link module https://www.drupal.org/project/link

If the text displayed on the button is always the same, you may want to change the default value displayed in the field settings for that content type. If you need the link to look more like a button use CSS.

Happy Drupaling :)

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.