Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Så här visar du beskrivningar av kategorier i WordPress

Vill du visa beskrivningar av kategorier på din site i WordPress?

Categories allow you to easily sort content on your website. De hjälper också användare att enkelt hitta content och är bra för sökmotorsoptimering.

I den här artikeln visar vi dig hur du enkelt kan add’a descriptions till dina kategorier i WordPress.

How to Display Category Descriptions in WordPress

Varför visa beskrivningar av Category i WordPress?

Om du har skapat en website i WordPress använder du förmodligen redan kategorier och tags. Men du kanske inte utnyttjar deras fulla potential.

Categories och tags allow you att enkelt sortera ditt content i olika ämnen. Och när de används korrekt kan kategorier och taggar också vara till stor hjälp för att förbättra din sökmotorsoptimering i WordPress.

WordPress allow you to add descriptions for your categories. Du kanske inte har notice detta om du skapar kategorier när du skriver ett post eftersom den metoden inte har behörighet att lägga till en description.

Med detta sagt, låt oss ta en titt på hur du enkelt kan add descriptions till dina kategorier i WordPress.

Lägga till beskrivningar av kategorier i WordPress

Först måste du heada över till sidan Posts ” Categories. Om du skapar en ny kategori kan du helt enkelt enter kategorinamnet och beskrivningen här och sedan klicka på knappen ”Add new category”.

The Posts»Categories Page

Om du vill add to en description till en befintlig kategori måste du click på länken ”Edit” under den kategorin.

Då kommer du till vyn Category edit, där du kan add to en description för your category.

Add a Description to a Category

Glöm inte att clicka på knappen ”Update” för att save your changes.

Upprepa bara processen för att lägga till beskrivningar till alla dina kategorier. Du kan använda samma metod för att add to beskrivningar för taggar också.

Displaying Category Description på Category Archive Pages

De flesta teman i WordPress visar automatiskt beskrivningen av kategorin på sidorna i kategorins archive.

Display Category Descriptions on Category Archive Pages

Men om ditt tema ej displayed category descriptions on archive pages, then you will have to modify your theme. Det säkraste sättet att göra detta är att skapa ett barntema.

Mer information finns i vår guide för nybörjare om hur man skapar ett barntema.

Därefter måste du kopiera en fil från huvudtemat till barntemat. Du kan använda en FTP-klient eller filhanteraren cPanel som erbjuds av ditt webbhotell för WordPress.

You will need to go to your website’s /wp-content/themes/parent-theme/ folder and find the category.php file. Om din fil inte innehåller den filen, måste du hitta archive.php istället.

Find category.php or archive.php Using FTP Software

Efter det bör du kopiera filen till mappen för ditt barntema.

Därefter måste du editera filen och sedan add to detta code snippet där du vill att kategoribeskrivningen ska displayed:

<?php
the_archive_description( '<div class="taxonomy-description">', '</div>' );
?>

Vanligtvis kommer detta att vara strax efter den section som innehåller the_archive_title. Glöm inte att save filen efter att du har klistrat in koden.

Paste the Code Snippet

Your category archive pages kommer nu att visa beskrivningar av kategorierna.

Här är ett exempel från vår demo site. Temat Twenty Nineteen visar inte kategoribeskrivningar som standard, men när vi addade code snippet till ett barntema kan du se att kategoribeskrivningen nu visas.

Preview of Category Description

Displaying Category Description i WordPress Theme

Om du är bekväm med att använda kod på din WordPress-webbplats kan du använda dessa code snippets för att visa kategoribeskrivningar på andra locations runt din website.

Displaying a Single Category Description on Your Website

Om du vill displayed en category description i andra delar av din website, då måste du använda category_description template tag:

<?php echo category_description(3); ?>

Du måste ersätta 3 med kategori-ID:n för den kategori du vill använda.

Displaying Category Descriptions i varje post

Om du vill visa en kategoribeskrivning i enskilda inlägg kan du add to ett code snippet till exempel i single.php eller footer.php template.

Om du använder ett barntema måste du först kopiera templaten från huvudtemat till barntemats folder.

Efter det måste du add to den här koden:

$catID = get_the_category();
echo category_description( $catID[0] );

Den här koden hämtar helt enkelt alla kategorier för det aktuella posten och matar sedan ut kategoribeskrivningen för den första kategorin.

Lista alla kategorier och beskrivningar

Om du gillar att lista alla dina WordPress kategorier med en description i listformat, kan du add to denna kod till ditt temas functions.php-fil eller insert code snippet med hjälp av WPCode plugin (rekommenderas).

För detaljer, se vår guide om hur du lägger till custom code i WordPress.

function wpb_catlist_desc() {
$string = '<ul>';
$catlist = get_terms( 'category' );
if ( ! empty( $catlist ) ) {
  foreach ( $catlist as $key => $item ) {
    $string .= '<li>'. $item->name . '<br />';
    $string .= '<em>'. $item->description . '</em> </li>';
  }
}
$string .= '</ul>';

return $string;
}
add_shortcode('wpb_categories', 'wpb_catlist_desc');

Den här koden skapar en shortcode som displayed all your kategorier och deras descriptions i en vanlig lista.

Du kan nu använda [wpb_categories] i dina posts och pages. Om du vill använda den här shortcoden i en textwidget måste du aktivera shortcodes för widgetar.

List WordPress categories with description

Bonus: Lägga till kategori Meta Description för att förbättra sökmotorsoptimering

Som standard lägger WordPress inte till din kategoribeskrivning i metataggarna.

Det är därför det är viktigt att du använder ett WordPress SEO plugin som All in One SEO för WordPress för att add to kategori meta beskrivningar för att öka din SEO.

Adding a meta description for your category in All in One SEO

Expertguider om kategorier i WordPress

Nu när du vet hur du visar beskrivningar av kategorier kanske du gillar att se några andra guider relaterade till WordPress-kategorier:

Vi hoppas att denna tutorial hjälpte dig att lära dig hur du visar beskrivningar av kategorier i WordPress. Du kanske också vill se vår guide om hur du flyttar WordPress från HTTP till HTTPS eller våra expertval för de tillägg du måste ha för att få din site att växa.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Avslöjande: Vårt innehåll stöds av våra läsare. Det innebär att om du klickar på några av våra länkar, kan vi tjäna en provision. Se hur WPBeginner finansieras, varför det är viktigt, och hur du kan stödja oss. Här är vår editoriala process.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Den ultimata WordPress-verktygslådan

Få GRATIS tillgång till vår verktygslåda - en samling WordPress-relaterade produkter och resurser som varje professionell användare bör ha!

Reader Interactions

29 kommentarerLämna ett svar

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Jiří Vaněk says

    I would like to ask. Previously, it was possible to add an image to category descriptions. There was a classic editor where you could add media. I have it set up this way on my blog. However, after some update of WordPress, this option disappeared, and now I can only add a description. I tried editing the category in the database by adding an image using HTML, but WordPress doesn’t display this link. Is there any way to add an image to the description?

    • WPBeginner Support says

      To prevent that you would either need to create a site specific plugin or a child theme

      Administratör

  3. Mirela says

    Hi. How do you make the description show only on the first page of the category? I want to avoid duplicate content :(

    • WPBeginner Support says

      Your SEO plugin should prevent duplicate content if you mean the description on the category archive

      Administratör

    • WPBeginner Support says

      No, this would be for standard WordPress categories and not WooCommerce categories

      Administratör

  4. Tiffany says

    So I created a category for slow cooker recipes. I titled it it ”healthy slow cooler recipes”. It displays properly in the drop down menu and on the back end. But when I look at the category results page from the front end, it has extra words at the front of the title that I can’t find anywhere and I did not add them. I need to delete them but I’m not sure where this is pulling from. Any ideas?

    • WPBeginner Support says

      Your theme would likely be what’s adding it. If you reach out to your theme’s support they should be able to assist you.

      Administratör

  5. Ola says

    God bless you real good. Please, how do I make the categories clickable? so that when someone clicks on each category, it will take them to the Archive list

  6. Anthony says

    Wondering if it’s possible to do this with custom post types. I have a recipe website and would love to add the descriptions to help with SEO.

    Thanks.

    • WPBeginner Support says

      As long as your custom post type accepts categories it should be able to display the same way.

      Administratör

  7. Sandra says

    Hi,
    Is there a way to hide the description of the categories? I am looking for the opposite of this post (Hide Category Descriptions) but can’t seem to find anything :(

    My previous theme didn’t display category descriptions, but I updated today to wpocean and this new theme does display the text, I don’t like it. I feel that users will get lost or won’t scroll down to read the posts :/

    Is there a code to fix it?

    • WPBeginner Support says

      You would want to reach out to the support for your current theme first to see if there is an option to do so built-in with the theme or a recommended method to remove the description.

      Administratör

  8. Mads Grønlund says

    EDIT: I am now subscriting to replies. You can delete my other reply. :-)

    Hey! Great post, although I would like to ask, is there a way to move the category description to the bottom of the page? In case I want say a 2.000 words description for the SEO-value but I don’t want it to block all the actual posts in that category.

    Thanks in advance!

    • WPBeginner Support says

      Hi Mads Grønlund,

      Yes, you can do that. For that you will need to edit your theme template files like category.php. Look for the code responsible for displaying description and move it down towards the end of the loop. You may run across some issues, so it would be best to backup your original template files first.

      Administratör

  9. Dejan says

    Hello everyone,

    This is very useful post and I was cracking my head why the category description wasn’t being displayed in my theme, and following this tutorial it occured to me that my theme didn’t even have the category.php or archive.php files!
    In such cases you need to edit the index.php file with the code provided in this tutorial. It worked like a charm for me :)

    • D says

      I don’t have category or archive in my theme either. Tried posting code in index.php but didn’t work (and i have no clue what I’m doing to post the code there) any way you can elaborate on the steps a little more?

  10. Madison Woods says

    Is there a way to make the category description only show up on the first page of category archives? Isn’t it ’duplicate content’ if it appears on every page of that category’s posts? Some of my categories contain a large amount of posts so there might be 4 or 5 pages of ’older posts’ in that category. Each one of those pages of posts shows the same description. Thanks for any tips!

  11. Naomi says

    Thanks so much for this tip – it worked absolutely perfectly and it saved me a lot of potential headaches.

    My category description is showing up as planned, just where I wanted it to :)

  12. Beth says

    If my category is a subcategory I notice there are two description boxes to fill out. Only the bottom one will automatically show up on my subcategory page. Should I fill out both description boxes? Should they be the same?

Lämna ett svar

Tack för att du väljer att lämna en kommentar. Tänk på att alla kommentarer modereras enligt våra policy för kommentarer, och din e-postadress kommer INTE att publiceras. Vänligen använd INTE nyckelord i namnfältet. Låt oss ha en personlig och meningsfull konversation.