To display WordPress categories in a paragraph with comma separators instead of bullet points, you need to modify the code that displays them.You can use the the_category
function, but change the separator parameter. Here's how:
single.php
, archive.php
) that's responsible for displaying the categories. It likely uses the_category()
or wp_list_categories
.the_category()
function and specify a comma as the separator:Code
<?php the_category(', '); ?>
This will display the categories separated by a comma and a space. You can adjust the separator as needed.
wp_list_categories
: Instead of wp_list_categories
, which defaults to a list, you can use get_the_category()
and implode()
to achieve the same result:Code
<?php
$categories = get_the_category();
$category_names = array();
foreach ($categories as $category) {
$category_names[] = $category->cat_name;
}
echo implode(', ', $category_names);
?>
Example:
If you have the following code:
Code
<?php the_category(); ?>
Replace it with:
Code
<?php the_category(', '); ?>