The multipage setting is not something that happen via a query, it is handled only via global variables, inside the setup_postdata()
function.
The only thing you need is to increment a global variable and add your static content using the 'the_post'
hook that is fired at the end of that function.
Something like:
add_action('the_post', function(WP_Post $post) {
global $multipage, $numpages, $pages;
$multipage = 1; // ensure post is considered multipage: needed for single page posts
$numpages++; // increment number of pages
$pages[] = my_last_page_content($post); // set the static content for last page
});
There is no need for anything else, because wp_link_pages()
will understand that there is the mocked number of pages for current post and will act accordingly.
As you can see I used a custom my_last_page_content
function to create content for the last page. I passed to that function the post object, because maybe you need to build your “fake” page content, e.g. to get post title or permalink.
Below a rough example:
function my_last_page_content(WP_Post $post)
{
$format="<div><a href="https://wordpress.stackexchange.com/questions/172466/%s"><i class="fa fa-twitter"></i> %s</a></div>";
$url="https://twitter.com/home?status="
. urlencode(__('New blog post: ', 'txtdomain'))
. '%22' . urlencode(apply_filters('the_title', $post->post_title)) . '%22'
. '%20' . urlencode(get_permalink($post));
return sprintf($format, $url, esc_html__('Share on Twitter', 'txtdomain') );
}