brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: wp rewrite structure sets the WordPress permalink format from the terminal

WordPress
~/tips/tip-wordpress-rewrite-structure-permalinks

wp rewrite structure '/%postname%/'

Changes the permalink structure, and optionally the category and tag base, in one command.

Settings > Permalinks has a form for this. In a setup script I want it as a line of code.

wp rewrite structure '/%postname%/'

The argument is the same pattern you’d type in the custom structure field: tags like %year%, %monthnum%, %category% and %postname%. The single quotes stop the shell from touching the percent signs. --category-base=topics and --tag-base=labels change the /category/ and /tag/ parts of archive URLs.

On Apache, add --hard so the rules in .htaccess get written too. Nginx ignores that file, it only needs the usual try_files line that sends everything to index.php.

To see what you have now:

wp option get permalink_structure

An empty answer means plain links like ?p=123.

Changing the structure on a site that is already live changes every post URL. Links from other sites, bookmarks and search results point to the old addresses. WordPress can guess its way to some of them, but I would not count on it. Test a few old links afterwards, and add redirects where they fail.

Further reading: wp rewrite structure, Using permalinks

More WordPress tips wp user application-password create anna backup-script --porcelain define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size All WordPress tips (85) All topics

Link