I found some plugins like WP Mobile Pack, but I want to put together my own very simple theme switcher. (Just don't want any bloat.)
I have a regular WordPress theme and I also created a WordPress Mobile theme as well. These are both standard WP themes that can be activated in the dashboard.
How can I direct certain user agents directly to the mobile theme? (I don't want a mobile domain, sub-domain, or trailing directory.) www.example.com should be the domain for any visitor.
The one catch is, I also want to offer a link to let users switch back. For instance, iOS devices should go to the Mobile Theme. But if they are on the large iPad, they may want to simply use the regular site. Having some sort of cookie override the default .htaccess or PHP redirection would be useful.
Any help, specifically targeted at WP and handling WP theme switching would be truly appreciated.
I would use 2 stylesheets to theme the page, and detect the browser and serve up the right css depending on what the browser is detected as. Have a look at the 'get_browser' function of PHP http://php.net/manual/en/function.get-browser.php
then just have an if statement:
if (preg_match('/mobile/i', $u_agent)) {
$css = 'mobile.css';
}
and then just load the $css
Hope that makes some sense.
You will have to create a plugin, that fires the switch theme action. Here is a reference:
https://codex.wordpress.org/Function_Reference/switch_theme
I think you can try the 'after_setup_theme' hook.
Related
yesterday i stumbled across Sergey Burkov's wordpress plugin 3DPrint Lite and I'd like to use it for my website. I'm currently using dokuwiki and don't want to switch to wordpress only for this single purpose. There aren't any similar solutions to Burkov's plugin and coding it all by myself is no option.
.I'm asking myself if its possible to only use wordpress' backend or something similar. So that I would end up with only one page. (Login and so on has to stay available of course)
Any suggestions?
You don't need to switch to wordpress for your whole site, just to use that plugin. Not hard to install wordpress in a directory on your site, and then if you don't want to use any wordpress pages, just use the login from yoursite.com/directory/wp-admin.
If you don't want yoursite.com/directory to show at all then you could do a redirect of that url only, perhaps to your homepage.
Just don't try installing wordpress at yoursite.com since that will mess with your current site.
Not sure how to title my issue.
I have a Wordpress website, where most values are stored in custom fields and is very independent of language - e.g. most values are numbers.
Instead of creating a multi-site with several network sites, I am looking for a much simpler solution. Let's say I want to create a German version. Then ideally, I could redirect all German users accessing the site with /de/ to a German version of the theme.
E.g.:
http://www.example.com/post-name/ directs to single.php in the theme files
http://www.example.com/de/post-name/ directs to single-de.php in the theme files. So they will have the same content, but the translation will be in the theme file.
The only problem I can see is the canonical URL, but I am guessing this can be dealt with as well. So my question is, is it possible to redirect all users that go to /subfolder/post-name/ to a specific theme file and display the content of that post with the specific theme file?
Is there any solution I have missed that might be easier?
My solution above would only require redirects and some additional theme files instead of creating a completely new multi-site and importing everything and having to keep this site updated as well.
There is already wp logic to do theme translations, so you don't need to re-invent that. If your content is in the theme or is the same for all languages (eg the numbers), then the translations should work well for this.
One can set WP-LANG dynamically. Viper's https://wordpress.org/plugins/in-their-language/ tries to do that automatically for admin area (not sure if it still works), or/and you could add a language switcher. Fairly easy, there's a variety out there https://www.google.com/search?q=wordpress+language+switcher.
this is an answer to
Is there any solution I have missed that might be easier?
not an answer to
So my question is, is it possible to redirect all users that go to
/subfolder/post-name/ to a specific theme file and display the content
of that post with the specific theme file?
I’ve been experiencing a problem that I was hoping someone could point me in the right direction. In an effort to make my website more mobile friendly, I purchased a mobile responsive theme. While I know I could have created a sub-domain or a directory to house the mobile version of the website, I’ve been attempting to have the original domain http://example.com switch themes based on the user. In other words, for http://example.com, Desktop user views DesktopTheme and Mobile user views MobileTheme. With the Any Mobile Theme Switcher plugin, I was able to accomplish this will little issue. However, for certain pages I would like to be able to display the desktop version to the mobile user. For example, for single posts, I would like the desktop user and the mobile user both to see the DesktopTheme.
Unfortunately, after several hours of searching and experimenting I am not further along than when I started. Using different templates appeared to be an option, but it’s not a true theme switch. When I altered the template files, mobile users received a hybrid version of the site that includes the mobile header and an unstructured version of the desktop version. A similar result was achieved when I simply copied the single.php file from DesktopTheme into the folder for MobileTheme.
Example:
<?php get_header('/var/www/html/wp-content/themes/DesktopTheme/header.php'); ?>
Any ideas?
There is a plugin that you can use for switching themes based on the post type as well as a lot of other conditions:
http://codecanyon.net/item/wordpress-theme-switcher/558740
I'm not aware of any free version that offers the same functionality, but that doesn't mean one doesn't exist.
With that said, I think you should reconsider your approach here. The entire point of responsive design is so you do not have to have separate mobile and desktop sites. I think you should sidestep this entire issue by using the responsive theme everywhere.
Using a single responsive theme is going to make maintenance much easier and give the user a more consistent experience.
Also, get_header is meant to load a header file from the current theme. You can't load components from other themes and expect them to work correctly.
For some reason, my theme will not use any of the .php templates that I have built. For instance, in my theme file, there is a template called "gridLayout.php" In Page Types I have created a "Grid Layout" page type with handle "gridLayout"—shouldn't that be all I need to do? I cannot see the template in the Defaults mode, or when I create a specific page of that type. I also tried de-activating and re-activating the theme, thinking that would refresh things; still nothing. I must be missing something simple.
page types ought to follow concrete5 naming rules, grid_layout.php is preferred to gridLayout.php also concrete5 will only ask you to register a new page type upon theme installation or using the inspect button.
There are a couple of options here. One, de-activating the theme is not enough. Uninstalling and installing the theme will restart the process of identifying page types. Even easer though is the "Inspect" button for the custom theme. It will identify page templates that are not being used and ask you to create said page type.
Check your cache settings in Concrete5. Make sure you turn off all caching while developing.
I have a Wordpress network with a big amount of different themes and even more pages using those themes.
Now, I have a PHP function (for some tracking) that I want to run every time a page from my network is accessed. I don't want to edit all my themes, so I am looking for a central file where I can have this new function.
First thing in my mind was the index.php in the root folder of the WP installation. This would probalby work but does not seem the finest solution.
All my themes are using the wp_head function maybe this can help somehow?
Is there any other place where I can add my tracking code and make sure that it is run on every page access?
You should create a plugin to do this. In that plugin you will have that function and add the action to the wp_head hook. This will keep it working with all of your themes and easy to change without having to go into all your themes.
The code will look something like this
/**
* Plugin Name: Tracking Function
* Description: Lets me track my code
*/
function tracking_function(){
//enter code here
}
add_action("wp_head","tracking_function");
Then, because you have a network of sites, you will have to go into the Network Plugin manager, and activate the plugin for all networks and then you can activate or deactivate it for each specific site in your network.
The two options I can think of would be to use a plugin that loads "custom functions" for the sites that it is included on - much like functions.php in your theme, but independent of each theme. I wrote a plugin that does this which you can find here: http://justinsilver.com/technology/wordpress/wordpress-plugins/wordpress-plugin-custom-functions-php/
The other option would be to put a PHP file with your code into the wp-content/mu-plugins (Must-Use Plugins) that will be loaded before all other plugins on every site in your network. A bit more straightforward than the first option, but you can't selectively disable it should you not want on it on one of your network sites.