instead of replacing the alt tag you could add-an-attribute-to-a-tag
function add_lazyload($content) {
$dom = new DOMDocument();
@$dom->loadHTML($content);
foreach ($dom->getElementsByTagName('img') as $node) {
$oldsrc = $node->getAttribute('src');
$node->setAttribute("data-original", $oldsrc );
$newsrc="".get_template_directory_uri().'/library/images/nothing.gif';
$node->setAttribute("src", $newsrc);
}
$newHtml = $dom->saveHtml();
return $newHtml;
}
note: i didn’t quite tested this code, so be careful 🙂
Related Posts:
- Unattaching images from a post
- How to wrap every image in a post with a div?
- how to replace embedded “full” sized images within a post with the “large” ones
- wp-cli post create & media import issues
- How to allow multiple thumbnail upload for Posts?
- Modified core/image rendering not showing in posts – only on pages
- Customizing individual images on posts
- Remove Categories / Tags From Admin Menu
- Setting Custom Sort Order of Posts within a Category
- Delete the original big size image after upload and leave only 3 images crunched by media gallery
- Custom permalink structure only for default posts
- Is this the best (and only) option to style CSS for a given post type?
- Sort post by attributes ‘order’
- How to change the layout and styling of posts according to their category in WordPress?
- Pagination not working on Custom Page Template
- upload featured image from front end using wordpress add media button
- Retrieving and Storing Images Linked from Other Domains on Local Server?
- Add custom field to category of custom post type
- Display custom post types by date field
- How to hook a function only when I need to delete permanently a post?
- What Can I Use To Add A Custom Button Between Publish button and Move To Trash?
- user contributed content as custom post types
- Custom Theme Want To Remove One Category From All Displays
- Is there any WordPress alternative to Book module of Drupal?
- How to get only text from wordpress post content?
- wp_query ‘s’ parameter does not work with custom post type
- How to start with post number x?
- Get all images out of the posts content
- Best way of deletion of old posts [closed]
- Sidebar links for different pages
- How to retrieve the postID in a “image_send_to_editor” hook function?
- Deleted category by mistake, all posts now have categorized category. Can i revert that?
- How to display data in archive page?
- Delete post by giving its link
- How to make classes for posts?
- Set size for attachments
- CPT archive redirects to single post
- I have a site where attachments in the wp_posts table have guid values of guid, how did this happen?
- Getting Custom Post Loop to display in Bootstrap 3 column grid
- Turn On Comments On Custom Post Types in Directory Theme
- ERROR: Your feed is invalid (after update WP4.7) in custom types
- Automatically add date to the auto generation of post slug
- Duplicate Custom Post Type and Taxonomy Slug
- How could I change my Permalink from blog to custom structure? [closed]
- WP Admin register taxonomy and post type performance
- WordPress Multisite – Create Default Post and New Category On New Site Install
- How to allow visitors to filter posts by multiple taxonomies
- Show only posts with images and a fixed amount of posts
- If statement to check if post has image
- a little direction on custom post type
- What are the benefits of setting a “featured image” for a WP blog post?
- Format latest/newest post differently
- relating business and products with custom taxonomy?
- WordPress Query Posts From Category Post on Static Page
- Edit multiple custom post types while saving a new or edited post
- Create a custom posts page
- add external project to web site wordpress on production
- Deleted a user with administrator rights. Now all the data/content/images are lost. how to recover them back
- get_children returns older images
- How to display post title inside thumbnail?
- register_post_type permalink
- How to remove text and retain in caption image using the_content function
- Change default post style to columns
- Inserting Media to WordPress Posts
- Custom Post Type, post-formats associated to custom post type > 404 archives
- Help with listing current users submitted custom post type in template file
- Delete post from admin but not from database
- Only show featured image on exerpt and exclude images in post
- how can display a post on home screen without images
- Custom Select Query – Selecting the Year?
- Deleting old posts
- How To Use Custom Tax of a Post Type
- What would causes search to return incorrect results?
- Changing The Default Header POST Title and Description text by category in wordpress
- search form for custom fields
- Pinterest button shows image options from different posts
- Some custom post types did not return an object
- Display Post from Custom Post Type with Shortcode
- Tag for custom post type
- Not display an image of category of custom post
- Blog images not showing on homepage
- Manual Scheduler For Custom Post Type
- Dev and prod on the same database- dev version active for IOS
- How to delete/customize imported demo content from a theme or add my own?
- Integrate video and iframe in a post type gallery
- how to create other sizes of original image in one go wordpress uploads
- single- and archive- templates not being applied to custom post types, not even after flushing permalinks
- How to show content of specific item on the same page?
- How to list all names and descriptions of a custom taxonomy
- How can I have the posts from one word press blog show on the presentation page of another word press site
- WordPress Media URLs?
- Show a Category Specific Info Box
- Make a custom URL and link to custom Template
- Special Query: Title, Terms, Content – %LIKE%
- WordPress 3.2 – Problem with WYSIWYG editors in a custom post type?
- Assign custom class to post content images
- How to show only the date, the title and a little “summary” of my WordPress post in my custom theme?
- Dynamic Menu Item
- Changes done in admin panel are taking time to reflect in the REST api responses
- I have a website issue I am trying to resolve