Skip to content

Instantly share code, notes, and snippets.

@pingram3541
Created June 22, 2021 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pingram3541/a3b283856b8b3f8ede16aa1b283f33a4 to your computer and use it in GitHub Desktop.
Save pingram3541/a3b283856b8b3f8ede16aa1b283f33a4 to your computer and use it in GitHub Desktop.
Elementor - Add URL control to Star-Rating widget
/**
* add url control to star rating widget
**/
add_action( 'elementor/element/star-rating/section_rating/before_section_end', function( $element, $args ) {
$element->add_control(
'rating_url',
[
'type' => \Elementor\Controls_Manager::URL,
'label' => __( 'Link', 'elementor' ),
'placeholder' => __( 'https://your-link.com', 'elementor' ),
'show_external' => true,
'default' => [
'url' => '',
'is_external' => true,
'nofollow' => true,
],
]
);
}, 10, 2 );
/**
* render star rating widget with url
**/
add_action( 'elementor/widget/render_content', function( $content, $widget ) {
if ( 'star-rating' === $widget->get_name() ) {
$settings = $widget->get_settings();
$url = $settings['rating_url']['url'];
$target = $settings['rating_url']['is_external'] ? ' target="_blank"' : '';
$nofollow = $settings['rating_url']['nofollow'] ? ' rel="nofollow"' : '';
$begin_html = '<a href="' . $settings['rating_url']['url'] . '"' . $target . $nofollow . '>';
if( ! empty( $url ) ){
$content = $begin_html . $content . '</a>';
}
}
return $content; //do not mess with this
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment