Sanjeev
Sanjeev

Reputation: 33

How to hide tags and categories link from search results? in wordpress

I don't know more about codding. I want to hide tags and categories link from search results. I am using Genesis theme for my website. how to do that? Please help me if any one know.

Upvotes: 0

Views: 1594

Answers (2)

brody
brody

Reputation: 1

Replace politics with the category slug,

function exclude_category_from_search($query) {
    if ($query->is_search) {
        $cat_id = get_cat_ID('politics');
        $query->set('cat', '-'.$cat_id);
    }
    return $query;
}

add_filter('pre_get_posts','exclude_category_from_search');

if you also want to remove category links from post meta, use the code provided on this page. https://themerevel.com/tutorials/wordpress-how-to-remove-category-from-your-urls/

Upvotes: 0

Luca Cardelli
Luca Cardelli

Reputation: 51

You need to modify the code a bit to remove it, or if you want to do it easily you can disable every category and tag link in the website by pasting this lines of code in Appearance->Editor of your wordpress theme.

To remove links ( and reset the style ):

.entry-categories a, .entry-tags a {
     text-decoration:none;
     pointer-events:none;
     color:inherit;
}

To hide it completely:

.entry-categories, .entry-tags {
    display:none;
}

That's an easy solution but it will be disabling or hiding every category and tag on your website,

To remove/hide them only on search result you need to modify the searchpage.php file.

If you don't know what to delete, you better not do it, it can break your theme.

Upvotes: 1

Related Questions