Featured Image Shortcode [Plugin]

Date Posted: January 7, 2015, 8:38 am


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);
    }
}

About author


Carl Victor Fontanos

A fine gentleman specializing in front-end and back-end development with extensive experience building high performance web applications that keeps users engaged and help businesses grow.

 
Hire Me