Add class to links generated by next_posts_link and previous_posts_link
These two functions create anchor links, and you can customize a lot of it, but it's impossible to add a class through just using their parameters alone. Gotta add a function to functions.php:
add_filter('next_posts_link_attributes', 'posts_link_attributes');
add_filter('previous_posts_link_attributes', 'posts_link_attributes');
function posts_link_attributes() {
return 'class="styled-button"';
}
Once again, thanks! I changed this a bit to accommodate different styles for next/previous. Here is what I did in case anyone else needs to have a class for each:
Thanks Chris! Loved your method!
another way to do this without a function would be to class an LI around each link:
brent
@
mimoYmima.com
check out our wordpress shell – html5.mimoymima.com
I like Brent’s method, except I used … as a wrapper around each link instead of tags. I was lazy and didn’t feel like writing the extra CSS for the list items, but worked just as well.
I like Brent’s method, except I used span tags to wrap around each link instead of li tags. I was lazy and didn’t feel like writing the extra CSS for the list items, but worked just as well.
I cannot get the ul/li approach to work. Styling is fixed what ever I do …. any ideas what I am doing wrong?
Is it also possible to generate an “last_posts_link” ? If you have for example 5 result pages, you would jump to page 5 immediately..
wp pagenavi uses it, but I won’t want to use that plugin.
I liked Brent’s way of doing.
Hi, thanks much!
This solved half of my “problems”.. any idea how to add custom styles to
next/previous_post_link? I tried the obvious way of addingnext_post_link_attributes, but it didn’t work.Any help appreciated :]