Wordpress - Image title exists - Gutenberg doesn't automatically get it
P粉823268006
P粉823268006 2024-01-16 21:17:02
0
1
440

Before asking this question, I paid for 9 hours from 10:00 am to 20:00 pm :( I tried everything...but no luck.

Well, I have set the image information: alt text, title, caption, description

gutenberg editor can get Alt text, image title but missing "Title" in Advanced -> Title Properties tab.

How do I get Gutenberge to get the title from the image post_id without having to manually rewrite it again? Thanks...

P粉823268006
P粉823268006

reply all(1)
P粉908643611

I tested adding an image with a title setting in WordPress 6.2 and confirmed that the title attribute is not added by default.

While looking at the source code, I noticed that the title key was not included in the pickRelevantMediaFiles - although image-block and title are universal use. Seems to be related to the Publish Featured Image: Add Title Attribute #46880 PR on GitHub (currently blocked at the time of writing).

A potential solution could be extending the image block's edit() function to include title For example:

export const pickRelevantMediaFiles = ( image, size ) => {
    const imageProps = Object.fromEntries(
        Object.entries( image ?? {} ).filter( ( [ key ] ) =>
            [ 'alt', 'id', 'link', 'caption', 'title' ].includes( key ) 
            // Added 'title' to prevent value being "undefined"
        )
    );
...
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!