WordPress Plugin: Decoupled set up
Integrating Parse.ly with a headless WordPress setup? The WordPress-Parse.ly plugin is available to meet your decoupled needs. We will discuss decoupled options, what we will provide, and what you’re responsible for. First, let’s review the basic definition of a decoupled set up. And then we will get into the details of how to use our plugin to complete your integration.
A decoupled or headless setup refers to an architecture where the front-end (what users see) is separated from the back-end (where site owners store and manage content). In our context of WordPress, a headless setup means using WordPress as a content management system (CMS) but delivering and presenting the content through different means, like a separate front-end application (like Next.js or Gatsby). This approach offers flexibility and customization for the website’s user interface and user experience.
With Parse.ly, you can either work with REST API or GraphQL. In either case, you’re responsible for:
- Loading the tracking script on your front-end.
- Rendering the metadata that Parse.ly will crawl. You can use the wp-parsely plugin for this.
Let’s look at each option in more detail.
REST API
The plugin automatically adds a parsely
field to REST API endpoints corresponding to the Tracked Post Types and Tracked Page Types selected in the plugin settings. By default, this would be the /wp-json/wp/v2/pages
and /wp-json/wp/v2/posts
endpoints along with the corresponding single resource endpoints. You may adjust the choice of object types by using the wp_parsely_rest_object_types
filter:
// Disable REST API output from pages, but enable for term archives.
add_filter(
'wp_parsely_rest_object_types',
function( $object_types ) {
$object_types = array_diff( $object_types, array( 'page' ) );
$object_types[] = 'term';
return $object_types;
}
);
The parsely
field contains the following fields:
version
, a string that identifies the REST API output’s version. We’ll update this string whenever making changes to the output. This allows consuming applications to check the version to ensure compatibility or identify updates.meta
, an array of metadata for the specific post, page, or other custom post type.rendered
, the rendered HTML of the metadata for the post, page, or other custom post type. This will be a JSON-LD<script>
tag, or a set of<meta>
tags, depending on the format you’ve selected in the plugin settings. The decoupled code can consume and use this directly, instead of building the values from themeta
field values.
The rendered
field is a convenience field containing the HTML-formatted metadata which you may printed to a decoupled page as is. You can disable it by returning false
from the wp_parsely_enable_rest_rendered_support
filter.
// Disable rendered field output from the REST API output.
add_filter( 'wp_parsely_enable_rest_rendered_support', '__return_false' );
The REST API integration can be disabled by returning false
from the wp_parsely_enable_rest_api_support
filter.
// Disable all REST API output from the Parse.ly plugin.
add_filter( 'wp_parsely_enable_rest_api_support', '__return_false' );
GraphQL
If you’ve installed the WPGraphQL plugin, the wp-parsely plugin will register a parsely
field on the ContentNode
interface, which makes it available on most post types by default.
Here is an example GraphQL query for a post. Documentation for each field is provided via the GraphQL schema.
query PostWithMetadata {
post(
id: 1
idType: DATABASE_ID
) {
id
parsely {
isTracked
jsonLd
rawJsonLd:jsonLd(removeWrappingTag: true)
repeatedMetas
scriptUrl
version
}
title
}
}
You may disable the GraphQL integration by returning false
from the wp_parsely_enable_graphql_support
filter.
// Disable all GraphQL output from the Parse.ly plugin.
add_filter( 'wp_parsely_enable_graphql_support', '__return_false' );
Additional Resources
If you would like additional help with your decoupled set up, please contact Support.
- Parse.ly – WordPress Plugin installation instructions
- Parse.ly – WordPress Plugin FAQ & customization
- Parse.ly tracking code options
- Metadata requirements
- Testing instructions
Last updated: August 15, 2024