Updating your WordPress Theme for Licensed Content

Once you've connected the CMP with your WordPress site (under CMS Accounts), there's a few quick updates you'll need to make to your theme.  

For this part of the integration, you will be required to update PHP files so it's recommended that a web developer handles this part!

Finding the Author and Source of an Article

Every article that the CMP posts to WordPress will include 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 them by navigating to Screen Options section in the top right-hand corner of the page, and clicking the checkbox labelled 'Custom Fields'.

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

nc-author - this is the author from the publisher. If you are publishing licensed content, you will need to edit your theme files in order to display the provided author instead of the default WordPress user.

nc-image-link - this is the link to the featured image of the article.

nc-link - this is the link to the article on the publisher's site. This will also serve as a canonical link for licensed content, and should be displayed when such content is in use.

*Note: if the publisher does not provide this link you will see a GUID in this field, please escalate this to support immediately by submitting a ticket here.

nc-source - this is the name of the publication, you should 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, additional data can be passed to WordPress using CMP custom fields. The use of these fields can include passing additional images or videos, or providing values for plugins that you are using.  Please reach out to your Customer Success team if you are interested in setting these up!

Code Samples:

Code samples for how to implement these changes on your theme are included below.  All code should be tested in a staging environment prior to adding to your site.  The code samples below may need to be adjusted based on your theme.

1. Surfacing Author & 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;

2. Displaying Author & Publisher Info In Theme:

In order to show the correct author and publisher information, you will need to edit the specific theme file for single posts. It is generally advised to create a WordPress user named newscred when connecting your site to the CMP initially. When publishing licensed content choose the newscred user from the list of authors in the article task as depicted below.

* For use in theme file where post is displayed
* It is advised to setup a WordPress user called 'newscred' when connecting to the CMP initially
* When publishing licensed content, choose the 'newscred' user 

 if ( 'newscred' == 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

In order to display canonical links correctly for licensed content, you will need to add the following code to your theme's header.php file. Note, if you are using Yoast SEO plugin, it is recommended that you disable the canonical link on single post pages. You can do this by adding the second snippet of code 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;
Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request


Powered by Zendesk