I have the plugin “The Events Calendar” on my WordPress website.
I want to show the event categories and tags next to the event name.
But I can’t manage that.
I used a widget to enter this. I have already added some php code. But I don’t see anything appearing. This only appears on the page of those events themselves. But not where I want it to be.
To clarify, this is the page of my website where it should be visible Website
Below I put the php code that I put in my child theme.
// Add categories and tags to event list
function add_categories_and_tags_to_event_list( $event_output, $event ) {
// Get categories for the event
$categories = get_the_terms( $event->ID, 'tribe_events_cat' ); // Adjusted for The Events Calendar plugin
// Get tags for the event
$tags = get_the_terms( $event->ID, 'post_tag' );
// Add categories to the output
if ( $categories && ! is_wp_error( $categories ) ) {
$category_output = '<div class="event-categories">';
foreach ( $categories as $category ) {
$category_output .= '<span class="category">' . $category->name . '</span>';
}
$category_output .= '</div>';
$event_output .= $category_output;
}
// Add tags to the output
if ( $tags && ! is_wp_error( $tags ) ) {
$tag_output = '<div class="event-tags">';
foreach ( $tags as $tag ) {
$tag_output .= '<span class="tag">' . $tag->name . '</span>';
}
$tag_output .= '</div>';
$event_output .= $tag_output;
}
return $event_output;
}
add_filter( 'tribe_events_event_schedule_details', 'add_categories_and_tags_to_event_list', 10, 2 );