Advertisement
febripratama

WP ALT TAG

Jan 5th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <?php // cretae gallery automatically
  2.     $images = get_children( array ( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image' ));
  3.  
  4.     if ( !empty($images) ) {
  5.  
  6.         $i = 0; foreach ( $images as $attachment_id => $attachment ) {
  7.  
  8.             if ($i == 0) { $i++; continue;}
  9.  
  10.             $attachment_meta = wp_get_attachment($attachment_id); $alt_title = str_replace('-', ' ', $attachment_meta['title']);
  11.  
  12.             //post's tags
  13.             $tags = wp_get_post_tags($post->ID);
  14.             $tagsString = ' ';
  15.             foreach($tags as $tag){
  16.                 $tagsString = $tagsString.' '.$tag->name;
  17.             }
  18.  
  19.             $arr_img = array( 'alt' => ucwords($alt_title).$tagsString, 'title' => ucwords($alt_title), ); echo '<span class="adagambar">' ; echo '<a href="' .get_attachment_link($attachment_id). '" rel="bookmark">' ; echo wp_get_attachment_image( $attachment_id, 'large', '', $arr_img ) ; echo '</a></span> '; echo '<center><strong>'. $alt_title .'</strong></center>';
  20.  
  21.             if ($i == 0) { break; } else {$i++;}
  22.  
  23.         }
  24.     }
  25. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement