hook not working - link_full=1

By: Butum Tech | Asked: 08/15/2022
ForumsCategory: General questionshook not working - link_full=1
Butum Tech asked 2 years ago
dear all,   i need urgently your support   the below hook is not linking the attachments to the images... it links the entry link only -----------------------------------------------------
add_filter('frmpro_fields_replace_shortcodes', 'frm_make_shortcode', 10, 4);
function frm_make_shortcode($replace_with, $tag, $atts, $field){
  if(isset($atts['link_full'])){
     $new_val = '';
     foreach((array)$replace_with as $v){
       if(is_numeric($v)){
         $full = wp_get_attachment_image_src($v, 'full');
         $thumb = wp_get_attachment_image_src($v);
         $new_val .= '<a href="'. $full[0] .'"><img src="' . $thumb[0] . '" /></a>';
       }
     }
     return $new_val;
  }
  return $replace_with;
}

-------------------------------------------

i used this code at the view field [212 link_full=1] where 212 is the field id containing the attachments.

do you have any recommendation?

the image of the attachment is linked to entry not to the attachment

thanks alot


1 Answers
Victor Font answered 2 years ago
I just ran your code in my test environment and it works although the HTML you're passing back to the shortcode is not well formed. You need to add a class or wrap each link in a div otherwise the thumbnail displays are stacked one upon the other. When Formidable uploads images, a record is added to the WordPress Media Library. The URL is pointing to the image url wp-content/uploads/formidable/[dir]/[file_name]. All the thumbnails for the image are in that directory. It doesn't matter if you use wp_get_attachment_image_src(), wp_get_attachment_url(), or get_the_guid(), they will all return the same value pointing to the image in Formidable's upload directory. Make sure 212 is the ID of the upload field.
Butum Tech replied 2 years ago

Thank you Victor for you feedback, you have pointed the case clearly.

Excuse our basic knowledge in coding, we tried to wrap each link in div but it seems we did not code it well.
Can you support with that?
thanks

Victor Font replied 2 years ago

If you need a developer to write code for your project, I'm not the one who can do it for you. I don't have the bandwidth to take on any more projects at present. I suggest you look at the Formidable Masterminds Developers Directory to locate a resource: https://formidable-masterminds.com/developers-directory/

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right