0

I have a Wordpress site that grew huge over the years. I need to add trademark ( ™ ) to specific phrase site wide.

Doing it manually one by one would be too time consuming and unreliable. I was thinking about some database query to edit tables containing post and page content.

Lets say I'd like to add trademark to phrase "this example". I'll need to find table that stores posts and transform via query phrases that do not have ™ added. So:

Lorem this example ipsum dolor sit amet, this example™ consectetur adipiscing elit.

Becomes:

Lorem this example™ ipsum dolor sit amet, this example™ consectetur adipiscing elit.

Note possibility of some phrases might already have trademark so I don't want to add it twice.

yivi
  • 42,438
  • 18
  • 116
  • 138
Greg Viv
  • 817
  • 1
  • 8
  • 22
  • Create an array of phrases, loop through the database for the phrase `WHERE post LIKE '%phrase%' AND post NOT LIKE '%™%'`, then all you gotta do is edit the database return appropriately and update your table. Alternatively, you could leave your database the same and just add the TM on the page itself where the post is loaded – GrumpyCrouton Aug 31 '17 at 15:13
  • 2
    Possible duplicate of [How can I use mySQL replace() to replace strings in multiple records?](https://stackoverflow.com/questions/4271186/how-can-i-use-mysql-replace-to-replace-strings-in-multiple-records) – yivi Aug 31 '17 at 15:21
  • You can use the replace, as in the linked duplicate. If you don't know which table you need to the replace in, is `wp_posts`. – yivi Aug 31 '17 at 15:22

1 Answers1

1

Do this in easy 3 steps.

Step 1:

Dump you post, page tables and any custom table that contain words that you like to replace

mysqldump -u yourUsername -p Db_name wp-posts > wordpress-post.sql

Step 2:

Replace all the posts in post table with the words that you like using;

find . -name "*.sql" -exec sed -i "s/example/example™/g" {} \;

And to restore it back and see the changes

mysql -u yourUsername -p Db_name < wordpress-post.sql

Step 3 :

Some of your page contents are static not pulled directly from the database, so we need to replace them as well using this command:

cd to you webroot (assuming /var/www/yourdomain.com/public_html/ ), then:

find . -type -f -exec sed -i "s/example/example&trade;/g" {} \; 

This search all files and replace example with example™

Hope it helps.

Community
  • 1
  • 1
Prince Adeyemi
  • 724
  • 6
  • 12