WordPress loads different themes according to different UA

» WordPress » WordPress loads different themes according to different UA

Several lines of code realize automatic switching of WordPress theme according to UA

WordPress根据不同UA加载不同的主题-极客公园

preface

describe

In fact, the working principle is very simple. It is to check the ua of the current browser. If the ua meets the requirements, it will switch to the theme you use. Otherwise, it will switch to another theme. The browser used here can be Firefox or Chrome browser. Using browser plug-ins can easily modify the ua of the browser. Cloud uses Firefox browser here, For example, the firefox ua in Yunluo is below
WordPress根据不同UA加载不同的主题-极客公园

code

 function ua_switching_theme() { if (strpos($_SERVER['HTTP_USER_AGENT'], 'yunluo') !==  false) { $theme = 'Git-alpha'; } else { $theme = 'html5blank'; } return $theme; } add_filter('template', 'ua_switching_theme'); add_filter('stylesheet', 'ua_switching_theme');

Add the above code to the function Documents are sufficient.

--End--

Post reply

Your email address will not be disclosed. Required items have been used * tagging

4 Replies to "WordPress loads different themes according to different UA"