Forums

How to strip tags from the_category (4 posts)

  1. KostRev
    Member
    Posted 3 years ago #

    I'd like to add the_category tag to the Loop's class="post but need to remove the extra mark-up. Can I use strip_tags and then split them? Something like this perhaps:
    <div class="post <?= split(strip_tags(the_category()))[0]; ?> id="post-<?php the_ID(); ?>">

    Thanks for the help.

  2. chaoskaizer
    Member
    Posted 3 years ago #

    I'd like to add the_category tag to the Loop's class="post but need to remove the extra mark-up. Can I use strip_tags and then split them?

    I think you should use get_the_category instead of the_category functions.

  3. KostRev
    Member
    Posted 3 years ago #

    I can't seem to add that PHP to class="post without the whole page going blank... I'll keep at it.

    I've had some success with this though there is still the anchor that needs to be removed:
    <div class="post <?php (strip_tags(":",the_category(','))); ?>" id="post-<?php the_ID(); ?>">

    Thanks

  4. KostRev
    Member
    Posted 3 years ago #

    You are right! This worked perfectly:

    <div class="post <?php
    $category = get_the_category();
    echo $category[0]->category_nicename;
    ?>" id="post-<?php the_ID(); ?>">

    Thanks for pointing me in the right direction.

Topic Closed

This topic has been closed to new replies.

About this Topic