0

In my Drupal site I have node teasers that show taxonomy terms. As it stands they are like:

Tags:

Houses

<div class="field field-name-field-tags field-type-taxonomy-term-reference field-label-above">
  <div class="field-label">Tags:</div>
    <div class="field-items"><div rel="schema:category" class="field-item even">
        <a datatype="" property="rdfs:label skos:prefLabel" typeof="skos:Concept" href="/tags/houses">Houses</a>
    </div>
  </div>
</div>

I cant locate where the <a> anchor tag is being generated. I want to be able to change it to a <button> tag instead of anchor.

Any ideas how to do this?

2
  • Have you tried hook_field_formatter_view()?
    – argiepiano
    Oct 20, 2015 at 3:32
  • Hi mate, I have not tired hook_field_formatter_view() how would I implement this?
    – harnamc
    Oct 20, 2015 at 15:55

1 Answer 1

0

Take a look at this tutorial that shows you how to create a custom formatter for specific field types. The taxonomy term field type machine name is taxonomy_term_reference

4
  • Brilliant tutorial, is there a way without creating a custom module?
    – harnamc
    Oct 20, 2015 at 15:56
  • If you intend to use the hooks in the tutorial, you need to create a module . Creating a module for Drupal 7 is really simple - there are many tutorials online. Other than that, I guess you could try using jQuery to replace the tag <button> for <a>, but I don't know enough jQuery to guide you. You would need to modify your theme .info file to load the .js file that contains the jQuery functions. I find this more complex than creating a module
    – argiepiano
    Oct 20, 2015 at 16:46
  • Would it have to be a similar method if I wasn't changing the anchor to button but wanted to add extra classes to the anchor tag?
    – harnamc
    Oct 20, 2015 at 16:59
  • Check out field_formatter_class drupal.org/project/field_formatter_class. It allows you do ad css classes to the <div> wrapper around the <a> tag
    – argiepiano
    Oct 20, 2015 at 17:34

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.