Created
April 1, 2023 16:53
-
-
Save ali7ali/7acd3473fa48b613e569b1bb42e83037 to your computer and use it in GitHub Desktop.
WordPress Shortcode to add an iFrame dynamically
This file contains 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 | |
function custom_html_render_shortcode_wp5431($attr) | |
{ | |
$id = (isset($attr['id']) && !empty($attr['id'])) ? sanitize_text_field($attr['id']) : null; | |
$height = (isset($attr['h']) && !empty($attr['h'])) ? sanitize_text_field($attr['h']) : '160'; | |
$height .= (isset($attr['h_unit']) && !empty($attr['h_unit']) && $attr['h_unit'] == 'pixel') ? 'px' : '%'; | |
$width = (isset($attr['w']) && !empty($attr['w'])) ? sanitize_text_field($attr['w']) : '100'; | |
$width .= (isset($attr['w_unit']) && !empty($attr['w_unit']) && $attr['w_unit'] == 'pixel') ? 'px' : '%'; | |
$page = (isset($attr['page']) && !empty($attr['page'])) ? sanitize_text_field($attr['page']) : null; | |
ob_start(); | |
if (!$id) : | |
echo '<div class="url-missing">Please, Enter a valid ID</div>'; | |
else : ?> | |
<iframe style="width:<?php echo esc_attr($width); ?>; height:<?php echo esc_attr($height); ?>;" src="https://<?php echo esc_attr($id) ?>.exprealty.com/<?php echo esc_attr($page); ?>" allowtransparency="true" frameBorder="0"> </iframe> | |
<?php endif; | |
return ob_get_clean(); | |
} | |
add_shortcode('exprealty-code', 'custom_html_render_shortcode_wp5431'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment