• I run a multi user site and its hard to get people to consistently not select the default options when making galleries. Namely attachment pages which really just ruins everything for my site.

    I thought about disabling attachment pages but that doesn’t solve the problem the way i need it to.

    So I need to get rid of the menu item entirely, or at least make it no longer the default.

    This issue only applies to galleries as you can set “media file” as the default for individual images.

    i tried this option but no dice…

    https://finkaboutit.com/how-to-get-rid-of-the-attachment-thing-on-your-images/

    I also tried adding a function to automatically add “media=file” to galleries but that disabled jetpack tiled galleries and i’m rather fond of that.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m not sure of a solution, but here’s a couple ideas.

    Use jQuery to set the attachment option to disabled once the page loads. Then no one can select it even though it’s still there.

    Hook ‘parse_request’ action and if the request is for a single image attachment send a location header (redirect) to the image URL contained in the attachment. Then it doesn’t matter if users select attachment.

    Hopefully one of these will work out for you.

    Thread Starter iadagraca

    (@iadagraca)

    Thank you for replying!

    Hmmm they both sound like good ideas, i’m not sure how to do the jQuery option but i think i know how to do the second one.

    Part of my concern is social network auto posting to sites like tumblr. Hopefully the second option will work for that just fine.

    That said could you explain the jQuery method in more detail?

    Thread Starter iadagraca

    (@iadagraca)

    https://wordpress.stackexchange.com/questions/135232/redirect-attachment-page-to-attachment

    I found a solution, i’m sure a lot of people have this issue and i found a page with the code before i tried tackling it myself XD

    Simply place this is on function.php

    function wpa_attachment_redirect(){
        if( is_attachment() ){
            $urlArr = wp_get_attachment_image_src($_GET['attachment_id'], 'full');
    
    		if(empty($urlArr))
    		$url = wp_get_attachment_url($_GET['attachment_id']);
    else
        $url = $urlArr[0];
    
    wp_redirect($url, 301); exit;
        }
    }

    Basically regardless of if attachment pages is selected it always redirects to the image. Even works with lightbox plugins and such. Its as if attachment pages don’t exist at all <3

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘I need to remove the attachment page menu item for galleries’ is closed to new replies.