I’m writing a simple script & plugin to move a “Staging” WordPress site over to a production site. The approach is simple: mysql dump, check everything into source control, adjust database name, restore in production.
The one problem I’ve run across is that I can’t figure out how to toggle the Search Engine Visibility setting under Settings > Reading. I’d like to have staging be ignored by search engines, but not overwrite that setting in production (after the restore).
Any ideas on how to do this? Quick and dirty (using sed / find & replace on the sql dump file, etc) is fine by me.
Thanks
WordPress Search Engine Visibility status stored on table option with option name
'blog_public'
, with value'1'
if site visible by search engine, and'0'
if site not visible by search engine,,So,maybe you can toggle it using update_option from wordpress function,
or just direct replace it on database
I wouldn’t use the WordPress site visibility setting for this at all.
I’d suggest using some/all of these:
(But you have to trust search engines to respect it, as you do the WordPress setting)
Password protect the staging site using something like
.htaccess
and.htpasswd
(assuming you use an Apache server).Use
.htaccess
to limit access to your staging site from any but a small set of IP addresses.That way you make the changes once, and you don’t need to do a dangerous sed operation on your database every time you do a sync to live.
TL;DR
Straightforward solution
Long version
I am building a similar project as you. With the above script, you can generate a new production database where you can set the value of WordPress’ Search Engine Visibility.
Input
You just need a dump file generated by
mysqldump
or a backup file fromphpMyAdmin
Output
After running the script you would be able to have a database that has been searched-and-replaced.