i’d like to create a shortcode for wordpress to display the category name.
Each post on the website is associated with only one category, so there is no need to display a list of categories but only one category name.
I have found here this code :
<?php
function categories_list_func( $atts ){
$categories = get_the_category();
if($categories) {
foreach($categories as $category) {
$output .= '<li class="cat-' . $category->cat_ID . '"><a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "Read more posts from : %s" ), $category->name ) ) . '">'.$category->cat_name.'</a></li>';
}
$second_output = trim($output);
}
$return_string = '<ul>' . $second_output . '</ul>';
return $return_string;
} // END Categories
add_shortcode( 'categories-list', 'categories_list_func' );
?>
The code gives me a partial answer because the result shows a bullet before the category name. How to use the code without showing a bullet before the category name?