First off: Interesting Question!
Second: you need to add the
<!--nextpage--> tag in your post one or multiple times. Else it won't work.
What this plugin does is intercepting the output of
get_permalink(), which is called internally by
get_permalink(), we got the
get_post_permalink() function that returns for custom post types. There we find the
'post_type_link'-filter and this is where we hook in.
Then we take the
global $pages, which holds an array of the post content splitted by the
<!--nextpage--> HTML comment. Our static variable is a counter that helps us determining which part we should return - based on the times the function was called (starting at
The last thing is that we append this part from
$pages to our post link. As the
esc_url() function intercepts our permalink and would mess up all our Uppercase letters, spaces, etc., we attach a single firing filter there too and just return the original string.
/** Plugin Name: (#67750) »kaiser« Append excerpt to post pagination */
* Callback for get_post_permalink() that is called by get_permalink() for
* custom post types. We append the $GLOBALS['pages'][ $current ] excerpt here.
* @param string $post_link The original posts page link
* @param object $post The post object
* @param mixed boolean/string $leavename
* @param mixed boolean/string $sample A sample link
* @return string $post_link
function wpse67750_pagination_excerpt( $post_link, $post, $leavename, $sample )
'YOUR_POST_TYPE' !== get_post_type()
OR ! in_the_loop()
OR ! is_singular()
static $n = 0;
// The global pages array: Contains the current post type pages
// We need a callback to reserve the original appended string
// not messed up by the esc_url() function.
add_filter( 'clean_url', 'wpse67750_pagination_url_cb', 10, 3 );
// The current page content
$curr = $pages[ $n++ ];
// Build the output
// Wrap it up for easy targeting via CSS and JS
// Also append a non visible single HTML tag to allow closing the still open anchor
$output = sprintf(
'"> %s <span class="excerpt" id="page-%s">%s</span><a style="display:none" rel="nofollow" href="#'
,trim( $curr )
/*$output = apply_filters(
// Append to the link
add_filter( 'post_type_link', 'wpse67750_pagination_excerpt', 10, 4 );
* The callback to preserve the string appended to the permalink
* @param string $url Escaped
* @param string $orig_url Not escaped
* @param string $context 'display'
function wpse67750_pagination_url_cb( $url, $orig_url, $context )
// Only run once
remove_filter( current_filter(), __FUNCTION__ );
// Return the non escaped original
The solution is not completely perfect. I hadn't got around getting rid of the first number and there seems to be a slight problem with retrieving the last link in some cases. It also had the problem, that core doesn't offer a possibility to get rid of the appended
</a> closing tag, so I had to add fake links there. Those don't get displayed, won't be followed by search engines and don't harm. They're just not beautiful, but that's the only possibility.