How To Show Post Title Event CPT Single Layout Elementor Free

This guide is related to this How To Edit Event CPT Single Layout Elementor Free.

  1. 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_Post_Title_Widget extends \Elementor\Widget_Base {

        public function get_name() {
            return 'linnet_post_title';
        }

        public function get_title() {
            return __('Linnet Post Title', 'linnet');
        }

        public function get_icon() {
            return 'eicon-t-letter';
        }

        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,
            ]);

            $this->add_control('html_tag', [
                'label' => __('HTML Tag', 'linnet'),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => 'h2',
                '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-post-title' => 'color: {{VALUE}};',
                ],
            ]);

            $this->end_controls_section();
        }

                protected function render() {
            $settings = $this->get_settings_for_display();
            $tag = esc_html($settings['html_tag']);

            // Get the main queried object from the main query
            $queried_object = get_queried_object();

            if ($queried_object instanceof WP_Post) {
                $title = get_the_title($queried_object->ID);
            } else {
                $title = get_bloginfo('name'); // Fallback
            }

            echo sprintf('<%1$s class="linnet-post-title">%2$s</%1$s>', $tag, esc_html($title));
        }



    }

    \Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Linnet_Elementor_Post_Title_Widget());
});

  1. Go to linnet templates -> edit your event single page template.
  2. Find the linnet post title widget/module, and add it to the page.
  3. Select the html tag you want the post title to have.
  4. Click publish.