Creating a custom img tag in contact form 7
-
Created a custom [img] tag for contact form 7 to image the current post/product. I managed to display an image of the product in the feedback form that I created, but I cannot convey this image in the letter. I’ve tried different options:
- Generated a url of the type uploads/data/…/.jpg (since the documentation says that for security reasons, everything that is behind the /wp-content/ aisles will not be considered.
- I used the [img] tag in the area for attached files and in the body of the letter.
- I set the name [img img-name] and used it in the area for attached files and in the body of the letter.
Nothing helped. If someone knows how I can solve this issue. Please tell me.
My function
/** * Return product image for CF7 tag. * * @param array $tag * @return string */ function custom_add_form_tag_img_handler($tag) { global $post; // Use $post to get the current post object. // Check if we're on a WooCommerce product page. if (function_exists('is_product') && is_product()) { $product_id = get_the_ID(); // Get the current post (product) ID. $product = wc_get_product($product_id); // Get the product object. $image_url = get_the_post_thumbnail_url($product_id); if ($image_url) { return '<img src="' . esc_url($image_url) . '" alt="Изображение товара">'; } // if ($image_url) { // return ltrim(wp_make_link_relative(esc_url($image_url)), '/wp-content/' ); // } } return ''; } /** * Hook to add custom 'img' tag to CF7. * Usage in CF7: [img] */ function custom_add_form_tag_img() { wpcf7_add_form_tag('img', 'custom_add_form_tag_img_handler', array( 'name-attr' => true )); } add_action('wpcf7_init', 'custom_add_form_tag_img');
The page I need help with: [log in to see the link]
- The topic ‘Creating a custom img tag in contact form 7’ is closed to new replies.