The activated theme is stored in the options
table: template
is the parent theme, stylesheet
is the child theme. If there is no child theme the two values will be the same.
The current hostname (URL without protocol or path) is available in the $_SERVER
variable.
You can then hook into the stylesheet
and template
filters to force a different theme.
function use_mobile_theme( $current_theme ) {
// If the domain is m.qqq.com and the current theme is 'qqq'
if ( 'm.qqq.com' === $_SERVER['HTTP_HOST'] && 'qqq' === $current_theme ) {
// Use the 'qqq-mobile' theme instead
return 'qqq-mobile';
} else {
// Otherwise, keep the current theme
return $current_theme;
}
}
add_filter( 'stylesheet', 'use_mobile_theme' );
add_filter( 'template', 'use_mobile_theme' );
If qqq-mobile
is a child theme, remove the add_filter( 'template', ...
line.
Related Posts:
- What’s the earliest point I can get the queried object ID?
- Using a Theme inside a Plugin directory
- Hook in wp.media to add a new tab
- Overide get_template_part( ‘partials/post’, ‘sidebar’ ); with a plugin
- Using Primary Color in Plugin Block
- Plugin development without Theme adjustments?
- What is the best way to provide plugin users with a way to customized the styles
- How to properly use a hook to create template for custom product type in a plugin such as Woocommerce? [closed]
- Fully automated theme install and activation via a plugin
- Calling plugins API within a theme
- Hook into theme-switching later than `setup_theme`
- WordPress security issue to output data from user input from theme option form
- Which themes do you use to test compatibilities with your plugin [closed]
- How to Debug: My Plugin Interferes With My Theme
- Theme Install using a Custom Repository
- How to serve different thumbnails/images depending on users browser/platform
- PowerPress mobile media player
- Auto-Populate Image After Media Upload
- How to create a backend for a custom theme?
- How to make “upgrade safe” theme for a plugin?
- Are there any official or unofficial guidelines for the styling of a widget?
- making a plugin that moves other plugins wp_head actions to wp_footer
- Get images / media attached to a page by page ID
- Create fixed static pages
- How To Protect Plugin Display From Being Affected By Theme’s CSS
- Displaying custom content from a plugin within the active theme
- Getting Post ID at “stylesheet” and “template” hooks
- WordPress admin panel not working
- Override category archive page title (not the head title)
- How to hide/remvoe unnecessary field/section in post edit section ( Dashboard )
- Redirect theme directory to plugin theme directory
- Adding and handling custom settings tab to fusion element
- Post Pagination does not working on WP-Query
- Managing Custom Designed Content
- Create and style menu
- Developing Themes on WordPress, Looking for Excellent Tutorials [closed]
- Find Any Theme’s page.php File
- Theme / Divi change visitor css and site logo and all site urls based on REQUEST_URI non logged in wp user
- How to give a NavWalker its own stylesheet?
- How to rename the plugin PHP file without affecting existent users?
- Add location tag to wordpress posts
- Open tab on current day problem jQuery and WordPress
- Why does comments_open() return false when publishing a scheduled post?
- Using delete_post_meta for deleting multiple selected options
- get_shipping_methods() return empty rate
- Can I Hook Into the TinyMCE Insert/Edit Link Button to Use Shortlink For Post?
- Include HTML (Bootstrap Modal Box) with a plugin into my header
- Ajax function is not working on WordPress
- Best way to ping for the API changes in the wordpress?
- when i activate my plugin i want to auto create pages with shortcodes
- Auto-complete or auto-suggest from stored data in database
- Best way to distribute templates and code accross multiple wordpress sites?
- Schedule some work in custom plugin
- What is the replacement for rich_edit_exists()?
- Disable Auto-Expanding Menu in WordPress Admin Menus
- How to overwrite iris color pallates from theme to plugin
- How to submit/upload data to database and in specific folder?
- OOP plugin not working
- About a programming language starts with [closed]
- Adding Custom CSS with PHP
- in_array function Problem
- Best practice for plugin: always detect admin-ajax call?
- custom wp_editor does not save the content in plugin settings
- Plugin Development: Storing and Manipulating Data That Fits JSON in Database
- Adding another field to user table
- How to set a header in wp_safe_remote_get()?
- Data inserted by wpdb insert is different than data pressnt in database.
- How do I force a download in the admin area?
- add_action wp_ajax_ not loading in plugin file WP Network
- get_avatar filter in WordPress 4.4, how to filter properly
- Cleaning a filename after image sideloading a url that contains `%20`
- Proper Prepare Statement for ALTER TABLE and using AFTER
- How to use a WP_Customize_Control outside of the Customizer?
- Why is the form not updating when I select a new sector from the list?
- Multiple page plugin settings
- WordPress Plugin Development- When our plugin functions call?
- How to change a field in database through a submit button or Checkbox? [closed]
- Plugin creation, restricting access to specific roles
- Overwriting a plugin function
- Grandchildtheme (plugin) add header.php (not exist in child theme)
- Get audio metadata on file upload
- Referencing files in JavaScript in WordPress Plugin
- How to Customize Polylang Language Items
- wordpress automatic update does not run
- Submit form to a different PHP file in the same plugin folder
- What might be the reason of Couldn’t fetch mysqli_result on another domain?
- How to list all images used on a specific page?
- Can calling wp_enqueue_style in wp_iframe apply the stylesheet to everything not just the iframe?
- WP Dropdown Categories, display subcategories but not grandchildren categories?
- How to get terms for taxonomy
- Copied files from plugin to theme not working
- How can I allow the user to press enter without creating a new element in the editor?
- wpdb->get_var always returning 0
- A function that will remove HTML and tags from a string?
- Information on plugin adding text when a post, page, or other such is displayed
- configuration of .htaccess for add_rewrite_rule to make sense
- Plugin working on my local installation but Cannot be activated online
- $wpdb->prepare is not working like mysql_real_escape_string
- How to insert HTML/CSS/JS into my iframe plugin?
- Workflow for new importer plugin – your advices?