I have aded a bunch of fields to my content template.
Now I need to add the filename of the featured image as well.
I followed the following post but seems I'm doing something wrong. It's not working.
https://toolset.com/forums/topic/display-file-name-of-uploaded-file-from-user-field/
I added the shortcode in settings, and then added the shortcode in the content template, but it's not displaying.
How do I do that? See attached images
Thanks in advance
Hello,
I suggest you try these:
1) Modify the custom PHP codes as below:
add_shortcode( 'wpv_display_file_name', 'wpv_display_file_title_func');
function wpv_display_file_title_func($atts, $content) {
global $wpdb;
$atts = shortcode_atts( array(
'url' => '',
'info' => '', // title, alt or id return
), $atts);
$res = '';
$url = do_shortcode($content);
$attachment_id = $wpdb->get_var($wpdb->prepare(
"SELECT ID FROM $wpdb->posts WHERE guid = %s", $url
));
if($atts['info'] == 'title'){
$res = get_the_title($attachment_id);
}
if($atts['info'] == 'alt'){
$res = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
}
if($atts['info'] == 'id'){
$res = $attachment_id;
}
if($atts['info'] == 'name'){
$path_parts = pathinfo($url);
$res = $path_parts['filename'];
}
return $res;
}
More help:
hidden link
2) Use above shotcodes as below:
[wpv_display_file_name info="name"][wpv-post-featured-image output="url" size="full"][/wpv_display_file_name]
I am not a developer.
Could you guide me where I need to change this code in WP?
Will updates overwrite my code?
Thanks
You can try these:
Dashboard-> Toolset-> Settings-> Custom Code,
https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/
find and edit existed custom codes as I mentioned above
https://toolset.com/forums/topic/add-filename-as-field-on-front-end/#post-2482867
And test again
If you need more assistance for it, please provide a test site with the same problem, fill below private message box with login details, also point out the problem post URL of your screenshot:
https://toolset.com/wp-content/uploads/2022/10/2482571-2022_10_24_13_12_14.png
I did everything you mentioned, but it is still did not working
hidden link
how can I give you access securely?
I have enabled the private detail box, please provide your website credentials in it.
Thanks for the details, you just need to activate that custom codes snippet, for example:
Dashboard-> Toolset-> Settings-> Custom Code, find the item "filename", click the link "Activate", see the result here:
hidden link