user3550879 user3550879 - 7 months ago 29
PHP Question

adding div to navigation - Wordpress

In the functions.php of my Wordpress site creates the back/next buttons

<?php if ( is_single() ) : // navigation links for single posts ?>

<?php next_post_link( '<div class="nav-next">%link</div>', '<span class="fa fa-chevron-right"></span>' . _x( '', 'Previous post link', 'bnNav' ) ); ?>
<?php previous_post_link( '<div class="nav-previous">%link</div>', _x( '', 'Next post link', 'bnNav' ). '<span class="fa fa-chevron-left"></span>'); ?>


...

which outputs

<nav id="nav-below" class="post-navigation" role="navigation">
<div class="nav-next">
<a rel="next" href="http://localhost/wordpress/?p=369">
</div>

<div class="nav-previous">
<a rel="prev" href="http://localhost/wordpress/?p=104">
</div>
</nav>


I want to put another div inside each div inside the .nav but not sure how to add it to the code in my functions.php

I WANT the output to be

<nav id="nav-below" class="post-navigation" role="navigation">
<div class="nav-next">
<div id="arrow-right"></div>
<a rel="next" href="http://localhost/wordpress/?p=369">
</div>

<div class="nav-previous">
<div id="arrow-left"></div>
<a rel="prev" href="http://localhost/wordpress/?p=104">
</div>
</nav>

Answer

Try to use the following code:

<?php if ( is_single() ) : // navigation links for single posts ?>

    <?php next_post_link( '<div class="nav-next"><div id="arrow-right"></div>%link</div>', '<span class="fa fa-chevron-right"></span>' . _x( '', 'Previous post link', 'bnNav' ) ); ?>
    <?php previous_post_link( '<div class="nav-previous"><div id="arrow-left"></div>%link</div>', _x( '', 'Next post link', 'bnNav' ). '<span class="fa fa-chevron-left"></span>'); ?>

Simply add the new <div> before the %link.