WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how to override get_the_tags core func in theme func and add spans to it (3 posts)

  1. devric
    Member
    Posted 3 years ago #

    Hi

    With the_tag(), i want to add a <span></span> in front and after EACH tag of the tag list for styling like this :-- eg: for tag1 and tag2

    <span class="tag_open"></span>
            <span class="tag">tag1_name </span>
    <span class="tag_close"></span>
    
    <span class="tag_open"></span>
            <span class="tag">tag2_name </span>
    <span class="tag_close"></span>

    I thought about using the :before and :after css but ie6 dont support. So how do i override the function? or how to write a custom foreach loop function to list the tags of the post?

    Thank you

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    there are two ways:

    either, writing your own function, using:
    get_the_tags()
    http://codex.wordpress.org/Function_Reference/get_the_tags

    or, using the parameters of 'the_tags()'
    http://codex.wordpress.org/Function_Reference/the_tags

    i.e.

    <?php the_tags('TAGS: <span class="tag_open"></span><span class="tag">','</span><span class="tag_close"></span>
    <span class="tag_open"></span><span class="tag">','</span><span class="tag_close"></span>'); ?>

    which would result in (for instance):

    TAGS: <span class="tag_open"></span><span class="tag"><a href="http://localhost/wordpress/keywords/apples" rel="tag">apples</a></span><span class="tag_close"></span>
    <span class="tag_open"></span><span class="tag"><a href="http://localhost/wordpress/keywords/bananas" rel="tag">bananas</a></span><span class="tag_close"></span>
    <span class="tag_open"></span><span class="tag"><a href="http://localhost/wordpress/keywords/chattels" rel="tag">chattels</a></span><span class="tag_close"></span> 
    
    <span class="tag_open"></span><span class="tag"><a href="http://localhost/wordpress/keywords/cienaga" rel="tag">cienaga</a></span><span class="tag_close"></span>

    (keep in mind that each tag name is actually a link)

  3. devric
    Member
    Posted 3 years ago #

    thanks works perfect and simple!

Topic Closed

This topic has been closed to new replies.

About this Topic