Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

etc.

Can you help with my problem?

share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.