When viewing available themes, how to change prevew to link to a demo

I’ve always felt that live preview of installed themes is pretty much useless, since so many themes depend on specific types of content and add-ons to achieve the look you see in the thumbnail. In fact, many themes look just plain broken. Thus, I would like to change the link of the Live Preview button to a Demo button instead. I would like to do this without hacking wordpress core files – namely /wp-admin/themes.php – but I’m guessing a core hack would be necessary to achieve this.

I found the link at line 325 of wp version 4.1.1 which outputs the Live Preview button as follows:

<a class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a>

I would like to change it to:

<a class="button button-primary load-customize hide-if-no-customize" href="http://demo.example.com/<?php respective_theme(); ?>"><?php _e( 'View Demo' ); ?></a>

Where I’m stuck is how to get the directory, such as ‘twentyfifteen’ for the Twenty Fifteen theme, for example. Any ideas how to retrieve the respective theme directory?

Also, is there a way to do this without hacking the core file?


  • Michelle Shull
    • DEV MAN’s Apprentice

    Hey, Tedster!

    The easiest way to do this without hacking any files is to do a network-wide text change with a tool like our Ultimate Branding. It will create a translation file that won’t be altered when any plugin, theme, or WordPress core updates, so you can make the change once and forget it.

    Plus, you should never, ever, ever, ever, ever, ever, ever alter WordPress core. :slight_smile:

    Thanks for your question!

  • Tedster
    • The Incredible Code Injector

    Thanks for the quick response, Michelle, but the text change plugin will simply change the words "Live Preview" to "View Demo". What I have to change is the actual link.

    In terms of doing a core hack, one should never ever say never :slight_smile: This would be a very simple hack which could easily be redone, in case of a wp core update. Unless there's a way to do this without editing code directly, I think a simple hack such as this one is reasonable.

    What I've tried since my original post is to use $theme['id'] to get the respective theme directory. Oddly, it gives me the directory of the very last theme listed – in this case, wp-zefir. I think I'm on the right track… just need it to get the correct theme.

  • Tedster
    • The Incredible Code Injector

    Not bad for a rookie, eh? :smiley:

    Only thing is I have to pay attention to when wordpress updates itself, as it seems the latest version does whether I want it to or not. I guess it’s no big deal if users see Live Preview for a short while, until I redo the hack. I just wish there was a way to do it without hacking, but we do what we gotta do.

  • Tedster
    • The Incredible Code Injector

    That’s a good idea but I wouldn’t know where to start. I wrote one simple plugin some time ago, to add code after posts and pages. For that I hooked into the_content(). As far as I can tell, there are no hooks for admin functions. Any ideas how I might accomplish this?

  • Jude
    • DEV MAN

    Hey Tedster

    I don’t see any simple hooks that you can do this with and Im sure there will be not many people who will be as courageous to modify the core like you.

    I think its best to shelve the plan till WordPress allows for the link to be changed with a filter.



Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.