最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to allow users to switch to the child theme from front end without plugin?

programmeradmin3浏览0评论

I have two themes.

  1. mytheme
  2. mytheme-child

    By default my site loads with mytheme And I have a link by the header:

    <a href=" [here I have to give a code line that switches the default theme to child theme] ">Visit our mobile site</a>

    When the user click the above link Visit our mobile site the theme should be switched to the child theme.

    I spent a day of googling but could NOT find any tutorials or info for achieving this without using a plugin. How can I do this without a plugin?

I have two themes.

  1. mytheme
  2. mytheme-child

    By default my site loads with mytheme And I have a link by the header:

    <a href=" [here I have to give a code line that switches the default theme to child theme] ">Visit our mobile site</a>

    When the user click the above link Visit our mobile site the theme should be switched to the child theme.

    I spent a day of googling but could NOT find any tutorials or info for achieving this without using a plugin. How can I do this without a plugin?

Share Improve this question edited Jun 3, 2015 at 4:28 Riffaz Starr asked Jun 2, 2015 at 11:51 Riffaz StarrRiffaz Starr 7964 gold badges20 silver badges41 bronze badges 1
  • What you want to do is a bad idea. You have three options here, create a separate mobile install and redirect to it if the user chooses to visit the mobile site, or have two different stylesheets which you load conditionally, or use responsive design. – Pieter Goosen Commented Jun 3, 2015 at 6:05
Add a comment  | 

1 Answer 1

Reset to default 0

I have different Point of View on that, and my solution is plugin-centric:

A mobile theme is for the user's ease-by-default, and should not for a user's ease-by-choice. Take the scenario:

  • a mobile theme is highly optimized
  • a mobile theme is designed with less resources (it serves lesser dev. resources to the user)
  • a mobile theme is lesser width devices-friendly

So, if a user browse my site with high load (the desktop theme), what's the purpose of a mobile-friendly theme then?

So, in my opinion, a mobile theme should be offered at the very first stage, and if it's automated, it'd be nicer. And then let the user choose whether they want to load the desktop site (parent theme) or stay into the mobile site (child theme).

I relied on Any Mobile Theme Switcher plugin by Dinesh Karki. It's an awesome free plugin that,

  • offers different theme for different devices
  • shortcode functionality for theme switching

My POV: While a plugin solves everything why not I use it solely? If I have obligation using a complete plugin for my purpose, then grab the code from the plugin and grab the necessary bit from there, or write down my own grabbing idea from there.

Without plugin

I still don't have any without-plugin-solution to this issue. But if you really in need of such functionality then I can assume you can code yourself using the technology:

  1. How the Theme Test Drive plugin activates a theme on choice
  2. Use two switching buttons and activate different theme using the method of #1

Hope that helps.

发布评论

评论列表(0)

  1. 暂无评论