• Resolved amritanshu

    (@monk_amritanshu)


    I want to change the value of title attribute of attachment link of the image by caption.
    I am using following code. It works fine but when i turn on this

    Display all your gallery pictures in a cool mosaic.

    then the code stops working

    function oikos_get_attachment_link_filter( $content, $post_id, $size, $permalink ) {
    
            $attachment = get_post( $post_id);
            if ( $caption = $attachment->post_excerpt){
    
                $new_content = preg_replace('/title=\'(.*?)\'/', 'title=\'' . $caption . '\'', $content );
                return $new_content;
            } else {
                return $content;
            }
        }
    
        add_filter('wp_get_attachment_link', 'oikos_get_attachment_link_filter', 10, 4);

    https://wordpress.org/plugins/jetpack/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    I’m afraid I have some bad news.

    Jetpack’s Tiled Gallery module modifies the default WordPress gallery output to be able to create the Tiled effect, so I’m afraid you won’t be able to customize the image link attributes, unless you deactivate the Tiled Gallery module under Jetpack > Settings in your dashboard.

    Thread Starter amritanshu

    (@monk_amritanshu)

    @jeremy Herve thanks for replying.

    I can’t do that as i ll not be able to use the tiled effect then,,,

    so i made the change in the file directly that generated this output.

    file is wp-content\plugins\jetpack\modules\tiled-gallery\tiled-gallery\templates\partials\items.php

    just changed the line no 4

    <a href="<?php echo $item->link; ?>" border="0" caption="<?php echo esc_attr( $item->image->post_excerpt ); ?>" >

    added the caption attribute

    will the changes be rewritten every time the jetpack is updated?

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    will the changes be rewritten every time the jetpack is updated?

    Yes, they indeed will be overwritten.

    Could you let me know why you’d like to make those changes? Do you think these changes should be made for all Jetpack users?

    Thread Starter amritanshu

    (@monk_amritanshu)

    @jeremy Herve I was customizing a theme for the client.They were already using the tiled gallery and for each image they are using formstone modal overlay.

    They want to show the caption below the image, which comes from the title attribute of the anchor.They could have written the text they wanted to show in the title instead of the caption..But they didn’t i am struck.

    So i need to put the value of caption in the title attribute or add new attribute caption.

    In short i want to edit the html generated by the tiled gallery.

    When there is filter to edit html of normal gallery then why is there no filter to edit html of tiled gallery.

    Don’t you think it should be there?

    Yup i think there should be some kind of filter to edit the html

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    When there is filter to edit html of normal gallery then why is there no filter to edit html of tiled gallery.

    Unfortunately you can’t edit the gallery HTML twice. When one filter takes over the gallery, the other can’t do the same, since the gallery doesn’t use the default HTML structure anymore.

    I’m afraid your only work-around is to edit the Jetpack plugin files, as you’ve done, or deactivate the tiled gallery module.

    Thread Starter amritanshu

    (@monk_amritanshu)

    🙁

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Unable to use wp_get_attachment_link filter for jetpack tiled galleries’ is closed to new replies.