Ok so, this solution is very particular to my case but maybe it can help point somebody else in the right direction in the future if they encounter a similar problem.
I have a custom function that adds a CSS class for lazy-loading images into all <img>
tags that are present in the_content().
In this function I am using the following code:
$document = new DOMDocument();
$document->loadHTML( utf8_decode( $content ) );
The DOCTYPE, html tags and body tags were appearing because of PHP’s loadHTML method.
Changing the above code to the following has solved this issue.
$document = new DOMDocument();
$document->loadHTML( utf8_decode( $content ), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
I found the details I needed to solve this problem here: https://stackoverflow.com/questions/4879946/how-to-savehtml-of-domdocument-without-html-wrapper
Related Posts:
- Error shown for Trying to get property ‘roles’ of non-object in WordPress After Content for User Roles
- How to echo a PHP Code After the Content
- How can I make my custom shortcode work in a Custom HTML Widget?
- Adding a post shortcode to a page template?
- How to trigger $_GET request within admin plugin page?
- How can I get WordPress to save comments in markdown format?
- WooCommerce: Building a page with user input which is used to query order status and external API and return a result
- How to insert HTML/JavaScript form into WordPress page? [closed]
- How to include this jQuery File in wordpress?
- How to Loop Through all Posts and Count Attachments using Get Media Attachments
- How can I exclude a dynamic URL to show a popup created using ‘WordPress Popup’ plugin
- Any idea how to get something like this to work? [closed]
- Is there a way to convert shortcodes to html content?
- File Uploader – Upload without adding to Media Library
- Wierd site output [closed]
- Add custom PHP and HTML to the_content()
- Code for unique user visit count on every page WordPress
- How to makes changes on the shop/category/tag pages but not on the product pages in woocommerce?
- How to translate to spanish wordpress hardcoded content/files?
- How to change a wordress plugin php code in my child’s functions.php file?
- make p tag collapsed after 3 rows
- Why is my form going to frontend on html form submission present on the php files inside my custom plugin?
- How To Toggle User_Meta in frontend in a form using PHP
- Get and Update Most Meta Value as an array in HTML form
- Can’t access 3rd party API, code works on local server but not on wordpress
- How to remove a css class for any wordpress page
- Why is every single HTML tag being stripped out of liveblog entries?
- Form tries to download a file on submit
- Adding link on title its in description but not in title see screenshots attached
- wordpress illegal string offset ‘parameter’ error
- Need help with wordpress audio preload
- Option value not getting updated until page refresh in WordPress
- Limit entry to a WordPress page
- How to create a “Most Popular” & “Latest” TAB in WordPress
- How to fix template and image buffering issues on website [closed]
- How to create different woocommerce single_product.php pages for each product? [closed]
- Customizing subject in comment notification e-mails
- WP showing “warning: call_user_func_array()”, What to do?
- How can I pass a variable to wp_ajax action?
- How can i change an image’s author?
- Plugin exceeds memory limit
- Pass a php string to a javascript variable
- Show price with Geo IP location
- How to generate video out of images via WordPress plugin
- Creating custom HTML pages
- How can I add hyperlink in WP_Error message?
- How to save inputed data in a textbox [EDITED] [duplicate]
- Frontent user submit and view content [closed]
- Output content to the_content before a plugin does
- WordPress Payment gateway add on form , how to add form into list or else how to submit form to next step for payment
- How to get the value of input hidden html from text editor to custom page template?
- Center and hide overflow of WP toolbar custom links
- How to get my plug-in, wrote in php, to refresh on its own every 5 minutes?
- Conditional tag doesn’t work in WordPress plugin
- PHP Fatal error: Call to a member function locale() on a non-object
- This WordPress plugin isn’t creating links correctly
- how to place a link on the first post only using a plugin
- Are there action hooks for comments?
- syntax error, unexpected ‘while’ (t_while) please help :)
- How to add a new column with text fields to WooCommerce Cart List?
- How to change WooCommece variation data programmtically [closed]
- How to include files relative to a file’s directory
- .php file for woocommerce edit category? [closed]
- Asynchronous request in wordpress
- Apply html elements in php statement
- Directorist – Dropdown doesn’t open
- Effeciently adding Checkboxes to TablePress table cells
- Get product categories and add them to a custom taxonomy
- How do I display PHP file contents on front end of WordPress?
- I want to add the below chatbot html code to index(main) file of WordPress sites how can I do that
- add_rewrite_rule to load different page, without changing URL in browser
- How can I translate something in my class constructor of my plugin in WordPress?
- Define global variable in theme file and call that variable in plugin file
- Adding discount functionality to the cart
- SimpleXML is not working with xml response from external api
- Using Shortcode Result In Custom HTML Block (Using Google Sheet JQuery Result As NumScroller data-max)
- Multiple image selection custom widget
- No result after wpdb->insert
- Edit the stylesheet of a child theme
- Cannot pass variable to page definition
- How do I change tab url
- Populate select option with JSON file
- Things that saved lose when logout
- How to speed up installing plugins and upgrading WordPress
- PHP and Jquery pass value from form. Update function on DataBase
- is ther a plugin that will hide/show content for a scheduled period of time? [closed]
- update_post_meta not working
- Pulling Advanced Custom Fields from other pages
- Plugin use of ajax/jquery depending dropdown
- Unable to show 4 products in a row
- WordPress portfolio pagination on home page
- Which action/filter can i use for a Member Plugin [closed]
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- Posts in Admin only display 1 Post instead of all Post in admin area
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- Creating a Table Row by Row
- Getting 504 Gateway Timeout Error on AWS Server! [closed]
- WordPress issue – data is not showing in wp-admin, but when searching through database, all the data is there
- WordPress Throwing Deprecated Errors on its own Files
- plugin doesn’t retrieve data from database