Created
June 22, 2021 18:09
-
-
Save pingram3541/a3b283856b8b3f8ede16aa1b283f33a4 to your computer and use it in GitHub Desktop.
Elementor - Add URL control to Star-Rating widget
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
/** | |
* 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