WordPress Remove Extra Line Breaks
Frequently, imported posts or posts created by auto-blogging plugins will create unnecessary tabs, newlines, and line breaks. This has a negative impact on readability and aesthetics of your site. If you cannot address the problem at its source, there is a relatively simple way of fixing the issue retroactively.
Below is a quick script that will scan all your posts matching the predefined slug and replace all tabs, newlines, and line breaks with spaces. In most cases, the end result would be smoother-flowing text. Having said that, you should back up your database before making any changes.
The script matches the slug with wildcards (LIKE “%${slug}%”). This works well if you want to make changes to posts in multiple categories that share a similar name. Alternatively, you can replace this with explicit matching.
#!/bin/bash # ---------------------------- # igor@krazyworks.com # 2013-12-02 # ---------------------------- configure() { db_name="database_name" db_user="dbusername" db_pass="dbuserpass" slug="slug_keyword" MYSQL="/usr/bin/mysql --batch --skip-column-names --max_allowed_packet=100M -u${db_user} -p${db_pass} ${db_name} -e" } replace() { ${MYSQL} "SELECT ID FROM ${db_name}.wp_posts p LEFT OUTER JOIN ${db_name}.wp_term_relationships r ON r.object_id = p.ID LEFT OUTER JOIN ${db_name}.wp_term_taxonomy x ON x.term_taxonomy_id = r.term_taxonomy_id LEFT OUTER JOIN ${db_name}.wp_terms t ON t.term_id = x.term_id WHERE p.post_status = 'publish' AND p.post_type = 'post' AND t.slug LIKE '%${slug}%' ;" | sort -n | while read post_id do ${MYSQL} "update ${db_name}.wp_posts SET post_content = REPLACE(REPLACE(REPLACE(post_content, 't', ' '), 'r', ' '), 'n', ' ') WHERE ID = ${post_id};" done } # RUNTIME configure replace

