• Hello,

    My wordpress blog has thousands of articles with galleries that link to the attachment page. I want the galleries’ images to link to the media file and not to the attachment pages. What should I do? Because I have thousands of galleries to convert and I can’t do that manually.

    Please take a look at the example of a gallery from one of the site’s articles: https://goo.gl/oUgZou

    I look forward to hearing from you so I can solve the problem asap.

    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter gemeweb

    (@gemeweb)

    I am still looking for a solution, thanks ??

    There is no simple way to do this – you could export the database and update the URL’s using regular expressions but without know how the galleries are setup, it might not even work if the data is serialized.

    Looks like you’re using a gallery plugin – have you tried contacting the plugin developer?

    Thread Starter gemeweb

    (@gemeweb)

    Hi Shannon, I don’t use a gallery plugin, all the galleries are created by default by wordpress. All the images from the galleries are linking to the attachment page. I need them to link to the media files and not attachment pages, but there are thousands of articles and very hard to do that manually. Can somebody help me to solve this? I am sure there is a way to do this.

    Ok, default gallery – I have just checked:

    Inserts into wp_posts (by default – which links to attachment page) as follows:

    [gallery ids="31,28,20,10"]

    OR
    Inserts into wp_posts (if you link to file) as follows:

    [gallery link="file" ids="31,28,20,10"]

    Therefore, if you were very, very careful and made a backup prior, you could issue the following MySQL statement directly into the database and it should work:

    UPDATE wp_posts SET post_content = REPLACE(post_content, '[gallery ids', '[gallery link="file" ids');

    Thread Starter gemeweb

    (@gemeweb)

    I’ve updated the database and it didn’t work. I get the same galleries linking to the attachment pages. How can I revert back? I mean to undo the update to the database. Thanks.

    Thread Starter gemeweb

    (@gemeweb)

    I’ve restored the database backup, dear Shannon. Is there any way to solve this? I am pretty sure there is a way to do this. Thanks.

    Thread Starter gemeweb

    (@gemeweb)

    Can somebody help me to solve this? Moderators? Thanks….

    Thread Starter gemeweb

    (@gemeweb)

    I’ve found a solution that works!

    Just added a filter in the media.php file

    CODE————————————–
    add_filter( ‘shortcode_atts_gallery’,
    function( $out ){
    $out[‘link’] = ‘file’;
    return $out;
    }
    ——————————————

    Hope it helps others! Thanks anyway!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How To Convert Posts’ Galleries To Link To Media File And Not To Attachment Page’ is closed to new replies.