sandrasimon of Cubera
12/6/2016 - 1:29 PM

No Description

No Description

Url cleaner for Wordpress

Wordpress always use an absolute url, so when you import an image or file the src tag is populate like so: src="http://localhost/..".

This approch is fine if you work only in local or in production but in the real life get some issues.

For a small project is simple check each page and correct the src tag manually. But when you have a project with 20/30 pages or more this come a nightmare!

For this reason I wrote this simple customizable query to replace all src tags on each pages.

How to use

  • Open your database via phpMyAdmin
  • Make a backup of the entire database
  • Open the SQL tab
  • Copy/paste the query into the textbox area
  • [OPTIONAL] if necessary change @search and/or @replace values

By default this query replace http://localhost/ with /.

# Provide a string being searched for
SET @search = 'http://localhost/';

# Provide a string that replaces found search values
SET @replace = '/';


UPDATE `wp_posts` SET `post_content` = REPLACE(`post_content`, @search, @replace) WHERE `post_type` LIKE 'page' AND `post_content` REGEXP @replace;