https://github.com/nash-ye/wp-conditional-themes
A simple API to switch the themes on certain conditions.
https://github.com/nash-ye/wp-conditional-themes
wordpress wordpress-plugin
Last synced: about 1 year ago
JSON representation
A simple API to switch the themes on certain conditions.
- Host: GitHub
- URL: https://github.com/nash-ye/wp-conditional-themes
- Owner: nash-ye
- License: gpl-2.0
- Created: 2013-10-16T22:52:05.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2019-07-21T15:17:43.000Z (almost 7 years ago)
- Last Synced: 2025-04-15T23:02:43.310Z (about 1 year ago)
- Topics: wordpress, wordpress-plugin
- Language: PHP
- Homepage: https://wordpress.org/plugins/wp-conditional-themes/
- Size: 27.3 KB
- Stars: 17
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
WP Conditional Themes
=====================
A simple API to switch the themes on certain conditions.
Usage
==============
Write an another plugin file and use the Conditional Themes API as the example below:
```
add_action('plugins_loaded', 'my_conditional_themes_setup', 100);
function my_conditional_themes_setup()
{
// Switch to Twenty Eleven theme if the visitor use Internet Explorer.
Conditional_Themes_Manager::register('twentyeleven', function() {
global $is_IE;
return (bool) $is_IE;
});
// Switch to Twenty Thirteen theme if the user has administrator role.
Conditional_Themes_Manager::register('twentythirteen', function() {
return current_user_can('administrator');
});
// Switch to a custom theme if the visitor use a mobile device.
Conditional_Themes_Manager::register('mobile', 'wp_is_mobile');
}
```
Another example, With enabling persistent mode.
```
add_action('plugins_loaded', 'my_conditional_themes_setup', 100);
function my_conditional_themes_setup()
{
// Enable the switcher persistent mode.
Conditional_Themes_Manager::set_option('persistent', true);
// Switch to Twenty Sixteen theme when we being on 2016.
Conditional_Themes_Manager::register('twentysixteen', function() {
return (date('Y') == 2016);
});
// Switch to Twenty Fifteen theme when the site reaches 500 post.
Conditional_Themes_Manager::register('twentyfifteen', function() {
return ((int) wp_count_posts() > 500);
});
}
```