Is there any way to modify the <a> tag surrounding an element, like e.g. adding data attributes?
-
Filter <a> tag
-
Hey do you mean the <a> tags for image links or post thumbnail links?
There is no specific filter for <a> tags only, but you could completely replace the post thumbnail markup with your own markup.
For post thumbnail links you can use the filter:
lg_frontend_postthumbnail
The following code is just an example:
add_filter('lg_frontend_postthumbnail', 'my_theme_lg_frontend_postthumbnail', 10, 3); function my_theme_lg_frontend_postthumbnail($thumbnail, $element, $obj)){ $thumbnail = ""; $attid = get_post_thumbnail_id($element->postid); $alt = get_post_meta($attid, '_wp_attachment_image_alt', true); $srcset = wp_get_attachment_image_srcset($attid); $vw = LayGridderFrontend::get_vw($obj, $element->colspan); // is viewport bigger than breakpoint? use $vw as "sizes", otherwise use 100vw $sizes = '(min-width: '.(LayGridderOptions::$phone_breakpoint+1).'px) '.$vw.'vw, 100vw'; $url = wp_get_attachment_url($attid); $is_gif = substr($url, -4) == ".gif" ? true : false; $thumbnail .= '<a href="'.get_permalink($element->postid).'" data-id="'.$element->postid.'" data-slug="'.get_post_field('post_name', $element->postid).'" data-title="'.htmlentities(get_the_title($element->postid)).'"> <div class="lg-placeholder" style="padding-bottom:'.($element->ar*100).'%;">'; if($is_gif){ $thumbnail .= '<img src="'.$url.'" alt="'.$alt.'">'; }else{ $thumbnail .= '<img srcset="'.$srcset.'" sizes="'.$sizes.'" src="'.$url.'" alt="'.$alt.'">'; } $thumbnail .= '</div> </a>'; $thumbnail .= '<div class="lg-caption lg-textformat-parent"><p>'.get_the_title($element->postid).'</p></div>'; return $thumbnail; }
-
If you want to change the anchor tag of an image element, that is linked, this is not possible right now.
Because the filter lg_frontend_img only filters the image, not the surrounding anchor tag markup.Let me know your exact use case and we can create a new filter!