WordPress How To Switch Theme Dynamically by URL

I want to switch my WordPress theme dynamically where if my visitor visits a specific URL they will see different theme while my main theme is still the same for other URLs.

All Other Pages will Show Main Theme Like Below

wordpress switch theme dynamically - original theme
wordpress switch theme dynamically – original theme

 

Only for Page wordpress-how-to-switch-theme-dynamically-by-url/ will show below Theme

wordpress switch theme dynamically - different theme based on url
wordpress switch theme dynamically – different theme based on url

 

WordPress Hook to Change the Theme

You can do it by using pre_option_{$option} hook. In this case:

This hook will filter the value of an existing option before it is retrieved.

You can refer the pre_option hook here.

The Code to Change WordPress Theme Dynamically

Don’t Put The Code at Your Theme files

It doesn’t work if you put the code at functions.php or in any files under your theme folder.

You must put at a plugin.

Side Effect by Switching WordPress Theme Dynamically

By switching the theme dynamically, I noticed that:-

  1.  The my top main menu doesn’t appear. I don’t how to solve this yet.
  2. Google AdSense also seems not loaded
wordpress switch theme dynamically - top menu not appear
wordpress switch theme dynamically – top menu not appear