Skip to content

Instantly share code, notes, and snippets.

@dannydickson
Last active May 19, 2017 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannydickson/215ddcdf439429abe7ca5c1737378545 to your computer and use it in GitHub Desktop.
Save dannydickson/215ddcdf439429abe7ca5c1737378545 to your computer and use it in GitHub Desktop.
Add iFrame to WordPress Widgets
<?php
/* Do not inlude the first 4 lines of this code. Only copy the code below this line. This should be
placed in your main functions.php to enable this globally, or on specific page templates */
//* Allow shortcodes to execute in widget areas
add_filter('widget_text', 'do_shortcode');
// Register function to allow shortcodes
function add_iframe($atts) {
extract(shortcode_atts(array(
'src' => '/'
), $atts));
$theframe = '<iframe src="'.$src.'" width="100%" height="450" frameborder="0"></iframe>';
return $theframe;
}
// Call function to allow iframe
add_shortcode('iframe', 'add_iframe');
@dannydickson
Copy link
Author

Now you can add iframes for specific pages or Google Map embeds (which is why I was trying to get this figured out).

Example: [iframe src=http://thesiteyouwanttoshow.com] <---update the URL to be anything you want to iframe into your widget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment