• I have created a custom dynamic Tag of category image to show an image in the frontend.
    It doesn’t seem to work. What am I doing wrong?

    <?php
    
    class Custom_Picture_Tag extends \Elementor\Core\DynamicTags\Tag
    {
        public function get_categories()
        {
            return [ \Elementor\Modules\DynamicTags\Module::IMAGE_CATEGORY ];
        }
    
        public function get_group()
        {
            return "additional-data";
        }
    
        public function get_title()
        {
            return "image";
        }
    
        public function get_name()
        {
            return "image";
        }
    
        protected function render()
        {
            return [
                    'id' => 1,
                    'url' => wp_get_attachment_image_src(1, 'full')[0],
                ]; 
        }
    }

    I have removed the rest of my code for demonstration purpose, but the main issue is that even this simple code block doesn’t work.
    The url does exist! So that should not be the issue.

    in functions.php:

    add_action( 'elementor/dynamic_tags/register_tags', function( $dynamic_tags ) {
        \Elementor\Plugin::$instance->dynamic_tags->register_group( 'additional-data', [
            'title' => 'Additional data'
        ] );
    
        include_once(SP_SRCDIR . '/Tags/Custom_Picture_Tag.php');
        $dynamic_tags->register_tag('Custom_Picture_Tag');
    } );

    Thank you very much!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,

    Since this is a development based query, may opt to visit our Github account where you may get in contact with a member of our development team to query this with.

    Please note that this is not an official support channel but a respective member of the development team will respond to your post as soon as they are available.

    Please follow this guide which outlines the steps required to post on our Github: https://github.com/pojome/elementor/blob/master/.github/CONTRIBUTING.md

    Kind regards,
    David

    Anonymous User 14940404

    (@anonymized-14940404)

    @tomberry98 don’t know if this ticket is still relevant … but I ran into the same issue … the trick is that you should use the Data_Tag Parent class and not the Tag Class. In this class you have the function get_value instead of render and then you can return an array ??

    You’ll find one example of this in this file of the elementor pro plugin
    /elementor-pro/modules/dynamic-tags/tags/author-profile-picture.php

    Cheers,
    Dominik

    for URL, Image, Media and Gallery controls, you need to extend Elementor\Core\DynamicTags\Data_Tag .
    use this code

    class Custom_Picture_Tag extends \Elementor\Core\DynamicTags\Data_Tag
    {
        public function get_categories()
        {
            return [ \Elementor\Modules\DynamicTags\Module::IMAGE_CATEGORY ];
        }
    
        public function get_group()
        {
            return "additional-data";
        }
    
        public function get_title()
        {
            return "image";
        }
    
        public function get_name()
        {
            return "image";
        }
    
        public function get_value( array $options = array() )
        {
            return [
                    'id' => 1,
                    'url' => wp_get_attachment_image_src(1, 'full')[0],
                ]; 
        }
    }
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom dynamic tag image doesn’t work’ is closed to new replies.