How can I add title attributes to next and previous post link functions?

Update

As I deleted the Repo on GitHub, here’s a new answer.

add_filter( 'previous_post_link"https://wordpress.stackexchange.com/questions/13044/,"wpse13044_adjacent_post_link_tooltip', 10, 2 );
add_filter( 'next_post_link"https://wordpress.stackexchange.com/questions/13044/,"wpse13044_adjacent_post_link_tooltip', 10, 2 );
function wpse13044_adjacent_post_link_tooltip( $format, $link )
{
    $previous="previous_post_link" === current_filter();
    // Get the next/previous post object
    $post = get_adjacent_post(
         false
        ,''
        ,$previous
    );
    // Copypasta from cores `get_adjacent_post_link()` fn
    '' === $title = get_the_title( $post->ID );
        AND $title = $previous 
            ? sprint( __( 'Previous Post: %s"https://wordpress.stackexchange.com/questions/13044/,"your_textdomain' ), $title )
            : sprint( __( 'Next Post: %s"https://wordpress.stackexchange.com/questions/13044/,"your_textdomain' ), $title );

    $format = str_replace(
         'rel="'
        ,sprintf(
             'title="%s" rel="'
            ,$title
         )
        ,$format
    );

    return "<span class="some classes">{$format}</span>";
}

Leave a Comment