coderz_studio

Guide to Add Custom Attributes to iFrame Widget

Apr 20th, 2025 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | Help | 0 0
  1. In the Custom iFrame plugin, a hook has been added that lets you add a custom title attribute (or any other attribute) to your iframe widget — even if you’ve added the same widget multiple times on the same page.
  2.  
  3. Here’s how you can do it step-by-step 👇
  4.  
  5. ✅ Step 1: Add a Custom ID to your iframe widget
  6. 1. Open the page with Elementor.
  7. 2. Click on the iframe widget.
  8. 3. Under the Content tab, scroll to the Advanced section.
  9. 4. Add a unique ID like this: contact-form-iframe or pricing-table-iframe — anything that helps you identify the widget.
  10.  
  11. ✅ Step 2: Add this code snippet to your theme’s functions.php file or use the Code Snippets plugin:
  12.  
  13. -----------------------------------------------------------------------------------
  14. add_filter( 'custif_iframe_attributes', function( $attrs, $settings ) {
  15. $custom_id = $settings['custif_custom_id'] ?? '';
  16.  
  17. if ( 'iframe-one' === $custom_id ) {
  18. $attrs['title'] = 'Contact Form';
  19. } elseif ( 'iframe-two' === $custom_id ) {
  20. $attrs['title'] = 'Pricing Table 2';
  21. }
  22.  
  23. return $attrs;
  24. }, 10, 2 );
  25. -----------------------------------------------------------------------------------
  26.  
  27. ✅ Step 3: Add more conditions if needed
  28.  
  29. You can keep adding more elseif conditions in the same code if you want to apply different titles for more iframe widgets.
  30.  
  31. -----------------------------------------------------------------------------------
  32. elseif ( 'video-iframe' === $custom_id ) {
  33. $attrs['title'] = 'Promo Video';
  34. }
  35. -----------------------------------------------------------------------------------
  36.  
  37. That’s it! 🎉
  38.  
  39. This gives you full control to set different titles (or other attributes) for each iframe based on the
  40. custom ID you set.
  41.  
  42.  
  43.  
Advertisement
Add Comment
Please, Sign In to add comment