1

this function produce this html

<ul class="post-categories">
   <li><a href="#" rel="category tag" class="text">test</a></li>
   <li><a href="#" rel="category tag" class="text">test</a></li>
</ul>

but i need this html

<ul class="post-categories">
<li>
    <a href="#" rel="category tag" class="text">            
        <span class="hover-toggle">Farm to Cup</span>
        <span class="hover-toggle">Farm to Cup</span>            
    </a>
</li>
<li>
    <a href="#" rel="category tag" class="text">            
        <span class="hover-toggle">Farm to Cup</span>
        <span class="hover-toggle">Farm to Cup</span>            
    </a>
</li>

i s there any solution?

1

you could use this snippet, and modify the output string accordingly.

$categories = get_the_category();
$separator = ' ';
$output = '';
if ( ! empty( $categories ) ) {
    foreach( $categories as $category ) {
        $output .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" alt="' . esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ) . '">' . esc_html( $category->name ) . '</a>' . $separator;
    }
    echo trim( $output, $separator );
}

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.