Is it possible to insert iFrames or better yet shortcodes

Is it possible to insert iFrames or better yet shortcodes into a unit? I have some content (training videos) that I want to make available as part of our courses, but this content is stored in a html wrapper. My hope is to allow the authors to insert these training materials via a shortcode in the unit. I have written the following shortcode function in the functions.php, but the text editor in the Unit is not parsing it. It is only displaying it as raw text. And if I type the iframe directly into the editor it is stripped out.

function iframe_shortcode($params, $content) {
    if(!$atts['width']) {
        $atts['width'] = 1500;
    }
    if(!$atts['height']) {
        $atts['height'] = 790;
    }

    $html = '<iframe border="0" class="shortcode_iframe" src="'.$atts['src'].'" width="'.$atts['width'].'" height="'.$atts['height'].'"></iframe>';
    return $html;
}
add_shortcode('iframe', 'iframe_shortcode');
  • Michael Bissett

    Hey @Susan, hope you're doing well this evening! :slight_smile:

    Could you give an example as to how this shortcode is to be used? And have you already confirmed that it works on a non-CoursePress page?

    I'm seeing that there does appear to be some stripping taking place, but I'd like to make sure that shortcode of yours works properly before we proceed further. :slight_smile:

    Please advise,
    Michael

  • Susan

    First off, I apologize for posting bad code. I realized when I looked at my code that I had forgot to change my input parameter from $params to $atts. I have since made the change and below is the new code.

    function iframe_shortcode($atts) {
        if(!$atts['width']) {
            $atts['width'] = 1500;
        }
        if(!$atts['height']) {
            $atts['height'] = 790;
        }
        return '<iframe border="0" class="shortcode_iframe" src="'.$atts['src'].'" width="'.$atts['width'].'" height="'.$atts['height'].'"></iframe>';
    }
    add_shortcode('iframe', 'iframe_shortcode');

    This code is implemented by entering the shortcode value into the Post Editor:
    [iframe src="https://example.com/mydirectory/subdirectory/player.html"] I can't include the real URL that I'm using due to company regulations. However, I can confirm that I'm still having some troubles getting the shortcode to parse. It's just returning the shortcode in text format.

    I have confirmed that if I switch to the Default TwentyFourteen theme the shortcodes work as expected.

  • Ash

    Nope, there should not be anything needed.

    Just one thing, if you use default WP 2012 theme, does it work for you?

    If not, would you please send me admin login and ftp login so that I can check?

    To send me details, please use our contact form: https://premium.wpmudev.org/contact/

    Select: I have a different question
    Subject: Attn-Ash
    Details: Send all required details (admin info and/or ftp details) with a link of this thread, so that I can track.
    Also post a note here once you send the info.

    I will be happy to take a look :slight_smile:

    Cheers
    Ash