• 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

    (@bcworkz)

    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

    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.