Add title attribute to next_post_link
This function adds the title and rel attribute to your internal navigation structure links. Note: Next_post_link is used for custom taxonomies and is different to next_posts_link.
/** * Snippet Name: Add title attribute to next_post_link * Snippet URL: https://wpcustoms.net/snippets/add-title-attribute-to-next_post_link/ */ function add_title_to_next_post_link($link) { global $post; $post = get_post($post_id); $next_post = get_next_post(); $title = $next_post->post_title; $link = str_replace("rel=", " title='".$title."' rel=", $link); return $link; } add_filter('next_post_link','add_title_to_next_post_link'); function add_title_to_previous_post_link($link) { global $post; $post = get_post($post_id); $previous_post = get_previous_post(); $title = $previous_post->post_title; $link = str_replace("rel=", " title='".$title."' rel=", $link); return $link; } add_filter('previous_post_link','add_title_to_previous_post_link');