Search
 
SCRIPT & CODE EXAMPLE
 

PHP

wp $product add alt

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);

    $attr['alt'] = $title;
    $attr['title'] = $title;

    return $attr;
}
Comment

PREVIOUS NEXT
Code Example
Php :: wordpress disable php update required 
Php :: sync fetch eloquent laravel 
Php :: Yii2 Dynamic Relational Query 
Php :: user ,role ,permission customize laravel application 
Php :: numberformatter gujarati 
Php :: php getUserStateFromRequest 
Php :: PHP not echoing variables when print_r does 
Php :: dreamweaver laravel plugin 
Php :: has_post_format wordpress 
Php :: $this meaning in codeigniter 
Php :: php retrieve data from database and show in text area greeper 
Php :: dompdf setoptions breaks images 
Php :: php The function is a conversion from a key to a value 
Php :: error correction in qr code php 
Php :: SendEmailVerificationNotification::class 
Php :: wc php free shipping function 
Php :: get pages with tempalte wp 
Php :: one to one relationship laravel 
Php :: direct your index.php to your site page 
Php :: retrieve the order Id on Order pay page 
Php :: PHP code to redirect a user from a page to an alternate destination 
Php :: how to pass variable to an event listener laravel 
Php :: QR CODE FROM CAMCODES 
Php :: php cut after first sentence 
Php :: set php version in php.ini 
Php :: how to get file name in upload images in php 
Php :: laravel migrate patth 
Php :: laravel faker realtext 
Php :: register column types octobercms 
Php :: php type generic object 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =