Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display category list without link wordpress

Tags:

php

wordpress

I was trying to list category names. wp_list_categories() returns a list of the categories but the problem is that it automatically wraps the names with links. I do not need the links.

It is possible to disable the links by JavaScript? But then I would have to fire some JS event.

I need to retrieve the category list without the automatic anchor tags, any idea?

like image 882
MD. Atiqur Rahman Avatar asked Dec 02 '22 13:12

MD. Atiqur Rahman


2 Answers

This works well, with less code:

<?php
$category = get_the_category();
echo $category[0]->cat_name;
?>
like image 114
Michel Moraes Avatar answered Dec 05 '22 22:12

Michel Moraes


You can achieve this using the wordpress function get_categories(), this should work :

PHP

 <ul>
  <?php
  foreach (get_categories() as $category){
    echo "<li>";
    echo $category->name;
    echo "</li>";
  } ?>
</ul>
like image 39
Sofiene Djebali Avatar answered Dec 06 '22 00:12

Sofiene Djebali