Forums

Best way to remove "No categories" when no sub-cats (3 posts)

  1. websta
    Member
    Posted 1 year ago #

    What is the best approach for removing the "No categories" notice when no sub-categories are present?

    Here is my code, which seems to work well, and links to populated sub-categories fine. Is something wrong here?

    <div class="sub-cathead">
      <ul>
        <?php
        $children =     wp_list_categories('style=none&hierarchical=0&title_li=&child_of='.$cat.'&echo=0');
        if ($children) { ?>
        <?php echo $children; ?>
        <?php } ?>
      </ul>
    </div>
  2. websta
    Member
    Posted 1 year ago #

    To answer my own question, here is what I have found:

    In wp-includes is a file, category-template.php.

    On line 454 (or so) is the line:

    'show_option_all' => '', 'show_option_none' => __('No categories'),

    Replace the ('No categories') with (''), save the file and upload it to replace the old category-template.php file.

    Every time you upgrade WordPress, repeat.

    If there is a better approach, please advise below.

  3. LukeHollins
    Member
    Posted 1 year ago #

    You can pass show_option_none='' to wp_list_categories instead.

Topic Closed

This topic has been closed to new replies.

About this Topic