• Dear –

    Above the h1 there is the categories associated with a given ‘Acticle’

    Each category is clickable and links to the Archive page

    How to remove the link using a child theme method?

    thx

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • This should already exist in the Appearance->Customize->Content Options section under the ‘Display categories’ checkbox

    Nevermind, this was only available with Jetpack enabled

    • This reply was modified 4 years, 8 months ago by Jarret.

    Try the following instead in your child theme’s functions.php file

    function no_cats_in_post() {
    	return false;
    }
    add_filter( 'twentytwenty_show_categories_in_entry_header', 'no_cats_in_post' );

    You can modify the no_cats_in_post wording to your liking, just make sure you update it to match in the last line of code

    Thread Starter thelabo

    (@thelabo)

    Hi Jarret !

    thank you for your quick turnaround.

    When I apply this function, the categories associated with a given ‘Acticle’ is not displayed anymore.
    => https://le-briand.fr/musee-literie/matelassier-paris/matelassier-fabricant-matelas-laine-histoire-episode-1/

    I was wondering if we could keep them displayed but just deactivated the hyperlink ?
    so that the categories are not clickable.

    thx and have a good day

    Hi, it is possible but requires some extra coding. Copy over /template-parts/entry-header.php into your child theme if you haven’t already. Open up that file and look for the following code

    <div class="entry-categories-inner">
    					<?php the_category( ' ' ); ?>
    				</div><!-- .entry-categories-inner -->

    replace it with the following

    <div class="entry-categories-inner">
    						<?php foreach( get_the_category() as $category ) {
    							echo "<div>" . $category->name . "</div>";
    						} ?>
    				</div><!-- .entry-categories-inner -->

    Then, we need to add some custom CSS to make it look like the normal links, add the following in Appearance->Customize->Additional CSS

    .entry-header .entry-categories-inner div {
    	color: red;
    	font-size: 1.5rem;
    	font-weight: 700;
    	letter-spacing: 0.036666667em;
    	margin: 1rem 0 0 2rem;
    	text-transform: uppercase;
    }

    From my testing it should replicate the categories without having them linked

    Thread Starter thelabo

    (@thelabo)

    Hi Jarret !

    Thank you!

    it works! ??

    How is possible to deactivate the Categorie listing page?

    Categorie listing page = the listing pages automatically generated by WordPress listing the article associated to a given category.

    thx

    Hmm, so you don’t want people to be able to browse example.com/category/some-category? But for all the categories on your site?

    I’m sure that is probably possible, though whether advisable and if it would cause issues with how WP works I’m not sure. I would think you could just force a redirect to the homepage or something using is_category()

    Would probably want to research it a bit more to see if there are potential issues from somebody that has tried it.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to deactivate the link on the categories in the Article template’ is closed to new replies.