Advertisement
adczk

shortcode for iframes

Mar 28th, 2023
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. <?php
  2.  
  3. function custom_html_render_shortcode_wp543( $attr ){
  4.  
  5.     $id = ( isset( $attr['id'] ) && !empty( $attr['id'] ) ) ? sanitize_text_field( $attr['id'] ) : null;
  6.     $width = ( isset( $attr['w'] ) && !empty( $attr['w'] ) ) ? sanitize_text_field( $attr['w'] ) : '160';
  7.     $width .= 'px';
  8.     $page = ( isset( $attr['page'] ) && !empty( $attr['page'] ) ) ? sanitize_text_field( $attr['page'] ) : null;
  9.  
  10.     ob_start();
  11.  
  12.     if( !$id ):
  13.         echo '<div class="url-missing">Please, Enter a valid ID</div>';
  14.     else: ?>
  15.  
  16.     <iframe style="width:100%; height:<?php echo esc_attr( $width ); ?>;" src="https://<?php echo esc_attr( $id ) ?>.exprealty.com/<?php echo esc_attr( $page ); ?>" allowtransparency="true" frameBorder="0"> </iframe>
  17.  
  18.     <?php endif;
  19.  
  20.     return ob_get_clean();
  21.  
  22. }
  23. add_shortcode('exprealty-code','custom_html_render_shortcode_wp543');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement