search

Home  >  Q&A  >  body text

Wordpress - Image title exists - Gutenberg doesn't automatically get it

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粉823268006P粉823268006342 days ago487

reply all(1)I'll reply

  • P粉908643611

    P粉9086436112024-01-17 11:46:30

    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"
            )
        );
    ...
    }
    

    reply
    0
  • Cancelreply