Woocommerce alt en title tags automatisch aanpassen
Deze code past automatisch de alt- en title-attributen aan van afbeeldingen die gekoppeld zijn aan WooCommerce-producten.
Concreet: als je ergens op je site een afbeelding van een product ophaalt via WordPress (wp_get_attachment_image() of via de standaard weergave), dan zorgt deze functie ervoor dat de afbeelding altijd:
een alt-tag krijgt met de titel van het product, en een title-tag krijgt met diezelfde titel van het product.
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;
}
Overige handleidingen
- Office 365 mail instellen op IOs (iPhone/iPad)
- Windows Hello aanmeld optie verwijderen bij het inloggen op je PC
- Redis Cache inschakelen op Wordpress
- Office365 14-dagen Azure AD Multi-Factor Authentication (MFA) melding uitschakelen
- IMAP mailbox toevoegen Outlook
- Composer installeren op een Mac
- Office 365 instellen op Gmail app (Android)
- Foutcode 801c000e oplossen: te veel apparaten of gebruikers voor dit account
- Office 365 mail instellen op Android (Outlook)
- Loopt je All-in-One WP Migration vast? Verhoog PHP execution time en limieten
- Visual Studio Code Live Share
- E-mail instellen in Windows mail voor Exchange
- Office 365 instellen op Outlook 2013/2016
- Office365 Multi-Factor Authentication (MFA) inschakelen met je telefoon
- Opstarten map vinden in windows 11
- Multi-Factor Authenticatie onthouden op trusted device
- Office 365 instellen op uw MAC
- 2FA login instellen in Wordpress met Wordfence
- Powershell commando's om een kopie van verzonden mail in de gedeelde mailbox achter te laten
- Woocommerce alleen gratis verzending weergeven als deze beschikbaar is
- Geen gratis verzending op bepaalde producten in Woocommerce
- Office 365 mail instellen op iPhone (Outlook)