Created
April 4, 2025 18:19
-
-
Save bhowe/d965526eab478d094814fe1dcebe0c2e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function accessible_slick_shortcode($atts) { | |
$atts = shortcode_atts([ | |
'imgid' => '' | |
], $atts); | |
$img_ids = explode(',', $atts['imgid']); | |
if (empty($img_ids)) { | |
return '<p>No images found.</p>'; | |
} | |
ob_start(); | |
?> | |
<div class="slider-wrap accessible-slick"> | |
<?php foreach ($img_ids as $img_id) : | |
$img_id = trim($img_id); | |
$img_url = wp_get_attachment_url($img_id); | |
$img_alt = get_post_meta($img_id, '_wp_attachment_image_alt', true); // Fetch alt text | |
if (!$img_alt) { | |
$img_alt = get_the_title($img_id); // If alt text is empty, use the image title | |
} | |
if ($img_url) : ?> | |
<div class="slider-images"> | |
<img src="<?php echo esc_url($img_url); ?>" class="img-fluid" alt="<?php echo esc_attr($img_alt); ?>"> | |
</div> | |
<?php endif; | |
endforeach; ?> | |
</div> | |
<?php | |
return ob_get_clean(); | |
} | |
add_shortcode('accessible-slick', 'accessible_slick_shortcode'); | |
Usage -[accessible-slick imgid="23,13,55,556"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment