Adding code to the category links and
-
I need to add an attribute to all the category links in all posts on a site I’m building for someone. Is there a simple way of modifying get_category_links ()?
At the moment I’m using this code in the single.php file:
<div class="entry-meta"> <?php // Get the ID of a given category $category_id = get_cat_ID( 'Category Name' ); // Get the URL of this category $category_link = get_category_link( $category_id ); foreach((get_the_category()) as $category) { echo '<a onclick="tb_remove()" href="'.$category_link.' ">'.$category->cat_name.'</a>' ; } ?> </div>
However this is outputting the following
<a href="https://www.xxxx.xxx/?cat=0 " onclick="tb_remove()">1960s</a>
Which works to an extent but why is it returning a cat=0?
Is there another way to add onclick=”tb_remove()” to the links?
Any help greatly appreciated as I’m getting worried now that I won’t be able to do it in time
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Adding code to the category links and’ is closed to new replies.