Forums

Conditional shortcodes within a post or page (4 posts)

  1. cvc1968
    Member
    Posted 1 year ago #

    I am trying to find a way to write conditional text within the content of a post or page.

    Specifically, I want to be able to switch between two shortcodes, depending on whether the user is on an iOS device or not. This is not about theme switching, this is about content within posts only.

    Specifically, I have found a plugin that displays video playlists the way I want for the desktop site using a shortcode. However, I have a different video plugin I want to use for mobile devices which also uses a shortcode.

    I have tried using the exec-PHP plugin and successfully created a conditional statement to display text in the post for iDevices vs. Desktop, but when I try to echo or return the shortcodes, they simply display in the post as text. The shortcodes are not parsed.

    Does anyone know of any way to achieve what I need to achieve, either through PHP coding that would allow me to output the correct shortcode in a way that would allow it to be parsed, or through some other solution I am not aware of?

    (btw, I know there are video players that are compatible with both desktop and iDevices: the problem is with the dimensions of the video player. A video player at, say, 640 x 360 in the desktop site is great, but it also displays at that size on the iDevice, which means it breaks out of the layout and extends outside of the margins of the iPhone screen. My purpose here is to have two different video plugins available, each with different preset dimensions, and display the appropriately sized player for each situation. I am open to suggestions of how best to accomplish this.)

    Thank you.

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    try to integrate do_shortcode() into your conditional statement

    http://codex.wordpress.org/Function_Reference/do_shortcode

  3. cvc1968
    Member
    Posted 1 year ago #

    Thank You. After playing around with a few different 'php in post' plugins, I got everything to work using do_shortcode. This is why I love forums.

    Thanks again.

  4. rajaito
    Member
    Posted 7 months ago #

    I am interested to know the code you used to produce a conditional shortcode for ios devices.

Topic Closed

This topic has been closed to new replies.

About this Topic