# WordPress

> Connect a WordPress site with an application password. RootSmith publishes each page as a WordPress post and updates the same post when you publish again.

Source: https://docs.rootsmith.io/publishing/wordpress.md

RootSmith publishes each approved page as a post on your WordPress site
through the WordPress REST API. You don't need a plugin.

## Requirements

- WordPress 5.6 or later on HTTPS, on this site's domain.
- Pretty permalinks. In WordPress, go to **Settings** → **Permalinks** and
  choose any option except **Plain**.
- A WordPress user who can publish posts, such as an Author, Editor, or
  Administrator.

## 1. Create an application password

1. In WordPress, go to **Users** → **Profile**.
2. Under **Application Passwords**, enter `RootSmith` and select
   **Add New Application Password**.
3. Copy the password. WordPress shows it only once.

## 2. Connect it in RootSmith

In **Publishing**, under **How is your site built?**, choose **WordPress**.
Enter the username and the application password, then select **Save and
connect**. If WordPress runs at a different address on your domain, such as
`https://example.com/blog`, enter it as the **WordPress address**.

RootSmith signs in first and saves the password only when WordPress accepts
it and the user can publish posts. The password is encrypted, and RootSmith
never shows it again. To change it, paste a new one. If you change the
WordPress address, paste the password again. RootSmith sends a saved password
only to the address it was saved for.

An agent sets this with `update_publishing_settings`, using
`fallbackDelivery: "wordpress"`, `wordpressUser`, and the application
password in `wordpressPassword`.

## What happens when you publish

1. RootSmith creates a published post. The post title, excerpt, and content
   come from the page. The slug is the last part of the page path, so
   `/blog/ai-search-guide` becomes `ai-search-guide`.
2. Your permalink settings decide the post's address. RootSmith saves the
   address that WordPress returns.
3. RootSmith checks that address for the version marker in the post content
   and marks the page published when it finds it. If the first check fails,
   it checks again every five minutes for 24 hours.

When you publish a page again, RootSmith updates the same post. If a post
that RootSmith didn't create already uses the slug, the publication fails and
your post stays as it is.

## Limits

- Images load only from your site's domain.
- RootSmith doesn't set categories, tags, featured images, or SEO plugin
  fields. Set them in WordPress.
- When you merge pages, add the redirects in WordPress, then confirm them in
  RootSmith. Unpublish or delete the old posts yourself.
- When you change the site's domain, connect WordPress again in
  **Publishing**.

## Troubleshooting

- **We couldn't sign in to WordPress**: check the username and the
  application password. Some security plugins and hosts block application
  passwords or the REST API. Allow `/wp-json/wp/v2/` for signed-in requests.
- **The page stays unconfirmed**: a caching plugin can serve old HTML for a
  while. Clear the cache, or confirm the page by hand in RootSmith.
