add_action(‘elementor/frontend/widget/before_render’, function( $widget ) {
if ( ! $widget instanceof \Elementor\Widget_Base ) {
return;
}
// Read the class from widget settings (NOT from HTML string)
$settings = $widget->get_settings_for_display();
$classes = isset($settings[‘_css_classes’]) ? (string) $settings[‘_css_classes’] : ”;
// Match full class name safely
if ( strpos(‘ ‘ . $classes . ‘ ‘, ‘ zeevou-channels-pms-loop-cta ‘) === false ) {
return;
}
$post_id = get_the_ID();
if ( ! $post_id ) {
return;
}
$post_type = get_post_type($post_id) ?: ‘post’;
$slug = get_post_field(‘post_name’, $post_id);
if ( ! $slug ) {
$slug = sanitize_title( get_the_title($post_id) );
}
$cta_id = ‘x-‘ . sanitize_key($post_type) . ‘-‘ . sanitize_title($slug) . ‘-cta’;
$title = wp_strip_all_tags( get_the_title($post_id) );
$name = $widget->get_name();
// Image widget (and most “featured image” style widgets) use render attribute key: ‘link’
if ( in_array($name, [‘image’, ‘theme-post-featured-image’, ‘post-featured-image’], true) ) {
$widget->add_render_attribute(‘link’, ‘id’, $cta_id, true);
$widget->add_render_attribute(‘link’, ‘title’, $title, true);
return;
}
// Button widget uses: ‘button’
if ( $name === ‘button’ ) {
$widget->add_render_attribute(‘button’, ‘id’, $cta_id, true);
$widget->add_render_attribute(‘button’, ‘title’, $title, true);
return;
}
// Fallback: try ‘link’ for other widgets that output an with that key
$widget->add_render_attribute(‘link’, ‘id’, $cta_id, true);
$widget->add_render_attribute(‘link’, ‘title’, $title, true);
}, 20);