How to override Elementor Essentials Addons template render output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
an example of how to add an extra field to an elementor section | |
and then override the ouput of the Elementor Essentials Addons template render | |
this should go to your child theme functions.php | |
More info at: https://www.nitroweb.gr/how-to-override-elementor-essentials-addons-template-render-output/ | |
*/ | |
add_action( 'elementor/element/before_section_end', function( $element, $section_id, $args ) { | |
/** @var \Elementor\Element_Base $element */ | |
// put the field in the right place | |
if ( 'eael-post-carousel' === $element->get_name() && 'eael_section_post_timeline_layout' == $section_id ) { | |
$element->add_control( | |
'nitro_carousel_link_title', | |
[ | |
'type' => \Elementor\Controls_Manager::SWITCHER, // https://code.elementor.com/classes/elementor-controls_manager/ | |
'label' => __( 'Link title' ), | |
'label_on' => __( 'Yes' ), | |
'label_off' => __( 'No' ), | |
'return_value' => 'yes', | |
'default' => 'yes', | |
] | |
); | |
} | |
}, 10, 3 ); | |
class nitro_elementor_hooks { | |
use \Essential_Addons_Elementor\Traits\Helper; | |
function __construct() { | |
// check if the eael_get_query_args Helper method exists | |
if( !method_exists( $this, 'eael_get_query_args') ) { | |
return; | |
} | |
add_action( 'elementor/widget/render_content', array( $this, 'nitro_carousel_render' ), 10, 2 ); | |
} | |
public function nitro_carousel_render( $content, $widget ) { | |
if ( 'eael-post-carousel' === $widget->get_name() ) { | |
$settings = $widget->get_settings(); | |
$args = $this->eael_get_query_args($settings); | |
if ( isset( $settings['nitro_carousel_link_title'] ) && $settings['nitro_carousel_link_title'] != 'yes' ) { | |
$query = new \WP_Query($args); | |
if ($query->have_posts()) { | |
while ($query->have_posts()) { | |
$query->the_post(); | |
$title_link = ''; | |
$title_text = ''; | |
if ($settings['eael_show_title']) { | |
$title_link .= '<a class="eael-grid-post-link" href="' . get_permalink() . '" title="' . get_the_title() . '">'; | |
if(empty($settings['eael_title_length'])) { | |
$title_text .= get_the_title(); | |
}else { | |
$title_text .= implode(" ", array_slice(explode(" ", get_the_title() ), 0, $settings['eael_title_length'])); | |
} | |
$title_link .= $title_text; | |
$title_link .= '</a>'; | |
} | |
$content = str_replace( $title_link, $title_text, $content ); | |
} | |
} | |
wp_reset_postdata(); | |
} | |
} | |
return $content; | |
} | |
} | |
new nitro_elementor_hooks(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment