Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Featured Image Title Attribute Output
- Plugin URI: n/a
- Description: adds the image title as the title attribute to the 'featured image' output.
- Version: 1.0
- Author: alchymyth
- Author URI: http://forum.wpde.org/mitglied/23424-alchymyth.html
- License: GPL2
- */
- add_filter('post_thumbnail_html','add_post_thumbnail_title_attribute',10,3);
- function add_post_thumbnail_title_attribute($html, $post_id, $post_thumbnail_id) {
- if( $html == '' ) {
- return $html;
- } else {
- $out = $html;
- $thumbnail_image = get_posts(array('p' => $post_thumbnail_id, 'post_type' => 'attachment'));
- if ($thumbnail_image && isset($thumbnail_image[0])) {
- $title = $thumbnail_image[0]->post_title;
- if($title) {
- $output = ' title="' . esc_attr($title) . '" ';
- $out = str_replace( 'class=', $output . 'class=', $html );
- }
- }
- }
- return $out;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement