Tell us what you are trying to do?
I'm trying to create an easy to use method for a client to load a pdf document into the media library, add a title, and see the title as the link on the front end in the page.
Is there any documentation that you are following?
I had asked about using an image to achieve this, but creating an image for each pdf involves designer work for each upload, so I will need further assistance.
Is there a similar example that we can see?
What is the link to your site?
hidden link is the development site.
If you need admin login please send private message.
Hello,
There isn't such a built-in feature within Types shortcode, it needs custom code, you can try the solution of another thread:
https://toolset.com/forums/topic/file-post-field-displaying-file-title-text-rather-than-file-path/#post-562737
For your reference.
I've added the code (inserting my types field name and leaving everything else as it is) to my functions.php child theme file, but I have one question about adding the shortcode to the link in the content template.
This is what I have:
[my_file_name types_field="certifications"]
But it is still returning the file URL.
Can I ask you to login and check the functions file for me? Or is there a simple mistake in the link shortcode?
OK, please provide a test site with the same problem, also point out the problem page URL and view URL, I need a live website to test and debug the custom codes. thanks
Thanks for the details, I can login your website, will update here if there is anything found
I have done below modification in your website:
1) Modify the PHP codes as below:
add_shortcode( 'my_file_name', 'my_file_name_func'); // Actually activate the shortcode
function my_file_name_func($atts) {
global $post; // So we can get the post meta later on
$res = ''; // Setting up a variable to hold the links so we can return it later
$types = $atts['field'];
if ($types) { // if the types_field argument was provided
//define ShortCode attr prefix
$types = "wpcf-$types";
$urls = get_post_meta($post->ID,$types); // let's get the (potentially multiple) values
$arr = array();
foreach ($urls as $fileurl) { // Let's iterate for each of the multiple values
$id = pippin_get_image_id($fileurl);
$title = get_the_title($id);
$arr[] = '<a href="' . $fileurl . '">' . $title . '</a>'; // Create whatever HTML and store it in the $content variable
}
$res = implode(' | ', $arr);
}
return $res; // Return the content as the shortcode value
}
2) Edit the content template
hidden link
in block "certifications", add below shortcode:
{!{my_file_name field='certifications'}!}
Please test again, check if it is fixed, thanks
Thank you. It's working fine if there is data in the "certifications" field. However, if the field is blank, it is returning the URL of the post on the front end. To see the problem look at: hidden link
for example.
I appreciate your help.
Let me know if you need credentials again.
I have changed the PHP codes to:
function my_file_name_func($atts) {
global $post; // So we can get the post meta later on
$res = ''; // Setting up a variable to hold the links so we can return it later
$types = $atts['field'];
if ($types) { // if the types_field argument was provided
//define ShortCode attr prefix
$types = "wpcf-$types";
$urls = get_post_meta($post->ID,$types); // let's get the (potentially multiple) values
if(empty($urls[0])){
return;
}
$arr = array();
foreach ($urls as $fileurl) { // Let's iterate for each of the multiple values
$id = pippin_get_image_id($fileurl);
$title = get_the_title($id);
$arr[] = '<a href="' . $fileurl . '">' . $title . '</a>'; // Create whatever HTML and store it in the $content variable
}
$res = implode(' | ', $arr);
}
return $res; // Return the content as the shortcode value
}
Please test again, check if it is fixed, thanks