1

I'm building a web application on top of WordPress. Part of this will be to automatically reconfigure theme assets based on the industry my user is aligned to. For example, the theme will auto-select from a library of stock background or slide-show images, based on the logged-in user's industry.

I'd like the user to also see theme snapshots that match their industry, so theme selection will look nicer.

Aside from creating a bunch of child themes, is there any way I can dynamically change the theme screenshot.png?

The only idea I've come up with so far is to directly manipulate the DOM with JQuery on the client side. I'd love a server-side solution, instead.

4

From quick look WP seems to process array of theme data in a way that is used for both PHP and JS sides.

Result passes through wp_prepare_themes_for_js filter, which seems like a suitable place to override screenshot URL as necessary.

This worked in my dev install:

add_filter( 'wp_prepare_themes_for_js', function ( $themes ) {

    $themes['r-test']['screenshot'][0] = 'http://dev.rarst.net/wordpress/src/wp-content/themes/twentyfifteen/screenshot.png';

    return $themes;
} );

Of course the nuance is that theme has to be running for its code to execute. If you need to do this for inactive themes the code would have to be placed/running outside of them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.