• Resolved nemillimen

    (@nemillimen)


    Hi, my first post here. Pls blow my mind away.

    I need to customize VC’s Single Image element from my plugin.
    I found this:

    add_filter( 'vc_shortcode_set_template_vc_single_image', array(
    $this,
    'addVcSingleImageShortcodesTemplates',
    ) );

    and:

    public function addVcSingleImageShortcodesTemplates( $template ) {
    $file = vc_path_dir( 'TEMPLATES_DIR', 'params/vc_grid_item/shortcodes/vc_single_image.php' );
    if ( is_file( $file ) ) {
    return $file;
    }
    return $template;
    }

    in class-vc-grid-item.php.

    I know for a fact that vc_single_image.php is the file that runs when displaying images on the site, but I can comment out the function addVcSingleImageShortcodesTemplates and it will still run without errors (and images will be displayed). I dont see how remove_filter( ‘vc_shortcode_set_template_vc_single_image’,…) could help.

    Could anyone explain to me how this works? How can I customize vc_single_image.php (I need to add more html tags to an image) from my plugin?
    Right now I have hard-coded my changes in vc_single_image.php and ofc they will be overwritten when VC updates.

    Unfortunately I cant link to project because problem is in admin panel.

    Any help is appreciated!

    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Have a look here:
    https://codex.wordpress.org/Plugin_API#Filters
    An explanation on removing filters follows.

    By using a filter, you plugin can force your own version of the file to be used, a version safely kept with your plugin code. No matter how may times VC updates, your file stays the same. As long as the filter continues to be applied in the VC code, you file will continue to be used.

    You don’t even really need to remove the current filter in this case, just add yours with a later priority so it gets the last say in what file to use.

    Thread Starter nemillimen

    (@nemillimen)

    Thank you bcworks.

    Looks like I did not understand the filters correctly..

    Solution:

    add_filter( 'vc_shortcode_set_template_vc_single_image', 'addVcSingleImageShortcodesTemplatesCustom_551124' );
    
    function addVcSingleImageShortcodesTemplatesCustom_551124() {
    	$file = plugin_dir_path( __FILE__ ) . '/template_override/vc_single_image.php';
    	return $file;
    }

    Now the vc_single_image.php is in my plugin directory and cant be overwritten plus I can customize the content.

    Thanks for the help.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Customize Visual Composer Single Image element’ is closed to new replies.