WordPress.org

Ready to get started?Download WordPress

Forums

Update image links from "link" to "file" (3 posts)

  1. Franz92
    Member
    Posted 1 year ago #

    Hello!
    I want to update all image links in articles. Currently they are linked to their attachment pages, I want to link them directly to the file to use a lightbox-style plugin.

    I found this code. It sets image links to "none" - that is nearly what I want, I want them to be set to "file" - is that possible?

    This is the "remove"-code:

    add_filter( 'the_content', 'attachment_image_link_remove_filter' );
    function attachment_image_link_remove_filter( $content ) {
     $content =
     preg_replace(
     array('{<a(.*?)(wp-att|wp-content/uploads)[^>]*><img}',
     '{ wp-image-[0-9]*" /></a>}'),
     array('<img','" />'),
     $content
     );
     return $content;
     }

    Thank you very much for your answer!

  2. I want to link them directly to the file to use a lightbox-style plugin.

    Which plugin? Usually the plugin will take care of the displaying of the image in a lightbox without having do play with filters like that.

  3. Franz92
    Member
    Posted 1 year ago #

    Hey!
    Thanks for your reply. It is "FancyBox for WordPress", running on aktuelles-bodensee.de

    Did that help?

Topic Closed

This topic has been closed to new replies.

About this Topic