Advertisement
alchymyth

plugin title attr post thumbnail

Feb 13th, 2013
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Featured Image Title Attribute Output
  4. Plugin URI: n/a
  5. Description: adds the image title as the title attribute to the 'featured image' output.
  6. Version: 1.0
  7. Author: alchymyth
  8. Author URI: http://forum.wpde.org/mitglied/23424-alchymyth.html
  9. License: GPL2
  10. */
  11.  
  12. add_filter('post_thumbnail_html','add_post_thumbnail_title_attribute',10,3);
  13.  
  14. function add_post_thumbnail_title_attribute($html, $post_id, $post_thumbnail_id) {  
  15.    
  16. if( $html == '' ) {
  17.     return $html;
  18. } else {
  19.     $out = $html;
  20.   $thumbnail_image = get_posts(array('p' => $post_thumbnail_id, 'post_type' => 'attachment'));
  21.  
  22.   if ($thumbnail_image && isset($thumbnail_image[0])) {
  23.  
  24.     $title = $thumbnail_image[0]->post_title;
  25.     if($title) {
  26.         $output = ' title="' . esc_attr($title) . '" ';
  27.         $out = str_replace( 'class=', $output . 'class=', $html );
  28.      } 
  29.   }
  30. }
  31. return $out;
  32. }
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement