• I would like to show the next/prev post link in a tooltip, i tried several options, but it won’t display it. The place is “SHOW POST TITLE HERE”.
    the code:

    <?php next_post_link('%link', '<span data-tooltip aria-haspopup="true" class="has-tip tip-bottom" title="SHOW POST TITLE HERE"><i class="fa fa-angle-left fa-2x"></i></span>
    '); ?>

    thnx in advance

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    next_post_link() doesn’t give you the opportunity to add a title attribute to the link it generates. You can only control the link text and what comes before and after the link, not what’s inside the anchor tag.

    There’s two obvious ways to get around this. One is to hook the ‘next_post_link’ filter and use PHP string functions to insert a title attribute before the closing ‘>’ of the anchor tag. You get the title from the $post object passed as the 4th parm to your filter callback.

    The other would be to use get_adjacent_post() to get the next $post object and construct the entire HTML anchor/href/title attribute/link text string yourself, then echo it out.

    Thread Starter myrok24

    (@myrok24)

    Moderator bcworkz

    (@bcworkz)

    Yes, they pull the title as link text, but not for the title attribute, the HTML looks like this:
    <a href='{$permalink}'>{$title}</a>

    My understanding is you want this:
    <a href='{$permalink}' title='{$title}'>{$title}</a>

    Yes? It’s this part that is not possible AFAICT: title='{$title}'

    Maybe I’m wrong, but I believe you need to work it as I first described to get the hover text to be something. There is one other way, by using javascript, but passing the title to javascript is just as convoluted as my first two solutions! I personally would use the get_adjacent_post() approach.

    Thread Starter myrok24

    (@myrok24)

    wow.. more complicated than i thought ??

    do mean something they use here ?

    <?php $prev_post = get_adjacent_post( true, '', true, 'taxonomy_slug' ); ?>
     <?php if ( is_a( $prev_post, 'WP_Post' ) ) { ?>
     	<a href="<?php echo get_permalink( $prev_post->ID ); ?>"><?php echo get_the_title( $prev_post->ID ); ?></a>
     <?php } ?>

    thnx

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Foundation tooltip and WP post_link’ is closed to new replies.