Do I need to create new param type since there is no “attach_file”-type in https://wpbakery.atlassian.net/wiki/pages/viewpage.action?pageId=524332#vc_map()-Availabletypevalues
How come this kind of element is missing?
What I need is “Attach file”-button to backend.
I have just had the same issue as you and the is what I came up with.
This allows for adding a visual composer content element in which you can select any file from the WordPress media manager (and remove the file selection).
Separate this from the rest of your functions (use a modular approach).
In your templates
functions.php
addAdd your new shortcode param
In
your_template/functions/vc-functions.php
add@ojrask was right – note the 3rd param of
vc_add_shortcode_param
. This is where we add the script for the media manager.Note that this saves the attachment id but shows the url. Using the attachment id is better for use in other WP functions (handy when you want to do things for the front end output).
Add your js
In
your_template/vc_extend/file_picker.js
addUse your newly created param type
The param can now be used in you vc_map(). This should also go in
your_template/functions/vc-functions.php
and should be something likeOutput
To show the output on the front end create the file
your_template/vc_templates/your_element_base.php
and add something likeThis will output just the url to whatever file was selected.
The following resources were useful in making this:
vc_map docs https://wpbakery.atlassian.net/wiki/pages/viewpage.action?pageId=524332
creating new param types https://wpbakery.atlassian.net/wiki/display/VC/Create+New+Param+Type
adding the media manager script https://wordpress.stackexchange.com/a/82874/99164