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
- Is there a action hook for the “Empty Trash” button?
- add action only on post publish – not update
- How to validate XML-RPC post creation and cancel when needed?
- 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 change post status from publish to draft using hook in wordpress?
- Filter post before *editing*
- get_post_custom stripping styling issue
- why does HTML Tag not working in Post and Page
- Get the post_id of a new post
- Content editor creating blank paragraphs in spaces and creating   in the_excerpt
- How to filter content post only on save
- How to place HTML below the title of the (custom) post overview
- Does an action fire when adding a tag via the “Tags” meta box?
- add_action not using ‘delete_post’ action with wp_delete_post
- the_posts filter been called multiple time
- Are posts updated or built from revisions + autosaves?
- Add scripts on custom post add/edit pages Not Working
- Add code just after Post content
- How to generate numbers indistinguishable for the IDs of the posts
- Articles are text-only in any “Category” instead of HTML
- 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
- How to modify post content?
- Which WordPress hook fires after post content loaded?
- use wpml_post_language_details function other plugin based on $post->ID [closed]
- Ajaxify This Code
- Pausing and Resuming WP_Query results
- Is Hfeed class for all pages needed
- Set static page/post from another blog on same network
- Anyone know why wordpress converts some html entities to their numeric equivalents?
- 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
- 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)
- Posting to WP via URL
- 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
- 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
- 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
- WordPress HTML Helper
- Checking if some condition is matched before inserting post into database
- 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