You first should find out where the divs are coming from, since that’s not normal behavior. Could be from a plugin or – as Damien said – copy-pasting a text from Word.
To remove the divs you can do a simple
str_replace(array('<div>', '</div>'), '', $content)
either before storing the text in the database (by hooking on save_post
), or before displaying it on the site (by adding a filter on the_content
).
EDIT: I was wrong, you don’t hook on save_post
, but instead you filter on wp_insert_post_data
. This function below should work:
function remove_divs($data) {
$filteredContent = str_replace(array('<div>', '</div>'), '', $data['post_content']);
$data['post_content'] = $filteredContent;
return $data;
}
add_filter('wp_insert_post_data', 'remove_divs', 99);
Put this in your functions.php
Related Posts:
- Action hook ‘wp’ firing twice… why?
- Count singular post views automatically
- Custom function for “Submit for Review” hook
- How can I hook into creating a new post and execute wp_die(), before the post is inserted into the database?
- How can i do something after head like adding a hook for after head but before post
- Adding buttons to Add New Post and Add New Page
- How to access $post from a callback function
- Copy post to separate database with “add_action(….)”
- Call Web Services on post first publish
- What does WordPress do if I save a post without content/title? [duplicate]
- Automatically set post_parent value
- Is there a way to know when a page has been updated and do some action only once?
- Is update_post_meta used when save_post action hook is invoked?
- Count singular post views automatically
- Grab meta data before post is saved
- Modify upload directory to use post category slug in file path on multisite installation
- Is there a action hook for the “Empty Trash” button?
- Function to execute when a post is moved to trash .
- add action only on post publish – not update
- Hook that get’s triggered when the author of a post is changed
- How to validate XML-RPC post creation and cancel when needed?
- The hook for the AJAX Add to Cart button?
- Get old values for post before saving new ones
- Execute function when post is published
- Create posts on user registration
- how to limit edit_form_after_title hook to page and post edit only?
- How to publish a post with empty title and empty content?
- flush_rewrite_rules on save_post Does Not Work on First Post Save
- How to add a “publish” link to the quick actions
- strip only specific tags (like ), but keep other tags (like )
- In what sequence are the hooks fired when a post is “published”?
- Removing the title attribute from links in the post content
- HTML code in Custom field
- Better post meta efficiency?
- How to wrap every image in a post with a div?
- How to change post status from publish to draft using hook in wordpress?
- Filter post before *editing*
- WordPress Delete hook with wp_delete_post function?
- How to dynamically parse and transform post/page content before displaying it?
- Adding bootstrap classes to video shortcodes
- preg_replace not removed “class”
- Best Way to Add UnEditable HTML to Posts
- why the same code got different results when using query_posts in functions.php and index.php
- Modify posts listing at back end
- Prevent posts with certain post_meta to be edited
- How to catch wordpress post ID when it’s published
- Benefits to using semantic HTML in post content? [closed]
- How to check in functions.php if there is data in a WP_Query?
- Hook for changing excerpt content when excerpt not set
- Creating a WordPress Post via REST API – HTML or Markdown?
- Is it possible to add a shortcode below post title?
- Update post meta within save_post action
- HTML Form Submit to table in same page
- Exists filter or action that change Add New Post link?
- What hook can I use to modify custom post data before it is displayed on the page?
- Locally change the font family [closed]
- Right align a youtube video
- Actions to use when flushing cache (when posts are added / deleted / modified)
- WordPress Post Block Element not properly parsed with the_content filter
- Posting to WP via URL
- Restricting displayed posts to posts from only select authors
- How can I change the date format of the revision list?
- Run a function when a custom post is update?
- WordPress 5: prevent link from displaying page title instead of URL
- the wp_post_update isn’t working all the time
- Hook when post is set from published to draft?
- Send email to user when I publish a new post
- WordPress Recent Post with the badge “New” on the side of the title post
- Get Category in save_post Hook
- Remove HTML tags from all posts
- How to prevent post update using transition_post_status
- Checking if a post contains an html tag
- How to generate an HTML link automatically from URL in a users’ post
- How can i take all ids from untrash_post action?
- Show all posts from the tags without having to set all of them
- Can’t get post_updated hook to work
- Is it possible to completely replace a post with an action/filter?
- How to get the postID inside ‘content_save_pre’? Other hook?
- Adding div to WordPress page content
- wp query custom orderby not custom field
- Hook To Get All Posts Deleted
- How to remove related post from home page
- WordPress HTML Helper
- Posts don’t appear on Template Page
- Checking if some condition is matched before inserting post into database
- fire action when post is being edited as well as saved?
- How to get all the terms of a post
- Which hooks are essential for post templates?
- save_post not working
- Action while post is being published
- CSS – Change height of Storefront / WooCommerce product categories, but not products
- Wrap posts from a category in HTML
- Do anything on post_status change [duplicate]
- How can I add a custom caclulation form in post?
- How to automatically convert a form with HTML link into post
- Admin notice on wp_insert_post
- Posts Page in WordPress loading bare HTML of my homepage
- WordPress as microblog: show excerpt instead of “(no title)” in posts view
- Comment count next to post title?
- How to add publish button in menu All Posts (Wp-Admin)