0

I want to add a custom link to a last <!--nextpage-->.

For example this is the page:

Slide 1 <!--nextpage--> Slide 2 <!--nextpage--> Slide 3 <!--nextpage--> <- I want the **nextpagelink** in this last **nextpage** to redirect to a custom page

I am assuming the edits have to be done in wp_link_pages.

I have added end in the $defaults array.

'end' => '<a href="www.google.com">',

And I added an if statement

if ( $next = $numpages) {
    $link = _wp_link_page( $next ) . $r['link_before'] . $r['end'] . 
      $r['link_after'] . '</a>';
        }

But its not working

The full function is below:

function wp_link_pages( $args = '' ) {

global $page, $numpages, $multipage, $more;

$defaults = array(
    'before'           => '<p class="post-nav-links">' . __( 'Pages:' ),
    'after'            => '</p>',
    'link_before'      => '',
    'link_after'       => '',
    'aria_current'     => 'page',
    'next_or_number'   => 'next',
    'separator'        => ' ',
    'nextpagelink'     => __( 'Next page' ),
    'end'              => '<a href="www.google.com">',
    'previouspagelink' => __( 'Previous page' ),
    'pagelink'         => '%',
    'echo'             => 1,
);

$params = wp_parse_args( $args, $defaults );

/**
 * Filters the arguments used in retrieving page links for paginated posts.
 *
 * @since 3.0.0
 *
 * @param array $params An array of arguments for page links for paginated posts.
 */
$r = apply_filters( 'wp_link_pages_args', $params );

$output = '';
if ( $multipage ) {
    if ( 'number' == $r['next_or_number'] ) {
        $output .= $r['before'];
        for ( $i = 1; $i <= $numpages; $i++ ) {
            $link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after'];
            if ( $i != $page || ! $more && 1 == $page ) {
                $link = _wp_link_page( $i ) . $link . '</a>';
            } elseif ( $i === $page ) {
                $link = '<span class="post-page-numbers current" aria-current="' . esc_attr( $r['aria_current'] ) . '">' . $link . '</span>';
            }
            /**
             * Filters the HTML output of individual page number links.
             *
             * @since 3.6.0
             *
             * @param string $link The page number HTML output.
             * @param int    $i    Page number for paginated posts' page links.
             */
            $link = apply_filters( 'wp_link_pages_link', $link, $i );

            // Use the custom links separator beginning with the second link.
            $output .= ( 1 === $i ) ? ' ' : $r['separator'];
            $output .= $link;
        }
        $output .= $r['after'];
    } elseif ( $more ) {
        $output .= $r['before'];
        $prev    = $page - 1;
        if ( $prev > 0 ) {
            $link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>';

            /** This filter is documented in wp-includes/post-template.php */
            $output .= apply_filters( 'wp_link_pages_link', $link, $prev );
        }
        $next = $page + 1;
        if ( $next < $numpages ) {
            if ( $prev ) {
                $output .= $r['separator'];
            }
            $link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . '</a>';

            /** This filter is documented in wp-includes/post-template.php */
            $output .= apply_filters( 'wp_link_pages_link', $link, $next );
        } if ( $next = $numpages) {

            $link = _wp_link_page( $next ) . $r['link_before'] . $r['eog'] . $r['link_after'] . '</a>';

        }
        $output .= $r['after'];
    }
}',

`

  • If you're doing that for a link in a JavaScript slide, you could simply use JavaScript to set the custom link URL. :) – Sally CJ Apr 4 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.