• Hi guys, I’m trying to add the title tag to the title product thumbnails . In html would be as follows:

    <a href="#" title="Product Name"> Product Name </a>
    I managed to enter the thumbnail image but lack the link.
    follows the code I used to add the image:

    //Adiciona Tag Title nas imagem thumbnail
    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;
    }

    Could you tell me how to add it in the link ?

    https://www.ads-software.com/plugins/woocommerce/

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    Which image is this for? Please provide example link.

    Thread Starter bahl2

    (@bahl2)

    when moving the mouse over the title display the html title tag as it appears in the image.

    Image Ref:
    https://snag.gy/0afWsQ.jpg

    Thank you Friend

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Look at https://docs.woothemes.com/document/template-structure/

    content-product.php can be customised

    Thread Starter bahl2

    (@bahl2)

    Hello, thank you for Help.

    /* CREATE the new function */
    function woocommerce_template_loop_product_title_tag() {
    		global $product;
    		echo '<h3 style="color: red;" class="loop-title">' . get_the_title() . '</h3>';
    }
    /* ADD new loop-title-with sku action      */
    add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title_tag', 10 );

    I got it, find the get the hook. But not know how to catch it dirematemnte or edit the main , what I did then he add the title again but without link and my not remove deuc erto . How can I fix , by changing the < h3 > without intefrir the rest or add the title again with product link and remove the other ?

    Image information:

    https://snag.gy/IMaBS4.jpg

    Thank YOu!

    Plugin Contributor Mike Jolley

    (@mikejolley)

    I’m not sure what you’re asking here. You want to remove the links?

    Thread Starter bahl2

    (@bahl2)

    I want to add the title product with < h3 title = ” Title of the product” >

    Plugin Contributor Mike Jolley

    (@mikejolley)

    First you need to unhook our titles:

    remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );

    Then you can hook in your custom function:

    add_action( 'woocommerce_shop_loop_item_title', 'custom_product_loop_title', 10 );
    
    function custom_product_loop_title() {
    // code here
    }
    Thread Starter bahl2

    (@bahl2)

    Hello, Thank you for help.
    I am problems not work my code

    /* ADD new */
    remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
    
    add_action( 'woocommerce_shop_loop_item_title', 'custom_product_loop_title', 10 );
    
    function custom_product_loop_title() {
    		global $product;
    echo '<h3 title='.get_the_title().' style="color: blue;" class="loop-title">' . get_the_title() . '</h3>';}

    Result of the code:
    https://snag.gy/sHp1AD.jpg

    Could you help me with this? Is not removing the title and the new title do not have the link to the url product or the tag title that I want to work.

    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    Instead of using get_the_title() try using $product->post->post_title instead.

    This should fix your issue.

    Thread Starter bahl2

    (@bahl2)

    Thanks, I will try ! xD

    Thread Starter bahl2

    (@bahl2)

    Hi could help me as would using this way?
    I am a noob half still to programming and am learning slowly.

    Thank you

    Thread Starter bahl2

    (@bahl2)

    using $product->post->post_title

    Plugin Contributor Mike Jolley

    (@mikejolley)

    echo '<h3 title="'. esc_attr( $product->post->post_title ) .'" style="color: blue;" class="loop-title">' . get_the_title() . '</h3>';
    Thread Starter bahl2

    (@bahl2)

    Right! gave the title tag Thank you, only has a problem, remove the action does not work on killing the two titles.
    And I would acrescenter url link to the title the same image

    `

    help me please

    Thank you!

    Thread Starter bahl2

    (@bahl2)

    Right url! \o sucess!

    New error about remove the action does not work on killing the two titles.
    Not work Oo
    https://snag.gy/AvaDOW.jpg
    Image

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Add html tag " title " in the titles product links .’ is closed to new replies.