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?
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>
This works well, with less code:
<?php
$category = get_the_category();
echo $category[0]->cat_name;
?>
With the_category()
you will get the links. However, you can also disable them with CSS.
<?php the_category($separator = ", "); ?> // with optional separator
Disable click events:
pointer-events: none !important;
Example:
<p style="pointer-events: none !important;"><?php the_category($separator = ", "); ?></p>