In 2023 I revamped my WordPress theme to include Daisy UI. In this article, I will show you how to change the default styles of the popular WordPress Page Navi plugin to use the styles created by Daisy UI without editing the plugin.
The WP-PageNavi WordPress plugin has been around for more than 16 years and it is popular enough that theme developers started to include support for it. It’s been a favourite for users ever since.
Here are some key features and details about WP-PageNavi:
previous_posts_link()
and next_posts_link()
functions in your theme with the plugin’s wp_pagenavi()
function.Please note: This has been tested on a traditional classic theme build. I do not recommend implementing this on your production/live version of WordPress.
If you want to experiment I recommend Local, by Flywheel. Local is a cross-platform WordPress development environment. You can either download your current theme or use a starter theme. I’m a big fan of Blank Slate. I also used Node and installed Tailwind Mix to compile the necessary CSS.
To get started with Tailwind Mix you may find Build an Awesome Daisy UI WordPress Theme – Part 1 useful. You will also need the page-navi plugin installed.
To disable the CSS go to the WordPress dashboard and click on Settings -> Page-Navi. Go to the section Page-navigation options and select No in Use pagenavi-css.css.
Below is a screenshot of my current settings for the plugin which works for me. I recommend using these options and testing others to get the correct format you need.
To use Daisy UI you need to use WordPress filters to change the CSS classes. Daisy uses several other components including joins and buttons to create the pagination. Take a look at Daisy UI’s pagination page for more details.
Add the following to functions.php
/********
* Change page-navi css classes
* */add_filter('wp_pagenavi_class_previouspostslink', 'theme_pagination_class');
add_filter('wp_pagenavi_class_nextpostslink', 'theme_pagination_class');
add_filter('wp_pagenavi_class_page', 'theme_pagination_class');
add_filter('wp_pagenavi_class_extend', 'theme_pagination_class');
add_filter('wp_pagenavi_class_current', 'theme_pagination_class');
add_filter('wp_pagenavi_wrapper_class', 'theme_pagination_class');
function theme_pagination_class($class_name)
{
switch ($class_name) {
case 'previouspostslink':
$class_name = 'join-item btn btn-outline';
break;
case 'nextpostslink':
$class_name = 'join-item btn btn-outline';
break;
case 'page':
$class_name = 'btn join-item';
break;
case 'extend':
$class_name = 'join-item btn btn-disabled';
break;
case 'current':
$class_name = 'btn btn-active';
break;
case 'wrapper_class':
$class_name = 'join';
}
return $class_name;
}
Here is a list of all the classes available.
If you don’t want to install a local development environment you have a few options. However, it also depends on your colour theme and your patience. You could use the Daisy UI theme customiser to create a theme similar to your current one.
You can then use a Tailwind playground to extract the generated CSS. If this method is used there will likely be more code than is needed and don’t forget to extract the CSS variables from the bottom of the base section and the component. See my example on Tailwind Play for reference.
Another option is to strip the CSS variables and manually assign your colours to the specific classes. Whatever you you choose it’s entirely up to you.
If you have found a better alternative to do this, or used another CSS framework or even rolled your own I would love to hear your thoughts.
Welcome to Hot Web Dev November 2024, featuring the latest technology and web development news.… Read More
Welcome to Hot Web Dev October 2024, featuring the latest technology and web development news.… Read More
In this tutorial, you’ll build a fun and interactive guessing game using Svelte 5, the… Read More
Welcome to Hot Web Dev September 2024, featuring the latest technology and web development news.… Read More
The JavaScript guessing game tutorial is a simple beginner's project. It features modern JavaScript syntax… Read More
If you have been following the monthly Hot Web Dev magazine you will find the… Read More