Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Specific theme for non logged in users

Functions – under the hood

While is_user_logged_in() can be used to determine the difference between a guest and a logged in (and therefore registered) user, switch_theme( $stylesheet ) alters actual database entries in the {$wpdb->options} table:

update_option( 'template', $template );
update_option( 'stylesheet', $stylesheet );
update_option( 'current_theme', $new_name );
if ( count( $wp_theme_directories ) > 1 ) {
    update_option( 'template_root', get_raw_theme_root( $template, true ) );
    update_option( 'stylesheet_root', get_raw_theme_root( $stylesheet, true ) );
} else {
    delete_option( 'template_root' );
    delete_option( 'stylesheet_root' );
}
update_option( 'theme_switched', $old_theme->get_stylesheet() );

Simple solution: Two stylesheets.

Therefore I wouldn’t recommend doing so. Simply switch “themes” – read: loaded stylesheets – on a user/guest basis

$stylesheet  = plugins_dir_url( __FILE__ ).'assets/';
$stylesheet .= is_user_logged_in()
    ? 'style-user.css'
    : 'style-guest.css;
wp_enqueue_style(
    'main-stylesheet',
    $stylesheet
    array( 'commons.css' )
    1.0
);

As you can see, I add a dependency of commons.css to the stylesheet. This would be another, previously registered/enqueued stylesheet that has all definitions that are shared between both.

Related Posts:

  1. Switch Theme Through Options Panel
  2. switch a theme different per user role
  3. Extra User Profile Field Upload File / Image
  4. Switch to other theme at URL
  5. Change avatar on themed profile page
  6. When someone likes an article on my blog, they are prompted to log in on WordPress.com [closed]
  7. How can my user make their own Blog/Diary
  8. How can I theme or style the lost password page without a plugin?
  9. Missing privacy policy checkbox on login page (using Enfold theme)
  10. Default and warning messages & no login
  11. Showing wordpress theme demo at front end
  12. change template with button
  13. How to have a WordPress user profile just having one button and one input textbox?
  14. Change wordpress theme name (not child theme)
  15. Edit a template while still keeping a Landing Page on the main address
  16. Copy from wordpress for dev gives different output in browser
  17. Cannot login in WordPress even after changing hash password in phpmyadmin
  18. Warning: call_user_func() expects parameter 1 to be a valid callback
  19. Full width background slider
  20. List users in a dropdown for login
  21. Can i add wordpress editor to my custom theme option? [closed]
  22. When translating not all string are present in POedit
  23. Updating theme resets theme options settings and widgets
  24. Phone numbers showing same color as header [closed]
  25. How can I Update my Theme
  26. Baskerville Theme – How to use the masonry grid layout on other pages
  27. load language file
  28. Are immediately-called actions not usable in themes?
  29. Password Protected Page + Showing Different Page If Not Authenticated/Authorized
  30. Featured images are cropped on index and post page
  31. Where is the stylesheet code?
  32. Detect PHP script usage in themes?
  33. How to allow users to switch to the child theme from front end without plugin?
  34. Firebug and Chrome rendering two body tags
  35. Show part of front page on another page [closed]
  36. wordpress theme link url
  37. Target Internal Link Of Another Page On Website
  38. Mobile theme switching problems
  39. custom login form, guide me
  40. Custom theme being prompted for update because of similarly named theme
  41. How to add different link on each Post [closed]
  42. EM in CSS different size on wordpress then elsewhere [closed]
  43. the_content doesn’t return tags
  44. How to retrieve images attached to post through media library?
  45. Use random theme
  46. Determine Featured Image Size in header
  47. Change the main width of Twenty Thirteen theme
  48. Background image not showing up
  49. Change theme’s thumbnail to cropped WP featured image
  50. How to display post meta data in secure manner
  51. Theme stops media uploader from working
  52. theme continuous deployment from bitbucket to windows azure
  53. Changing themes on locally hosted webpages
  54. Change whole theme depending on resolution
  55. WordPress Theme Migration Local to Live Assets Not Loading
  56. Lost for direction on how to continue building a theme
  57. post_prev & post_next within same category
  58. Revamping a WordPress mirror site – and I don’t know where to start!
  59. Changing admin Textarea to integrated WP editor
  60. Costum Theme template directoy url problem
  61. Plugin to load theme if mobile and specific page
  62. Line break no working on theme
  63. Meta title W3C Validation Error with
  64. Replacing current theme folder by previous version of the same folder produces “undefined function get_header()” error
  65. Can I add a blog subfolder to my website and use a different theme
  66. adding a unique page to an existing site
  67. Premium theme – hardcoded url?
  68. Any Mobile Theme Switcher – Theme not complete (Stylesheet missing)
  69. Work on theme files on a server & browser preview before installing it
  70. How to change images size after theme modification?
  71. What is the template file for topic layouts in bbPress?
  72. Does WordPress provide themes_api function?
  73. Style of a theme
  74. Unable to access new installed theme
  75. Adding admin-ajax.php to the frontend. Good or bad idea?
  76. Route to custom file
  77. permissions on themes directory
  78. Orion theme (from theme forest) [closed]
  79. WordPress Form To Email.php and Theme
  80. Where do URI files come from?
  81. How do you make your theme Child Theme-able? [duplicate]
  82. “Template is missing” install error on non-child theme
  83. QA/Staging envirnoment for wordpress sites
  84. Add Media + Quick Edit buttons not working
  85. Theme comment callback results nothing
  86. How to fetch the no. of Users dynamically?
  87. Multiple Users Logged In Causing Incorrect Account Returned
  88. Does not work bookmarklet in the theme Tagology
  89. Will this js code work in a page template?
  90. How do I block a subdirectory from WordPress theming?
  91. Changing user_login ends current session
  92. spacing disappears on posts when importing
  93. How to remove the option data of a theme when that theme is removed?
  94. Problems Replacing Background Color with Static Background Image in Responsive Design
  95. How to prevent tinyMCE editor to be loaded completely in Text Editor?
  96. Current User Seeing Another Logged In User Info
  97. Lost in creating multiple meta boxes
  98. div having different appearances in different themes
  99. Categorising themes by folders in backend
  100. How to show tags in posts with a theme that does not do it
Categories themes Tags login, switch, themes, users
wp_mail attachment not working
How to list all external URLs that I have posted on my WordPress blog?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress