WordPress.org

Ready to get started?Download WordPress

Forums

Media Library Assistant
[resolved] set the product category as alt and title tag for all images (7 posts)

  1. Dana S
    Member
    Posted 2 months ago #

    I just discovered your plugin and haven't yet figured out how to set the alt and title tags for images.

    The images whose alt and title tags I'm trying to set are for product images within my woocommerce powered site. .

    I would like to use the first category (highest parent category) of the product for the alt and title of every image.

    So if the image is on a product page under (shop>tvs>cheap tvs>used tvs>product page), I would like the alt and title for the image to be "tvs". If using the parent category isnt possible, I would be happy even if I could use all categories pertaining to a particular product as the alt and title for all images.

    Alternatively, If setting the category as the alt/title for every image isnt possible, what about the tags pertaining to the product the image is on. I'm still learning your plugin, but I can tell your plugin is awesome. :) Thanks, Dana

    https://wordpress.org/plugins/media-library-assistant/

  2. David Lingren
    Member
    Plugin Author

    Posted 2 months ago #

    Thank you for the good words about MLA and for your question.

    I haven't looked too closely at WooCommerce, so I don't know exactly how to identify the "product images", but I am confident you can accomplish your task with the "MLA Custom Field and IPTC/EXIF Mapping Actions and Filters (Hooks)" (see the Settings/Media Library Assistant Documentation tab for more information). Here are some earlier support topics along the lines of your request:

    Transferring tagged images from another plugin?

    The custom plugin for the above topic is in the /media-library-assistant/examples/mla-media-tagger-example.php.txt file.

    Taxonomy term mapping only if term already exists

    Pull Featured Image from MLA Gallery

    Have a look at those topics and tell me if they make sense to you. You will have to write a bit of PHP code, but I can give you more specific help with that if you agree that the overall approach will work for you. Let me know if you want to proceed and I'll do a bit more research.

  3. Dana S
    Member
    Posted 2 months ago #

    Thanks for your reply :)

    I took a look at your references, but I’m not sure if they are what I’m looking for; they might be, but I just need to familiarize myself better with the terminology.

    I went to the plugin area (IPTC & EXIF Processing Options). For the alt and title field names, I chose (2#015 category). I chose “replace” existing text for both fields. I saved the settings. Then I pressed the “Map All Attachments, Standard Fields Now” button. Neither the title nor alt tags for images changed. I assuming there was no change, because “categories” isn’t referencing “product categories”.

    I know your busy, but if you’re interested I let you log into my wordpress site. I’m not sure how to pm you, but let me know and I can send you login details of my wordpress site.

    Further information:

    My images have regular tags that aren’t dependant on any plugin. All my images have the image name (example.jpg) for the image Meta title. All alt fields are blank. I have considered several ways to place the product category as the alt tag, but the easiest thing to do seems to be figuring out what code/page is responsible for grabbing the alt tag. If I can isolate that code, maybe I could force the alt tag to use the product page meta title or category, instead of referencing the meta alt/title inputted in the media library.
    For example, the following code (in wp-content/…/…/woocommerce/single-product/meta.php) is responsible for display the products category on any given product page:

    <?php $size = sizeof( get_the_terms( $post->ID, 'product_cat' ) ); echo $product->get_categories( ', ', '<span class="posted_in">' . _n( '', '', $size, 'woocommerce' ) . ' ', '.</span>' ); ?>

    If I could just find what code is responsible for the product image alt tag, maybe I could do something like this:

    alt=”<?php $size = sizeof( get_the_terms( $post->ID, 'product_cat' ) ); echo $product->get_categories( ', ', '<span class="posted_in">' . _n( '', '', $size, 'woocommerce' ) . ' ', '.</span>' ); ?>”

    I can tell that your plugin is capable of achieving what I’m hoping for, but maybe I just need to spend more time with it. Thanks :)

  4. David Lingren
    Member
    Plugin Author

    Posted 1 month ago #

    Thanks for posting your response, for reading through the earlier topics I suggested, for the offer to give me access to your site and for taking the time to go through the WooCommerce (Woo for short) code and include the references to "product_cat". You're on the right track but you have a ways to go.

    I set up a WooCommerce site with one product and poked around a bit. Here are my initial findings, which you may already know:

    1. Woo creates custom taxonomies product_cat (Product Categories) and product_tag (Product Tags).
    2. Woo creates a custom post type for products.
    3. Woo uses the "Featured Image" of the custom post type for the "product image".
    4. Woo assigns Product Category values to the Product custom post type.
    5. Woo does NOT assign Product Category values to the "product image" itself, in the Media Library. However, you can assign values manually.
    6. Woo also supports a "Product Gallery" with one or more additional images.

    I know you've started a separate topic regarding the Product Gallery images - I will get to that soon. Regarding this topic, do you want to set Title and ALT Text values for the gallery images, or just the Featured Image/Product Image?

    I may have confused you with my suggestion regarding the mapping hooks, so I'd like to clarify how MLA works in response to your comment:

    I went to the plugin area (IPTC & EXIF Processing Options). For the alt and title field names, I chose (2#015 category). I chose “replace” existing text for both fields. I saved the settings. Then I pressed the “Map All Attachments, Standard Fields Now” button. Neither the title nor alt tags for images changed.

    The IPTC/EXIF meta data mapping functions are designed to extract meta data embedded in the image files by tools such as Adobe PhotoShop. Unless you've done that, the mapping rules won't help you. However, the hooks give you an easy way to go through the images in the Media Library and do something with them by writing PHP code.

    In this case, what you really need to do is go through the Woo Product custom post types, find the Featured Image for the post and then modify the Title and ALT Text of the image. Does that make sense?

    A couple of questions occur to me:

    1. Does each Product Image appear in only one Product? WordPress allows you to use the same image in more than one post/page, but your replacement strategy only makes sense if the Product Images are unique.
    2. Do you want to actually replace the Title and ALT Text values, or just display the alternative in a particular context? In other words, why are you doing this?
    3. Is this a one-time, all products/images fix, or do you want some automatic way of making the change each time an image is assigned to a Product?

    At this point I think you need a small custom plugin if you want to actually modify the image Title/ALT Text values, or a modification to your theme if you just want to display something different in a particular part of your site.

    I can work with you on either of those alternatives. The best way to proceed would be by e-mail; I can update this topic when we've reached a conclusion. If that suits you, contact me and I will give you an e-mail address you can use to send more information. You can use the Contact Us page at our web site:

    Fair Trade Judaica/Contact Ushttp://fairtradejudaica.org/our-story/contact-us/

    Thanks for you interest and your patience. Please get in touch if you think I can help.

  5. Dana S
    Member
    Posted 1 month ago #

    The support you've provided already is exceptional; Thank You! I will contact you with answers to your questions via the information provided and see if there is a simple fix for what I'm trying to do.

  6. David Lingren
    Member
    Plugin Author

    Posted 3 weeks ago #

    Dana,

    Thanks for getting in touch via the FTJ web site and for working with me on the "WooTools" custom plugin. I am happy to hear that it has given you the tools you needed to clean up and organize the Product pages on your site.

    I am marking this topic resolved, but please let me know if you have any problems with or questions about the custom plugin.

    Thanks for your interest in the Media Library Assistant.

  7. Dana S
    Member
    Posted 3 weeks ago #

    Thanks again David! You've exceeded my expectations with your wonderful support and plugin! Not only did you resolve my topic, but You've went out of your way to provide me with tools to achieve my goals with the website in question and more.

Reply

You must log in to post.