get_controls( 'container_link' ) ) { return; } $element->start_controls_section( 'section_container_link', [ 'label' => __( 'Container Link', 'addon-elementor-container-link' ), 'tab' => \Elementor\Controls_Manager::TAB_LAYOUT, ] ); $element->add_control( 'container_link', [ 'label' => __( 'Link', 'addon-elementor-container-link' ), 'type' => \Elementor\Controls_Manager::URL, 'placeholder' => __( 'https://your-link.com', 'addon-elementor-container-link' ), 'dynamic' => [ 'active' => true ], 'show_external' => true, 'default' => [ 'url' => '', 'is_external' => false, 'nofollow' => false, ], ] ); $element->end_controls_section(); } /** * Wrapper attributes to make the element clickable on the frontend. * * @param \Elementor\Element_Base $element */ function fr_render_container_link( $element ) { $settings = $element->get_settings_for_display(); if ( empty( $settings['container_link']['url'] ) ) { return; } $link_data = $settings['container_link']; $link_url = esc_url( $link_data['url'] ); $target = ! empty( $link_data['is_external'] ) ? '_blank' : '_self'; $nofollow = ! empty( $link_data['nofollow'] ) ? 'nofollow' : ''; $attributes = [ 'class' => 'fr-container-link', 'data-fr-container-link-url' => $link_url, 'data-fr-container-link-target' => $target, 'role' => 'link', 'tabindex' => '0', ]; if ( ! empty( $nofollow ) ) { $attributes['rel'] = $nofollow; } $element->add_render_attribute( '_wrapper', $attributes ); } /** * Enqueue frontend CSS and JavaScript assets. */ function fr_enqueue_container_link_assets() { static $assets_enqueued = false; if ( $assets_enqueued ) { return; } $custom_css = '.fr-container-link { cursor: pointer; }'; if ( wp_style_is( 'elementor-frontend', 'registered' ) || wp_style_is( 'elementor-frontend', 'enqueued' ) ) { wp_add_inline_style( 'elementor-frontend', $custom_css ); } $custom_js = " (function( $ ) { 'use strict'; function handleContainerClick( e, el ) { // Prevent navigation while editing inside Elementor Editor if ( ( typeof elementorFrontend !== 'undefined' && elementorFrontend.isEditMode && elementorFrontend.isEditMode() ) || $( 'body' ).hasClass( 'elementor-editor-active' ) ) { return; } // If the user was selecting/highlighting text, do not navigate if ( window.getSelection && window.getSelection().toString().length > 0 ) { return; } var linkUrl = $( el ).data( 'fr-container-link-url' ); var linkTarget = $( el ).data( 'fr-container-link-target' ); if ( ! linkUrl ) { return; } // Ignore clicks on child links, buttons, form controls, and interactive widgets if ( $( e.target ).closest( 'a, button, input, textarea, select, label, .elementor-button, .elementor-icon, .elementor-widget-button' ).length ) { return; } e.stopPropagation(); // Support opening in new tab via option, Ctrl/Cmd click, or middle mouse click if ( linkTarget === '_blank' || e.ctrlKey || e.metaKey || e.which === 2 ) { window.open( linkUrl, '_blank', 'noopener,noreferrer' ); } else { window.location.href = linkUrl; } } $( document ).on( 'click auxclick', '.fr-container-link', function( e ) { if ( e.type === 'auxclick' && e.which !== 2 ) { return; } handleContainerClick( e, this ); } ); $( document ).on( 'keydown', '.fr-container-link', function( e ) { if ( e.key === 'Enter' ) { handleContainerClick( e, this ); } } ); })( jQuery ); "; if ( wp_script_is( 'elementor-frontend', 'registered' ) || wp_script_is( 'elementor-frontend', 'enqueued' ) ) { wp_add_inline_script( 'elementor-frontend', $custom_js ); } $assets_enqueued = true; } /** * "Buy cup of coffee" donate link. * * @param array $links An array of plugin row meta links. * @param string $file The current plugin file. * @return array An array of plugin row meta links. */ function fr_add_support_link_to_plugin_row_meta( $links, $file ) { if ( $file !== plugin_basename( __FILE__ ) ) { return $links; } $support_link = '' . __( 'Buy cup of coffee', 'addon-elementor-container-link' ) . ''; $links[] = $support_link; return $links; } if ( is_admin() ) { add_filter( 'plugin_row_meta', 'fr_add_support_link_to_plugin_row_meta', 10, 2 ); }