admin管理员组文章数量:1122832
Hi I am trying to add dynamic tags to the wordpress "image" widget, so that I will be able to choose custom featured image: second-featured-image and third-featured-image. These second and third images are working, I have created it a custom code and if I retrieve them with normal code i see them appearing, so meaning the get saved to the database.
I have it almost working, but the most important, showing the image on the front end is not working.
I have created a folder called: custom-efi-dynamic-tags in the plugin folder. In this folder I have created file called custom-efi-dynamic-tags.php and a folder calles includes, where I have my second featured tag code in the file: class-second-featured-image-tag.php
I am wondering why the image is not loading.
I have tried codes and read the documentation of elementor on this topic, but I am somehow not able to get the images.
<?php
/**
* Plugin Name: Custom EFI Dynamic Tags
* Description: Adds custom dynamic tags for Elementor for second and third featured images.
* Version: 1.0.0
* Author: Your Name
* Text Domain: custom-efi-dynamic-tag
*/
namespace Custom_Efi_Dynamic_Tag;
use Elementor\Plugin;
use Elementor\Core\DynamicTags\Tag;
class Efi_Plugin {
private static $_instance = null;
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
public function __construct() {
add_action( 'init', array( $this, 'init' ) );
}
public function init() {
add_action( 'elementor/dynamic_tags/register_tags', [ $this, 'register_dynamic_tags' ] );
}
public function register_dynamic_tags( $dynamic_tags ) {
error_log('Registering dynamic tags...');
\Elementor\Plugin::$instance->dynamic_tags->register_group( 'custom-dynamic-tags', [
'title' => 'My Custom Dynamic Tags'
]);
include_once( plugin_dir_path( __FILE__ ) . 'includes/class-second-featured-image-tag.php' );
include_once( plugin_dir_path( __FILE__ ) . 'includes/class-third-featured-image-tag.php' );
$dynamic_tags->register_tag( 'Custom_Efi_Dynamic_Tag\Second_Featured_Image_Tag' );
$dynamic_tags->register_tag( 'Custom_Efi_Dynamic_Tag\Third_Featured_Image_Tag' );
error_log('Dynamic tags registered.');
}
}
if ( ! function_exists( 'Plugin' ) ) {
function Efi_Plugin() {
return Efi_Plugin::instance();
}
}
Efi_Plugin();
and my second featured images looks like this:
<?php
namespace Custom_Efi_Dynamic_Tag;
use Elementor\Core\DynamicTags\Tag;
use Elementor\Modules\DynamicTags\Module;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Second_Featured_Image_Tag extends Tag {
public function get_name() {
return 'second-featured-image';
}
public function get_title() {
return __( 'Second Featured Image', 'custom-efi-dynamic-tag' );
}
public function get_group() {
return 'custom-dynamic-tags';
}
public function get_categories() {
return [ Module::IMAGE_CATEGORY ];
}
protected function register_controls() {
// No additional controls required for this dynamic tag.
}
public function render() {
$second_featured_image_url = get_post_meta( get_the_ID(), '_second_featured_image', true );
if ( empty( $second_featured_image_url ) ) {
error_log('No URL found for second featured image.');
return;
}
error_log('Rendering image: ' . $second_featured_image_url);
echo '<img src="' . esc_url( $second_featured_image_url ) . '" alt="' . esc_attr__( 'Second Featured Image', 'custom-efi-dynamic-tag' ) . '">';
}
}
What am I missing that the images are not showing if i choose them from the dymanic tag?
Thanks already.
本文标签: pluginsCustom Dynamic Tag in Elementor not showing image
版权声明:本文标题:plugins - Custom Dynamic Tag in Elementor not showing image 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736295761a1929639.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论