Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyphen automatically gets added on 'title' tag of image #8902

Closed
anupviews opened this issue Aug 12, 2018 · 9 comments
Closed

Hyphen automatically gets added on 'title' tag of image #8902

anupviews opened this issue Aug 12, 2018 · 9 comments
Labels
[Feature] Media Anything that impacts the experience of managing media [Type] Enhancement A suggestion for improvement.

Comments

@anupviews
Copy link

When I upload an image that has no hyphen (eg. round clock.jpg), it automatically adds hyphen in the title tag and appears as: round-clock. This had happened with previous version of WordPress and was fixed, but Gutenberg has this bug.

Please fix this.

@chrisvanpatten
Copy link
Member

@anupviews do you happen to know if there was a Core Trac ticket about this issue? I was under the impression that WordPress always normalised image filenames, but perhaps I'm wrong :)

@chrisvanpatten chrisvanpatten added the [Feature] Media Anything that impacts the experience of managing media label Aug 12, 2018
@chrisvanpatten
Copy link
Member

Oh, do you mean in generating the "title" attribute of the image?

A screenshot would be helpful here as well, if you have one!

@WPprodigy
Copy link
Contributor

WPprodigy commented Aug 13, 2018

I uploaded an image (image name.png) to a Gutenberg image block. Here is the frontend output (no title attribute):

<figure class="wp-block-image">
<img src="https://wpdev.test/wp-content/uploads/2018/08/image-name.png" 
  alt="" class="wp-image-73" 
  srcset="https://wpdev.test/wp-content/uploads/2018/08/image-name.png 1200w, https://wpdev.test/wp-content/uploads/2018/08/image-name-300x205.png 300w, https://wpdev.test/wp-content/uploads/2018/08/image-name-768x525.png 768w, https://wpdev.test/wp-content/uploads/2018/08/image-name-1024x700.png 1024w" 
  sizes="(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px">
</figure>

When clicking on the pencil icon in the block for the image though, I do see the hyphenated title:
edit-image

So a GB uploaded image is auto-hyphenating the image title, but it does not use the title attribute, which has been brought up here: #7504


I then uploaded a new image through just the media library in WP. This time, the image title was not auto-hyphenated

edit-image2


I believe the relevant trac ticket can be found here: https://core.trac.wordpress.org/ticket/37989

I've not done much digging, but this might be a core rest api issue rather than GB specific.

@WPprodigy
Copy link
Contributor

WPprodigy commented Aug 13, 2018

Ah yea, so the title is getting assigned while the image is being uploaded via the rest api here: https://github.com/WordPress/WordPress/blob/aab929b8d619bde14495a97cdc1eb7bdf1f1d487/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php#L143

Possible Solutions:

  1. See if the REST API should be handling this differently, and patch there (see media_handle_upload in core).
  2. Pass along the image title in Gutenberg when first uploading the image. Which I believe would be here: https://github.com/WordPress/gutenberg/blob/master/packages/editor/src/utils/media-upload/media-upload.js#L158.
  3. Both one and two? ¯\(ツ)

data.append( 'title', file.name.replace( /\.[^/.]+$/, '' ) );
should do the trick for the second option.

@anupviews
Copy link
Author

anupviews commented Aug 13, 2018

@chrisvanpatten I uploaded an image (file name without hyphen), and the editor adds title tag as follows:

screen shot 2018-08-13 at 9 21 18 pm 1

It automatically adds hyphenated title. I reported this issue with previously, but I don't remember which version had it.

And as @WPprodigy pointed out, it does not add title tag in frontend output even though I added something using the 'title' filed of the image:

screen shot 2018-08-13 at 9 36 50 pm

Edit: Found the trac ticket here: https://core.trac.wordpress.org/ticket/38090

@WPprodigy
Copy link
Contributor

Opened up a wp core issue as well, linking for reference: https://core.trac.wordpress.org/ticket/44789

@designsimply designsimply added the [Type] Enhancement A suggestion for improvement. label Aug 15, 2018
@nicopujol
Copy link

nicopujol commented Apr 13, 2019

Having this issue of hyphens in image file name and titles. Was there a fix or did it get reverted?
hyphens in file name
WordPress 5.1.1 with Gutenberg plugin 5.4.0

@WPprodigy
Copy link
Contributor

I vaguely remember the issue, but fairly sure your SS is expected behavior. The image name had hyphens on it when uploaded, so they will also be there in the title by default.

@nicopujol
Copy link

The Gutenberg editor is adding the hypens to the file name. When uploading images from a recipe plugin, for example, the issue does not occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Media Anything that impacts the experience of managing media [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

5 participants