• Resolved ehuds

    (@ehuds)


    Hello,
    Can some one help me please?
    I want to dynamic add pods url field to iframe and to show it on pods custom post type.
    I think the way to do it is to create short code in function.php with iframe and dynamic src that will be the pods url field. and then add it to the template for that custom post type.
    But I can’t figure it out.
    Any help please?
    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Paul Clark

    (@pdclark)

    Hi @ehuds,

    The following code will add an iFrame to the end of the content for post type post and meta key iframe_url.

    It can be installed as a plugin, in a theme’s functions.php, or using the Snippets plugin:

    <?php
    /**
     * Plugin Name: iFrame in Post Content
     * Description: Add an iFrame to post type <code>post</code> if meta key <code>iframe_url</code> is set.
     */
    add_filter(
    	'the_content',
    	function( $c ) {
    		$meta_key = 'iframe_url';
    		$post_type = 'post';
    
    		if ( $post_type !== get_post_type() || empty( get_post_meta( get_the_ID(), $meta_key, true ) ) ) {
    			return $c;
    		}
    
    		return $c . sprintf(
    			'<style>
    				.entry-content iframe { width: 100%%; max-width: 100%%; height: 70vw; margin: 20px 0 20px 0; border: none; }
    			</style>
    			<iframe src="%s"></iframe>',
    			esc_url( get_post_meta( get_the_ID(), $meta_key, true ) )
    		);
    	},
    	PHP_INT_MAX
    );
    Thread Starter ehuds

    (@ehuds)

    Thank you,
    I did found a way to do it, what do you think?
    using the custom field from pods custom post and adding it in Elementor template for that post type. working good.

    // Create shortcode to show Yacht 3D tour.
    function yacht_3d_iframe() {
    	$yacht = pods('yacht', get_the_ID())
    	?>
    		<iframe src="<?php echo $yacht->field('virtual_tour'); ?>" height="500"></iframe>
    	<?php
    }
    add_shortcode('yacht_3d', 'yacht_3d_iframe');
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘use pods url field in iframe’ is closed to new replies.