This guide is related to this How To Edit Event CPT Single Layout Elementor Free.
- You need to put this custom code inside a snippet plugin. I am using WPCodeBox, which is a paid plugin. You can also choose a snippet plugin that is free, or create a child theme and put it inside the functions file. Make sure that if you choose a snippet plugin, you put it in as a PHP snippet.
<?php
add_action('elementor/widgets/widgets_registered', function() {
if (!class_exists('Elementor\Widget_Base')) return;
class Linnet_Elementor_Taxonomy_Terms_Widget extends \Elementor\Widget_Base {
public function get_name() {
return 'linnet_taxonomy_terms';
}
public function get_title() {
return __('Linnet Taxonomy Terms', 'linnet');
}
public function get_icon() {
return 'eicon-taxonomy';
}
public function get_categories() {
return ['basic'];
}
protected function _register_controls() {
$this->start_controls_section('linnet_content', [
'label' => __('Content', 'linnet'),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]);
// Select Taxonomy (category, tag, or custom)
$tax_options = [];
foreach (get_taxonomies(['public' => true], 'objects') as $tax) {
if ($tax->show_ui && $tax->public) {
$tax_options[$tax->name] = $tax->labels->name;
}
}
$this->add_control('taxonomy', [
'label' => __('Taxonomy', 'linnet'),
'type' => \Elementor\Controls_Manager::SELECT,
'options' => $tax_options,
'default' => 'category',
]);
// Select HTML tag
$this->add_control('html_tag', [
'label' => __('HTML Tag', 'linnet'),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'p',
'options' => [
'h1' => 'H1',
'h2' => 'H2',
'h3' => 'H3',
'h4' => 'H4',
'h5' => 'H5',
'h6' => 'H6',
'p' => 'Paragraph (p)',
'span' => 'Span',
],
]);
$this->add_control('text_color', [
'label' => __('Text Color', 'linnet'),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .linnet-taxonomy-terms' => 'color: {{VALUE}};',
],
]);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
$taxonomy = $settings['taxonomy'];
$tag = esc_html($settings['html_tag']);
$queried_object = get_queried_object();
if ($queried_object instanceof WP_Post) {
$terms = get_the_terms($queried_object->ID, $taxonomy);
if (!empty($terms) && !is_wp_error($terms)) {
$term_names = wp_list_pluck($terms, 'name');
$output = implode(', ', $term_names);
} else {
$output = __('No terms found.', 'linnet');
}
} else {
$output = __('No post context.', 'linnet');
}
echo sprintf('<%1$s class="linnet-taxonomy-terms">%2$s</%1$s>', $tag, esc_html($output));
}
}
\Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Linnet_Elementor_Taxonomy_Terms_Widget());
});
- Go to linnet templates -> edit your event single page template.
- Find the Linnet Taxonomy Terms widget/module, and add it to the page.
- In the module option find the taxonomy option and set it to event category.
- Click publish.