Integrate WordPress

  • Updated

Connecting WordPress to the Optimizely Content Marketing Platform (CMP) lets you publish your content directly to your site and generate article previews. When combined with the CMP analytics plug-in, the CMP can surface content-centric analytics for the articles published from the CMP to your site. When you add the site, you can edit your SEO fields directly from the CMP — making it simple to choose a category or an author for each article. The integration currently supports only WordPress standard post types, categories, and tags.


If you cannot confirm these prerequisites, contact your WordPress administrator before you attempt to connect.

Failure to connect with your WordPress site can occur because of one of the prerequisites below. If you are having issues connecting and have discussed the above with your WordPress Administrator, contact the Support team or your CMP representative.

  • WordPress Plug-in – Certain features of the WordPress integration require you to install the CMP plug-in to ensure that users can preview pages before publishing to websites. Install the WordPress Plug-in here.
  • User Account – Although the integration will authenticate with any WordPress user account, your WordPress administrator should create a dedicated account for the integration to run. This user account will need Administrator permissions. Integration and publishing may fail without the correct permission level.
  • XML-RPC – The integration requires WordPress XML-RPC to be accessible and authenticated. Ensure this is accessible before connecting the integration, and your WordPress administrator confirms you can use it. Your IT team may also need to place the CMP publishing IP address on the allow list and ensure you can use it through your network configuration, caching, and so on. If so, ask your CMP representative for the IP address. You may also use the CMP User Agent of Welcome NodeJS XML-RPC Client as an extra security measure.
  • WordPress Authentication URL – The URL of your website, the login page a user accesses to log in, and the URL for integration can be personalized within your own WordPress setup, meaning they are not always the same. Confirm the URL for the integration to authenticate with xml-rpc with your WordPress administrator.
  • htaccess credentials (optional) – If your public WordPress site is password-protected with .htaccess, you must supply additional login credentials for the integration. In most cases this level of protection is only for internal or in-testing sites but if in doubt you should speak to your WordPress administrator.
  • Post Types & Taxonomy – CMP is configured to communicate with WordPress standard post types and taxonomies only. If you are using custom post types or taxonomies you will need to configure WordPress to accept standard types and convert where necessary.

Connect WordPress to the CMP

  1. Go to your avatar > Integrations > Website, CMS & Feeds.
  2. Select Add > WordPress.


  3. Fill out the form with the necessary information, including the title of your website and public URL.


  4. Select the website type and add the credentials in the username and password section to complete the process. To minimize the risk of unauthorized access, WordPress stores credentials securely in the database in encrypted form, and only the microservice that communicates with WordPress has access to the decryption key.
  5. You should enable the JavaScript Snippet option because it eradicates potential risks that impact the snippet, something that cannot be guaranteed if the JavaScript gets added manually through WordPress.


The website becomes available in a task on the Publishing tab; select the Add Channel drop-down and then select a website.

Install the CMP WordPress plug-in

Installing the CMP plug-in lets you display content analytics reporting. 

Installation is similar to any other WordPress plug-in installation. You can upload the plug-in to your plug-in directory (generally wp-content/plug-ins) or install it through WordPress' built-in web-based installer. The plug-in does not have any visible interface like an option panel or such. If you have issues installing or using the plug-in, contact

After you integrate the CMP with your WordPress site (under CMS Accounts) and you receive licensed content from CMP, update PHP files (which should be done by a web developer).

Field mappings (author and custom data)

By default, every article that the CMP posts to WordPress includes the following data in the Custom Fields section of the post entry. If the Custom Fields section does not show at the bottom of a post, you may need to enable it by going to Screen Options in the top right-hand corner of the page and clicking the checkbox labeled Custom Fields.

When visible, you will see a section similar to the setup depicted below:


  • nc-author – The author, sent from CMP. If you publish licensed content or have authors that do not exist in WordPress, edit your theme files to display the provided author instead of the default WordPress user.
  • nc-image-link – The link to the featured image of the article.
  • nc-link – The link to the article on the publisher's site serves as a canonical link for licensed content and should be displayed when such content is in use.
    If the publisher does not provide this link, you will see a GUID in this field. Escalate this to support immediately by submitting a ticket to
  • nc-source – The name of the publication. Put this value in the byline next to the author attribution.

A properly set up theme will look like the following:


Additional custom fields

In addition to the default fields above, you can pass data to WordPress using Custom Fields and Labels in the CMP. These can include passing additional images or videos or providing values for plug-ins that you are using. If you send labels to WordPress, these display with a prefix of label_{label name}.

Code Samples

The following code samples implement changes to your theme. Test code in a staging environment before adding it to your site. You may need to adjust the code samples based on your theme.

Codes for surfacing author and publisher information

Drop this into functions.php to generate an "author, source" string.
The function generate_license_info produces a formatted string with
author and source name for use in the theme file that display the post.

function generate_license_info() {
$license = '';
$nc_author = get_post_meta(get_the_id(), 'nc-author', 1); // Pull in the author custom-field
$nc_source = get_post_meta(get_the_id(), 'nc-source', 1); // Pull in the source custom-field
``` // Check if both the nc-author & nc-source field aren't empty,
// then assign it to $license string

if ( $nc_author != '' )
$license = $nc_author;

if ( $nc_source != '' )
$license = $nc_source; // Join the author name & source name together,
// separated by a comma for a complete byline.

if ( $nc_author != '' && $nc_source != '' )
$license = $nc_author . ' | ' . $nc_source;

return $license;

Codes for displaying author and publisher information in the theme

To show the correct author and publisher information, edit the theme file for single posts. You should initially create a WordPress user named CMPuser when connecting your site to the CMP. When publishing licensed content, choose the CMPuser from the list of authors in the article task as depicted below.

For use in theme file where post is displayed.
You should set up a WordPress user called 'CMPuser' when connecting to the CMP initially.
When publishing licensed content, choose the 'CMPuser' user

if ('CMPuser' == get_the_author_meta('user_login'))

else {

Replace the above line of code with the theme's default function
to display author information (usually 'the_author()' in standard WordPress setups)

Adding a canonical link

Add the following code to your theme's header.php file to display canonical links for licensed content correctly. If you are using the Yoast SEO plug-in, you should disable the canonical link on single post pages. You can add the second code snippet to your functions.php file.

Canonical in header

$canonical_url = get_post_meta( $post->ID, 'nc-link', true);

if (is_single() && !empty($canonical_url)) {
<link rel="canonical" href="<?php echo $canonical_url ?>"/>

else {
<link rel="canonical" href="<?php the_permalink(); ?>"

Disabling Yoast SEO on post pages (only applies if Yoast is in use)

function wpseo_canonical_exclude($canonical) {
global $post;
if (is_single()) {
$canonical = false;

return $canonical;

Questions and answers

How to link a WordPress site with CMP by authenticating with credentials

CMP users can link their WordPress blogs by authenticating their site with credentials inside the CMP. You must provide their username, password, and domain path where their WordPress xmlrpc.php file lives. If your blog uses HTTP basic auth with .htaccess or other methods, you can also provide your HTTP auth information. All credentials are AES-256 encrypted.


How does CMP authenticate with XMLRPC?

CMP makes XML-RPC calls following the WordPress API spec to authenticate an account. To authenticate and retrieve blog information, CMP initially requests to get any blogs associated with the provided credentials and domain with wp.getUsersBlogs. After authenticating an account, you can optionally default posts from the CMP to a specific author or draft post type. Depending on how you configure a self-host install, making XML-RPC calls may require placing CMP IPs on the allow list. These IPs are provided upon request.

How are tags and categories set up inside CMP?

To let you set tags, categories, and authors from CMP, CMP makes calls to retrieve this data using the API endpoints specified in the WordPress spec for retrieving taxonomies and authors.

How does draft post work?

When publishing in the CMP, you can sync posts by draft before publishing. Syncing creates a post with a post ID, which updates on future post synchs, and you can convert it to a live post at publishing time.