Dev Tip: How to Use Acquia Lift with WordPress

We share the steps and script to personalize CTAs in WordPress using Lift.
twittertwittertwittertwitter
MBlog_AcquiaLift.jpg

Yes. Yes, you can use Acquia Lift with WordPress.

Let me backup here, though. For those of you who may not know, Acquia Lift is “the only personalization tool optimized for Drupal.” Lift depends on Acquia’s Content Hub, “a cloud-based, centralized content distribution and syndication solution.”

Lift does take a bit of configuration. But our dev team at Manifest has recently scripted a way to use it with WordPress.

It’s easier than you might think. Here’s a real-world example of how we have done it.

We have five sites for one of our clients working as a Drupal 8 multisite installation, pushing specific content types and view modes to Acquia’s Content Hub, allowing the client to use the same content from site to site. We also push content to users based on their onsite behavior.

For its WordPress blog, the client had a very specific use case request. Could we promote content that lives on the client’s main dot-com site on its WordPress blog?

We wanted to serve up calls to action (CTAs) based on user page views of content tagged with specific related categories on that WordPress blog. Sounds a bit confusing, I know, but I’m going to walk you through how we created a more integrated brand experience aimed at keeping visitors in our client’s digital ecosystem.

How to Optimize Drupal for Integration with WordPress

There is no out-of-the box solution (yet) that pushes content from a WordPress site to Drupal’s Content Hub. There is a Content Hub application programming interface, but we’d be starting from scratch and writing a custom WordPress plug-in that would only be uploading four or five pieces of content a month (at least for this pilot program).

We wanted to begin serving up these CTAs quickly. And since we already had a Drupal multisite that pushes articles and videos to Content Hub, we thought, “Why not just use one of those?”

Our Proposed Workflow

1

 

So, that’s what we did. On our Drupal multisite, we created a view mode and Twig template for an existing content type that mimicked sidebar content on our client’s WordPress blog.

The existing content type is primarily used for CTAs on our Drupal multisite. It doesn’t show up in any views, it isn’t indexed, and it isn’t crawled by bots. That makes this a reasonable content type to use for content that isn’t intended to be accessed on the Drupal multisite.

This content gets pushed from the Drupal multisite to Content Hub using the markup in the template. Once it gets pulled from Content Hub to the WordPress blog, the markup will pick up the WordPress blog’s cascading style sheets for setting the content’s presentation.

The Acquia Content Hub Interface

2

 

Migrating Content from Acquia Content Hub to WordPress

But how do we actually pull the content from Content Hub into the WordPress blog?

Lift gets content to the page using slots that have their own filters and rules. Usually, you try to target a <div> tag on the page as your container and use the Classes and site IDs that are on that <div> tag. In this case, we needed five slots within the same <div> tag because there are five segments we need to show up.

We created the slots and segments using Lift’s Experience Builder. You can either target specific <div> tags or use the provided embed code. The embed code contains a “data-lift-slot” attribute that contains a site ID. Once we had five slots with separate IDs, what came next? [By the way: We realized we didn’t necessarily need five slots as you can add multiple rules (or segments) to a single slot.]

Acquia Lift’s Experience Builder User Interface

3

 

We made a custom widget to hold the five slot IDs. I’m a Drupal developer but I do have to say, WordPress can’t be beat for documentation and tutorials. Google it. Even a novice PHP programmer should be able to get a custom widget built with what you can find out there.

Lift Admin Form for Custom WordPress Widget

4

 

The widget display consists of <div> tags that have a variable for the slot IDs listed on the back end:

<div data-lift-slot=”[slot-id]”></div>

That worked, but there was still one small problem. The title, “Recommended for You,” showed up even if Lift wasn’t serving content and even if a user hadn’t met the criteria in the rule. For instance, a rule might be: “Viewed two or more articles tagged with ‘security’ in the last 30 days.”

Luckily, Lift has a solution. [Shoutout to our developer Dan Flanagan, who reminded me that he had written a Drupal module for this very thing.]

Lift supplies event notifications that allow you to “enable custom JavaScript to provide additional features.” In this case, we needed JavaScript to fire only after Lift content was on the page. So, we hid the widget <div> tag by default and added a class to the content coming from Lift:
 

5

 

Now, the div tag will only display if there’s content.

Customized Content CTAs on a WordPress Blog

6

 

There you have it — a somewhat painless solution for syndicating content across content management platforms.

Stay tuned: There will be a Part 2 when we begin pushing content from our WordPress blog to Acquia Content Hub.

About the Author