• Resolved s151675

    (@s151675)


    Hi,
    I want the wordpress gallery images be displayed in a lightbox. Its working but only if the gallery image is linking to the file and not the attachment-site.
    WP always links automatically to the attachement site. How can I change this standard behaviour?
    Thx

Viewing 6 replies - 1 through 6 (of 6 total)
  • To update the default link type of images moving forward, you can do this by accessing your site options at yourdomain/wp-admin/options.php

    Scroll down and find the image_default_link_type field. You have 4 choices:

    1. none – This links back to the post it was uploaded to
    2. file – This links to the image file in your wp-content/uploads folder
    3. post – This links back to the post it was uploaded to
    4. attachment – This links to an attachment post generated by WordPress for all image files uploaded to a post

    You can also do this with a function in functions.php:

    function mytheme_setup() {
     update_option('image_default_link_type', 'file' );
    
    }
    add_action('after_setup_theme', 'mytheme_setup');

    Here’s a video I created that outlines how the Function above works and how to install on your WordPress site:

    Thread Starter s151675

    (@s151675)

    Is it important where in the functions.php this strip is located? I need to change the word mytheme with the name of mine true?
    Does this affect gallerys too?
    Thx

    You don’t have to change the Function name. You can, as long as it’s the same in both places. Also, it does not matter where you add this function to your theme’s functions.php file. Sometimes you have to add a function before calling the filter, and a priority order, but it should not matter with this function.

    On testing, however, I see that I was mistaken on this functionality working for image galleries, it does not.

    To update the default image linking behavior for image galleries, please use this function:

    add_filter( 'shortcode_atts_gallery',
        function( $out ){
            $out['link'] = 'file'; 
            return $out;
        }
    );

    Here is an updated video outlining the new Function, and how it works with the default linking behavior for galleries on a new install of WordPress:

    • This reply was modified 6 years, 4 months ago by cleancoded.

    I tried the same thing on my blog, but it did not work so I installed a custom plugin for galleries. It was way easier and they look better anyway.

    Thread Starter s151675

    (@s151675)

    Another plugin is not good for me. I want postie creating the gallery. It’s just working with the normal galleries

    I try adding the function. Thx anyway

    Thread Starter s151675

    (@s151675)

    @cleancoded You are my hero… its working well!!!! Thx a lot

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Standard of wordpress Gallery’ is closed to new replies.