Remove link around category and tags in Genesis template

2.9k Views Asked by At

I want to remove the links (a tag) in the blog template and in the single template in Genesis. I just want to show the plain category names and tags, and don't want a link to the categories.

<p class="entry-meta">    
    <span class="entry-categories">    
       <a href="domain.com/category/category-name/" rel="category tag">Categoryname</a>  
     </span> 
 </p>

So i want to remove the a tag.

I can't find how to do that in Genesis. I know of the function "genesis_post_meta" but i can only change the text and seperator.

4

There are 4 best solutions below

0
On BEST ANSWER

I found this on http://elektroelch.net/wordpress-remove-links-from-the-category/:

add_filter( 'the_category', 'no_links' );
      function no_links($thelist) {
        return preg_replace('#<a.*?>([^<]*)</a>#i', '$1', $thelist);
 }

The function no_links() contains a regular expression which removes all anchors from the string. That’s the whole trick. At the end of your code you should remove the filter again, just in case the categories are displayed on the same page with the standard style.

1
On

You can do this using css

<p class="entry-meta">
    <span class="entry-categories">
      <a href="domain.com/category/category-name/" rel="category tag"> Categoryname</a>
    </span>
</p>

and in css use this

    .entry-categories a {pointer-events: none;cursor: default;}

check this too http://jsfiddle.net/7EQJp/

0
On

the proper way is to use a filter

remove_filter( 'the_category', 'no_links' 10,1 );
or
add_filter( 'the_category', 'no_links' );

Here is the full example: https://themerevel.com/tutorials/wordpress-how-to-remove-category-from-your-urls/

2
On

Do not use CSS to strip links. It is not accessible, provides a poor user experience, and Google will penalize.

Easiest way below:

add_filter('the_category', function ($theList) {
    return preg_replace('#<a.*?>([^<]*)</a>#i', '$1', $theList);
});