Title: Where to insert mobile redirect code?
Last modified: August 20, 2016

---

# Where to insert mobile redirect code?

 *  [helices](https://wordpress.org/support/users/helices/)
 * (@helices)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/where-to-insert-mobile-redirect-code/)
 * I have this simple PHP code:
 *     ```
       <?php
       require_once "/_PATH_/_DOMAIN_/class.mobile.php";
       $mobile = new MobileWebarto("http://m._DOMAIN_");
       ?>
       ```
   
 * Obviously, _PATH_ and _DOMAIN_ are placeholders.
 * class.mobile.php identifies whether or not the visitor is a mobile device.
 * On most sites, inserting this code at line #1 of header.php behaves exactly as
   I want and expect.
 * However, some sites do NOT behave as desired.
 * In reality, I want this code to execute PRIOR to any theme code.
 * Furthermore, I don’t want WordPress updates to remove the call to this code.
 * It seems that this code could be inserted into index.php – BUT, where?
 * HOW can this be done WITHOUT future WP updates removing my code?
 * Please, advise. Thank you.

The topic ‘Where to insert mobile redirect code?’ is closed to new replies.

## Tags

 * [header.php](https://wordpress.org/support/topic-tag/header-php/)
 * [index.php](https://wordpress.org/support/topic-tag/index-php/)
 * [mobile](https://wordpress.org/support/topic-tag/mobile/)
 * [redirect](https://wordpress.org/support/topic-tag/redirect/)
 * [Updates](https://wordpress.org/support/topic-tag/updates/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [helices](https://wordpress.org/support/users/helices/)
 * Last activity: [14 years, 2 months ago](https://wordpress.org/support/topic/where-to-insert-mobile-redirect-code/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
