Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ for more details.
I've been trying to make some major changes to the theme on my blog recently and doing this on the live website is not a great idea, so I started looking into the FlatPress code to see how I could dynamically change the theme that it loads by specifying a URL parameter. The changes are straight forward, but do require modification of the core files.

The change is done in the core.system.php file. Specifically, inside the system_init() function. There is a call to the user_loggedin() function that I commented out and replaced with the lines of code shown below.
function system_init() {
//user_loggedin(); // comment this out and add the following 3 lines
if (user_loggedin() && isset($_GET['theme'])) {
$GLOBALS['fp_config']['general']['theme'] = $_GET['theme'];

My code checks for whether the user is logged in, because you don't want just any visitor switching the theme on the fly. It then looks for the 'theme' URL parameter and if that's set, it modifies the loaded FlatPress configuration to the new theme. Simple.

Note: Playing around with a live system is not ideal, a test system should be set up that addresses this issue directly. However, sometimes you do want to test a theme on the live system without rolling it out for everyone to see, in that case, this kind of modification is justified.


Skip down to comments...
Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...