You can try this code to add the new attribute in the html code:
$dom = new DOMDocument();
$dom->loadHTML($html);
foreach ($dom->getElementsByTagName("a') as $item) {
$item->setAttribute('data-caption', 'This is an anchor tag');
echo $dom->saveHTML();
exit;
}
Related Posts:
- Move captions under gallery images in twenty fourteen theme
- Remove Captions from Custom Gallery function.php
- Customize WordPress Media Manager – Media Window
- Gallery images titles – get from post
- How to use thumbnails in gallery?
- Display gallery on top before content
- Converting html to wordpress images not showing
- Getting Featured Image Caption to Only Show if Populated
- Default Gallery Edit/Template Editable?
- Shortcode pagination not advancing
- Add caption functionality to custom WordPress theme
- Help with WP gallery function, wrap gallery in div
- how can I edit flexslider in woocommerce. [Urgent]
- Custom Attachment Caption Fields
- Display gallery on bottom after content
- Way to add captions to gallery images by code
- watermarking gallery items
- Functions Error: Impacting Galleries
- Native gallery custom html output
- Check if a different page has any attached images
- Render metabox gallery in frontend
- a SET of wordpress native galleries with title and text?
- Customise the WordPress gallery html layout
- Add gallery id to rel attribe of wp_get_attachment_link
- Dynamically adding Captions to images
- Gallery Shortcode Function Help
- Get the ID of the page a menu item links to?
- Add container to nav_menu sub menu
- One Child Functions.php for Multiple Child Themes
- Disabling pingback and trackback notifications
- register_post_type for Pages?
- Paged Single Post doesn’t redirect to the main url after Removing Pagination
- How to get comments with mixed status using get_comments?
- How can I rename the WordPress AJAX URL? [duplicate]
- How to add a rel attribute to images that contains their categories?
- Is it possible to be more page/post specific with admin_enqueue_script?
- Enqueue script o style only if a template part is loaded
- Can I pass two roles to the function get_users?
- Add external js file to footer with id
- wp_enqueue JavaScript in child-theme (ReferenceError) using Search & Go
- How can I enable uploading excel files?
- Translation of theme using child theme
- Last Login in number of days format
- Display post shortcode content in the sidebar?
- IF Statement on Button to make it complete and “uncomplete” based on user action / click
- Gravity Forms Button Text
- How to use wp_trash_post (or wp_delete_post) for deleting a (or all) post(s) from custom post type?
- change the url paths in the stylesheet dynamically
- When sale price is 0.00 show only regular price
- Dumping variable in custom pre_gets_post function in functions.php, returns NULL
- How to load parent theme template parts in child theme
- allow only one post in specific category
- ACF not showing
- Cannot modify header information – headers already sent (wp_redirect in functions.php)
- Javascript function not working when placed in Text Block
- Need help getting a function to function
- How to remove comment count column in Posts inside the admin dashboard?
- Cannot declare function twice [closed]
- Running script based on Category
- Get array of metakey in all posts
- How do I hook into the container of wp_nav_menu?
- Remove links from the_content when using filters wp_trim_excerpt
- Function not working inside of a function in functions.php
- How to Use Global Variables Inside Header and Footer
- Redirect website domain (including all pages) to external URL after Popup message (few seconds)
- Where do I go to edit this area? [closed]
- Enable right click on WordPress site
- This code works, but the way I integrated it is breaking the media uploader. How can I integrate it properly?
- Email Exists ERROR into Ajax registration form
- How to overwrite template.php file
- Limit number of characters in different excerpts
- How to avoid saving empty data to sql while using add_meta_box
- How to assign php file(template) to several pages with same prefix page name/slug
- How to fix Function create_function() is deprecated in / themes
- Block all plug-ins from initiating redirection upon activation?
- How to display my comment count in the wordpress admin bar?
- custom error message for empty username and password using authenticate filter not working
- Modifying a WordPress Plugin
- Last updated posts shortcode in functions.php
- I have an fatal error on my funcyions.php
- Get post_author email for Zapier Integration
- get_locale() is different from $locale
- If click on Save/Publish change Post Status to Pending Review instead Publish
- Remove all video attachment, both files and post/postmeta from database?
- Remove the delete link from pages without a plugin
- Custom download page
- HowTo: Add wrapper to columns shortcode?
- How to include a hyperlink in the body text of a custom password protected form?
- Get title from IDs in a string
- uninstall a theme programmaticlly
- Dynamically generated Navigation Diagram using Custom Fields
- Update add_image_size
- Function to get the name in database table from the comma separated string
- Full size image option removing problem
- Limit length of headline in Editor
- Way of getting queried loop before the query with a filter hook?
- Why my wp_enqueue_script doesnt work on some page?
- Need to use an external variable inside a function
- Trying to get this function to show below the content
- Using input_attrs() Multiple Times Within One Customizer Control