Last active
May 19, 2017 05:26
-
-
Save dannydickson/215ddcdf439429abe7ca5c1737378545 to your computer and use it in GitHub Desktop.
Add iFrame to WordPress Widgets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.