WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I had created a dedicated mobile version for my website, not responsive theme.

I used a wp_is_mobile function to change some styles and script, also a template. All working good but I want to add a mobile prefix to all links like:

  • mysite.com/mobile/category/mycategory
  • mysite.com/mobile/mypost
  • mysite.com/mobile/tag/mobile


Can you help with my problem?

share|improve this question

You can change the options siteurl and home.

add_action('after_setup_theme', 'maybe_mobile_url');
function maybe_mobile_url() {
  if ( wp_is_mobile() ) {
    add_filter('option_siteurl', 'add_mobile_url' );
    add_filter('option_home', 'add_mobile_url' );
function add_mobile_url ($url) { return $url . '/mobile'; }

But, I think, that if you define WP_SITEURL and/or WP_HOME in config.php it will fail, and you will have to add filter to all the function that retrieve permalinks.

share|improve this answer
Actually you can just define those two constants in the wp-config.php. The problem is that you do not have the function wp_is_mobile() available, so you may have to define those two later, or write your owwn mobile switch. using the constatnts brings you the advantage of not having to filter every url-function. – fischi Nov 6 '13 at 7:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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