Featured Image Shortcode [Plugin]

featured-image-shortcode

Usage:

1
[featured-image size = "large" class = "featured-image" title = "something" alt = "image"]

Available attributes:
1. class
2. title
3. alt

Available sizes:
1. thumbnail
2. medium
3. large
4. full

Give away code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
add_shortcode('featured-image', array('Featured_image_shortcode', 'cvf_post_thumbnail_shortcode') );

class Featured_image_shortcode {

    public static function cvf_post_thumbnail_shortcode($atts, $content = '') {
       
        $img_attr = '';
        $atts['class'] = '';
       
        $img_attr = array(
            'class' => $atts['class'],
            'alt'   => trim(strip_tags($atts['alt'])),
            'title' => trim(strip_tags($atts['title']))
        );
       
        if(!$atts['size']){
            $atts['size'] = 'thumbnail';
        }
       
        return get_the_post_thumbnail(null, $atts['size'], $img_attr);
    }
}


Do you need help with a project? or have a new project in mind that you need help with?

Contact Me