Title: Rewrite shortcode if mobile device.
Last modified: August 21, 2016

---

# Rewrite shortcode if mobile device.

 *  [andy_woz](https://wordpress.org/support/users/andy_woz/)
 * (@andy_woz)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/rewrite-shortcode-if-mobile-device/)
 * Hi I have an older site that uses a flash based audio player proprietary shortcode
   in the page content. What I’d like to do is to switch to an HTML5 audio player
   for mobile devices. I guess I’d be looking for a filter to replace shortcode 
   content based on device?
 * I know wordpress has an wp_is_mobile() function. Could that be used to rewrite
   shortcodes in the content?
 * I’d need to change shortcodes in the format `[audio:http://myaudiosource.com/
   filename.mp3|titles=My audio Title]`
    to `[audio src="http://myaudiosource.com/
   filename.mp3|titles=My audio Title"]` for mobile devices, assuming the |titles
   part wouldn’t break the player.
 * Maybe I could do a preg_replace() just not sure how to target the shortcodes 
   in a function.
 * Thanks!

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/rewrite-shortcode-if-mobile-device/#post-4648160)
 * Hook the filter ‘wp_embed_handler_audio’ and change the HTML output as required.
   Your filter callback is passed 4 different parameters that you may find useful.
   See the source: [http://core.trac.wordpress.org/browser/trunk/wp-includes/media.php#L1615](http://core.trac.wordpress.org/browser/trunk/wp-includes/media.php#L1615)
 * You are right, `wp_is_mobile()` can be used to conditionally change the output.
   Note that you are altering the HTML that replaces the shortcode found in content.
   Your example is changing the actual shortcode, which is done through different
   filter. I don’t see this as necessary since you have complete control over the
   final HTML.

Viewing 1 replies (of 1 total)

The topic ‘Rewrite shortcode if mobile device.’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/rewrite-shortcode-if-mobile-device/#post-4648160)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
