• Resolved dfwgreg

    (@dfwgreg)


    Hi everyone,
    What’s the best way to remove attachment from a gallery? I’m making a WordPress photo gallery and the links have url/category/post-name/attachment/img-name

    I have %category%/%postname%-%postid% as my permalinks and I really don’t want to change them.

    Thanks,
    Gregory S.

Viewing 1 replies (of 1 total)
  • Thread Starter dfwgreg

    (@dfwgreg)

    Found a solution

    add_filter( 'attachment_link', 'wp_gallery_attachment_link', 10, 2 );
    function wp_gallery_attachment_link( $link, $id )
    {
        // If the attachment name is numeric, this is added to avoid page number conflicts
        $link = str_replace( 'attachment/', '', $link );
        $attachment = get_post( $id );
        $link = str_replace( '/' . $attachment->post_name . '/', '?attachment=' . $attachment->post_name, $link );
        return $link;
    }

    http://wordpress.stackexchange.com/questions/5015/attachment-url-rewrite

Viewing 1 replies (of 1 total)
  • The topic ‘Remove attachment from permalinks’ is closed to new replies.