Automate insertion of Image Alt text with RM focus keyword

#496747
  • Resolved Fredrick
    Rank Math free

    Hi all

    I have read the KB for automate insertion of focus keyword as image alt with Image attribute pro..

    But can someone please edit the below code to update IMAGE ALT as FOCUS KEYWORD only for those images not having IMAGE ALT TAG

    add_filter('wp_get_attachment_image_attributes', 'change_attachement_image_attributes', 20, 2);
    function change_attachement_image_attributes( $attr, $attachment ) {
    // Get post parent
    $parent = get_post_field( 'post_parent', $attachment);
    
    // Get post type to check if it's product
    $type = get_post_field( 'post_type', $parent);
    if( $type != 'product' ){
        return $attr;
    }
    
    /// Get title
    $title = get_post_field( 'post_title', $parent);
    
    if( $attr['alt'] == ''){
        $attr['alt'] = $title;
        $attr['title'] = $title;
    }
    
    return $attr;
    }  
Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    Custom code not entirely related to our plugin falls outside the scope of our support so if you are looking for some help with that you would need to post it in StackOverflow or other similar forums to get further assistance with that.

    Alternatively, you can hire a developer to create the custom code for your website per your requirements.

    Don’t hesitate to get in touch if you have any other questions related to our plugin.​​​

Viewing 1 replies (of 1 total)

The ticket ‘Automate insertion of Image Alt text with RM focus keyword’ is closed to new replies.