Set iframe display format for the attribute

I want to take a virtual walk .To do this I have to put an <iframe> in the attributes there is no such option there.

If it is a listing attribute then please try this PHP snippet. Please change attribute_slug_field_name on the attribute slug/field name where you want to add the iframe

add_filter( 
	'hivepress/v1/models/listing/attributes', 
	function ($attributes){
		if(isset($attributes)){
			$attributes['attribute_slug_field_name']['display_format'] = '<iframe src="%value%"></iframe>';
		}

		return $attributes;
	}, 
	1000
);

After pasting into function.php, I get an error
Warning : Undefined array key “type” in C:\xampp\htdocs\hivepress\wp-content\plugins\hivepress\includes\models\class-model.php on line 145

I changed the class-url.
I added url there.
It works.
Will it still work after the update?

<?php

/**

 * URL field.

 *

 * @package HivePress\Fields

 */

namespace HivePress\Fields;

use HivePress\Helpers as hp;

// Exit if accessed directly.

defined( 'ABSPATH' ) || exit;

/**

 * URL.

 */

class URL extends Text {

    /**

     * Class initializer.

     *

     * @param array $meta Class meta values.

     */

    public static function init( $meta = [] ) {

        $meta = hp\merge_arrays(

            [

                'label'      => esc_html__( 'URL', 'hivepress' ),

                'filterable' => false,

                'sortable'   => false,

                'settings'   => [

                    'min_length' => null,

                    'max_length' => null,

                    'pattern'    => null,

                ],

            ],

            $meta

        );

        parent::init( $meta );

    }

    /**

     * Class constructor.

     *

     * @param array $args Field arguments.

     */

    public function __construct( $args = [] ) {

        $args = hp\merge_arrays(

            $args,

            [

                'max_length' => 2048,

            ]

        );

        parent::__construct( $args );

    }

    /**

     * Sets field display template.

     *

     * @param string $display_template Display template.

     */

    protected function set_display_template( $display_template ) {

        if ( strpos( $display_template, '<a ' ) === false && ! hp\has_shortcode( $display_template ) ) {

            $display_template = str_replace( '%value%', '<iframe src="%value%" width="100%" height="300px" name="_blank" >%value%</iframe> <a href="%value%" target="page">Wirtualny spacer pokaż w nowym oknie</a>', $display_template );

        }

        $this->display_template = $display_template;

    }

    /**

     * Sanitizes field value.

     */

    protected function sanitize() {

        $this->value = esc_url_raw( $this->value );

    }

}

Please don’t make changes in the code directly because any changes may be lost on updates. Please try to use the suggested snippet and save it with the Code Snippets plugin (or the similar one) or the child theme

I have added this code snippet.
Nothing is happening.
Can you explain me how to do it correctly?

https://nieruchomosci-budownictwo.pl

Please help

Please replace the attribute_slug_field_name with the attribute name (wirtualnyspacer), it should be ok then - this was just a sample name since I didn’t know the attribute name you’re using.

field type = embedded content.

does not read% value%
reads width: 299

Please try switching the attribute type to URL, and make sure that the value is set for this listing. Then if the attribute name in the snippet is correct, the “src” attribute of the iframe will get the entered URL.

when changed to url it does <iframe src = “<a href =” …

I modified the code in Code Snippets in iframe
And it works.
I don’t know how but it works :slight_smile:)

And it works.
I don’t know how but it works :slight_smile:

https://nieruchomosci-budownictwo.pl/oferta/qwe/

Awesome, I’m glad this is resolved, you can also try to make this attribute full-width via CSS if required. We also plan to add more display areas for attributes.

Thank you for your help :slight_smile: