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?


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.

| 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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