Content only on last page, if the page has pagination

Instead of using the global variables directly, here’s a way to use the content_pagination filter to add custom HTML to the last content page:

/**
 * Append HTML to the last content page, if it's paginated 
 */
add_filter( 'content_pagination', function( $pages )
{
    if( count( $pages ) > 1 )
        $pages[count($pages)-1] .= '<div>MY HTML HERE!</div>';

    return $pages;
} );

This appends the custom HTML to all last content pages, where there is content pagination.

Update: To include posts without content pagination, we can e.g. replace > 1 with > 0.