[Resolved] WP 3.5 – set title for image when inserting media
Hopefully someone will be able to help me with this and it’ll be an easy fix! In the previous version of WP I had changed the code so that when I inserted a new image into a post, the title which is shown in the media manager would be set as the title for the image inserted into the post.
With the upgrade to WP 3.5 the media manager has changed and I’m not sure how to get that back. The php code that does the actual inserting of html into the post appears to be wp-admin/includes/media.php. I’ve edited the get_image_send_to_editor function so that it does output the title where I want it, but I have to statically set the title. I would like the title to be taken from the media manager Title field for the image.
I’ve traced back to the file ajax-actions.php which is in wp-admin/includes, the function wp_ajax_send_attachment_to_editor, appears to be what sets up the variables that are used by the media.php file to output the code. In that function there’s this line:
$title = ”; // We no longer insert title tags into <img> tags, as they are redundant.*/
I’ve tried putting in code such as:
$title = $attachment[‘post_title’]
but it doesn’t work. If I put in this code:
$title = isset( $attachment[‘image_alt’] ) ? $attachment[‘image_alt’] : ”;
It works and the html inserted into the post contains a title which is set to the alt field. But what I want is to set it to the title that’s shown in the media manager. Anyone know how I can do that?
- The topic ‘[Resolved] WP 3.5 – set title for image when inserting media’ is closed to new replies.