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?
- add action only on post publish – not update
- Hook that get’s triggered when the author of a post is changed
- 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?
- 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
- 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?
- Paragraphs removed when using get_post_custom()?
- Get the post_id of a new post
- First hook to use current page post id
- Content editor creating blank paragraphs in spaces and creating   in the_excerpt
- How to filter content post only on save
- Does an action fire when adding a tag via the “Tags” meta box?
- the_posts filter been called multiple time
- Are posts updated or built from revisions + autosaves?
- How to run a function when post is edited or updated using publish post action?
- Add scripts on custom post add/edit pages Not Working
- Create cron job without a plugin?
- WordPress’ visual editor messing up my (nested) lists (and other things as well)
- How to generate numbers indistinguishable for the IDs of the posts
- Action hook for new pending posts?
- How to retrieve the postID in a “image_send_to_editor” hook function?
- Register post status, exclude from searches
- Ajax Dynamic Archives not showing correct results
- Which WordPress hook fires after post content loaded?
- What is the filter or hook to add admin controls to posts on the front end?
- use wpml_post_language_details function other plugin based on $post->ID [closed]
- Hide a specific category in admin All Posts page (WordPress)
- Updating post data on save (save_post vs wp_insert_post_data)
- Is Hfeed class for all pages needed
- Set static page/post from another blog on same network
- Hooking into the post editing screen for an existing page only
- Anyone know why wordpress converts some html entities to their numeric equivalents?
- Trying to alter the post_content through the_post
- How to check if single.php has already called the_post_thumbnail function
- Adding bootstrap classes to video shortcodes
- preg_replace not removed “class”
- Best Way to Add UnEditable HTML to Posts
- Prevent posts with certain post_meta to be edited
- Benefits to using semantic HTML in post content? [closed]
- How to check in functions.php if there is data in a WP_Query?
- 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
- 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
- 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
- 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?
- 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
- 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?
- 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
- Which hooks are essential for post templates?
- save_post not working
- Action while post is being published
- 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
- Posts Page in WordPress loading bare HTML of my homepage
- Comment count next to post title?