Support » Plugins » Hacks » More classes at previous_post_link

  • At the moment my php knowledge isn’t very high. Even then the WordPress CMS is very well build and easy to understand for a newbie.

    One thing im stuck on for a while now is the possibility to add extra classes to the previous_post_link and next_post_link.

    My code is like this atm:
    <?php previous_post_link( ‘%link’, __( ‘<span class=icon-chevron-left></span> Vorige’ ) ); ?>

    I would like to add another class to the string but when i use ‘.’ like WordPress is using at other spots it will put the second class outside the class=””.

    Can anyone help me with this issue? I think there sould be an simple solution for it.

Viewing 6 replies - 1 through 6 (of 6 total)
  • esmi


    Forum Moderator

    Why do you need to add an extra class?

    I am using the Bootstrap framework with WordPress and it uses object orientated css. I am a big fan of OOC because it will keep the CSS clean and structured when a website is growing large.

    In my specific case I am using a spriteset (glypthicons) what is already integrated in the Bootstrap framework. With the class=icon-chevron-left I call an arrow icon background image. With another class (icons-white) in my case i can make the background white.

    The quickfix would be to overwrite the bootstrap class in styles.css. But I want to prevent that since the best solution is a extra class so the stylesheets will be as slim as possible and the style.css wont get filled with unnecessary styles.

    I hope someone can help me out 🙂



    Forum Moderator

    have you tried:

    <?php previous_post_link( '%link', __( '<span class="icon-chevron-left icons-white"></span> Vorige' ) ); ?>

    but when i use ‘.’ like WordPress is using at other spots

    if the above does not work, could you post exactly what you have tried?

    That was the first thing I tried. When I put the code like that and inspect the code with firebug the output is like this:

    a rel=”next” href=”url..”>Volgende <span icon-white=”” class=”icon-chevron-right”></span>/a

    I use WordPress 3.5 and the only relevant code I changed for the buttons is:
    <?php previous_post_link( ‘%link’, __( ‘<span class=icon-chevron-left icons-white></span> Vorige’ ) ); ?>

    In my functions.php I use extra code to put a class on the anchor:
    function single_btn_add_class($format){
    $format = str_replace(‘href=’, ‘class=”btn btn-small btn-info” href=’, $format);
    return $format;
    add_filter(‘next_post_link’, ‘single_btn_add_class’);
    add_filter(‘previous_post_link’, ‘single_btn_add_class’);

    It seems so simple but ive been trying all sort of things and searching on the WordPress forums for similar cases.



    Forum Moderator

    have you noticed and tried the double-quotes in my version:

    <span class="icon-chevron-left icons-white">

    vs your version:

    <span class=icon-chevron-left icons-white>

    It works now, thank you! When I tried the double-quotes my HTML editor is calling for a error in the code because of the ‘at the span’ but I ignored it now and it works without php errors 🙂

    EDIT: I have to say I tried to fill in single quotes what was triggering the error I understand now why next time I’ll use double quotes.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘More classes at previous_post_link’ is closed to new replies.