Of course there’s a function for that (Codex):
switch_theme( $stylesheet )
It:
Switches current theme to new template and stylesheet names. Accepts
one argument: $stylesheet of the theme. ($stylesheet is the name of
your folder slug. It’s the same value that you’d use for a child
theme, something liketwentythirteen
.) It also accepts an additional
function signature of two arguments: $template then $stylesheet. This
is for backwards compatibility.
And why is that any better? WordPress uses filters and actions for many things. For example, when you switch the theme, the unused widgets will get saved, so you can restore them in new sidebars… All of that won’t be done, if you switch the theme directly in DB.
Related Posts:
- unzip a folder on specific location and delete the zip file
- How to override any plugin file in the child theme
- Uninstall, Activate, Deactivate a plugin: typical features & how-to
- How do I cleanly override a plugin’s CSS with a child theme?
- What is the correct way for a theme to support plugin UIs?
- Automatically install wordpress plugin at theme activation
- How to call “page specific menu items” in template [closed]
- Update Multiple Post Meta for the Same Post In One call?
- Which functions in theme or plugin load first
- How to make my plugin theme-independent?
- Activate Plugin which is in subfolder?
- Should I use RIPS tool to test my themes and plugins?
- How to Build a Movie Library in WordPress 3.x
- Force plugin to fail activation
- Autoload via composer in plugin interference
- WordPress register_activation_hook table creation not working
- Workflow and best practice for documentation [closed]
- Correct way to use register_activation_hook
- Display future posts?
- Having separate plugins and themes folder for multi-site setup
- How can I get full attachment url from wp_get_attachment_metadata?
- gallery option is not available in media upload box in costum theme option page
- Why is the Settings API is not saving my array of options
- How to integrate plugin in WordPress theme
- How to include plugin without activation?
- Auto add content such as pages upon plugin activation?
- How to automate wordpress plugin activate and deactivate by php logic?
- Default Plugin Settings Not Writing to Database
- WooCommerce get_price returning wrong price when used via ajax
- Open Post Thumbnail in New Child Theme File in WordPress
- How to use get_theme_mod in gutenberg editor wordpress?
- Reusable functions and tools (Framework)
- How to get current post user id
- Why does my functions.php cause white-screen and media-library issues?
- Own plugin corrups plugin-activation
- Display post lists in 2nd paragraph
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- What are the specifics of WordPress development I need to know? [closed]
- Force file download on plugin activation
- How to create a code editor for my plugin .?
- How to show only next post pagination link using wp_link_pages()
- wp_footer hook only working on homepage not in other pages
- Redirect to another page using contact form 7? [closed]
- Overriding Parent Theme… will cause plugins failure?
- How do I combine a theme with a plugin
- how to force tag page layout to use same as search layout?
- Run function on plugin activation before plugin is loaded
- Great blogs site resources/tutorial for WordPress Developers? [closed]
- How to write “alt” tag in image for wordpress code?
- Release the plugin in the WordPress repository where redux is used
- Shortcode Attributes to Return different $_POST
- How to use the CSS of the WordPress core in the development of my administration page?
- Managing wordpress Themes & plugins for multisite
- Set up functions to be overridden without using function_exists() by short-circuiting them?
- How to customize this theme? [closed]
- WordPress API functions not working at AJAX functions.php call
- Don’t load the theme for a page FROM a plugin EDITED
- Extending a theme: build new features as plugin or core modules?
- Remember the Meta Value With Radio Buttons
- How do you create a re-useable HTML fragment in wordpress
- Next Previous Post in wordpress with previous / next link with title?
- WordPress plugin with its own “site”/theme
- Yoast SEO Plug In and my Theme duplicating code. Need some feedback on what to do? [closed]
- My plugin does not install correctly if a previous version is still installed
- Seperate plugin and theme files
- Xamp installed local wordpress not allowing to publish or install plugin
- Activation flow of a plugin in a multisite environment
- Widgets are not displaying in the admin panel
- submit two file input fields in the same form
- Content-Security-Policy implementation with WordPress W3Total Cache plugin installed
- woocommerce: Customize email with item total count
- Child theme modifications not showing up
- How to check for already existing plugin versions on activation? and prevent errors
- How can I see $post object in frontend from functions.php?
- My WordPress activation hook isn’t working
- when i activate my WordPress plugin cannot see customizer options or preview
- Remove action added in plugin class from theme
- Can you develop themes and plugins while using the hosting services BlueHost? [closed]
- Help Code Review – I need to write on .htaccess file from theme’s function.php
- how to add custom css at top above all css file for specific url
- Where do the section input fields values are stored in database
- Why the output of an image gallery plugin is not displayed into a page of my custom theme?
- How to show post attachment image
- Can anyone tell me why I can’t edit a plugin when it is installed without having to re-install?
- What is the Object for WP_Error Class?
- Active Plugins for current blog in WP Multisite Network? [duplicate]
- Site is setup statically – how to make it content managable?
- How can I make a website with dynamic features with wordpress?
- How to generate a responsive output from plugin?
- How to create post comparison in wordpress
- How to add image for custom taxonomy
- Integrating WordPress Content into a jQuery Slider
- How to escape html code?
- manage_{taxonomy}_custom_column not working
- how to make wordpress remember my choice
- How to Enfroce Domain Licensing Limits? [closed]
- Meta box not displaying on the plugin page
- add_meta_box showing blank screen in my page
- How to make content as required in custom post type?
- What are Seeds? [closed]