Last active
October 6, 2015 18:52
-
-
Save cdmz/67a9d3f0a7fd431d915d to your computer and use it in GitHub Desktop.
input img wordpress SEO
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
| <?php | |
| /* | |
| @author Cristiano de Mari | |
| @param Int $ID | |
| @param String $attachment | |
| @param Array $args | |
| @return <img /> | |
| */ | |
| function img($ID = NULL, $thumb_size = 'post-thumbnail',$args = NULL ){ | |
| if($ID){ | |
| //get post | |
| $p = get_post( $ID ); | |
| //not attachment | |
| if($p->post_type != 'attachment'){ | |
| //get id thumbnail | |
| $image_post_id = get_post_thumbnail_id( $ID ); | |
| //get post thumbnail image | |
| $image_post = get_post( $image_post_id ); | |
| $source_files = wp_get_attachment_image_src( $image_post->ID , $thumb_size ); | |
| } | |
| //is attachment | |
| if($p->post_type == 'attachment'){ | |
| //thumbnail id | |
| $image_post_id = $ID ; | |
| //get post thumbnail image | |
| $image_post = $p; | |
| $source_files = wp_get_attachment_image_src( $image_post->ID , $thumb_size ); | |
| } | |
| //Set attrs | |
| if(isset($args['class'])){ | |
| if(is_array($args['class'])){ | |
| $class = implode(' ', $args['class']); | |
| }else{ | |
| $class = $args['class']; | |
| } | |
| } | |
| if(isset($args['id'])){ | |
| $id = $args['id']; | |
| } | |
| $alt = get_post_meta($image_post_id, '_wp_attachment_image_alt', TRUE); | |
| #$legenda = ($image_post->post_excerpt) ? $image_post->post_excerpt.' ' : ' ' ; | |
| #$descricao = ($image_post->post_content) ? $image_post->post_content.' ' : ' ' ; | |
| $title = $image_post->post_title; | |
| $img = '<img '; | |
| $img .= ($source_files[0]) ? "src=\"{$source_files[0]}\" " : '' ; | |
| $img .= ($id) ? "id=\"{$id}\" " : '' ; | |
| $img .= ($class) ? "class=\"{$class}\" " : '' ; | |
| $img .= ($title) ? "title=\"{$title}\" " : '' ; | |
| $img .= ($alt) ? "alt=\"{$alt}\" " : '' ; | |
| $img .= ($source_files[1]) ? "width=\"{$source_files[1]}\" " : '' ; | |
| $img .= ($source_files[2]) ? "height=\"{$source_files[2]}\"" : '' ; | |
| $img .= ' />'; | |
| return $img; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment