Custom Gallery HTML only working when images are attached to post/page

You’re not passing your attribute array to the shortcode_atts method. You’re passing in an uninitialized variable.

Your function starts with

function get_my_gallery_content ( $atts ) {

But then you don’t reference $atts again. The code is reading $attr, which is empty.

Change the line

), $attr, 'gallery'));

to

), $atts, 'gallery'));

You also need to change the following to match your argument variable name:

if ( isset( $attr['orderby'] ) ) {
    $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
    if ( !$attr['orderby'] )
        unset( $attr['orderby'] );
}

This code reads $attr but you’re passing in $atts. Make sure they all match.

Because the array is empty, the logic falls back to only retrieving the current post’s children. That’s why you’re only seeing those in your galleries.