Custom Fields in Yoast SEO Page Titles

March 5, 2019

Yoast SEO and Advanced Custom Fields are probably two of the first plugins we add to any new website. Inevitably, we’re going to need to add some custom fields to custom post types and – because the agency we work at is a full-service agency – we incorporate SEO services into every site we work on.

Recently, we ran into a situation where we needed to add content from a custom field into the page title of a post type. Specifically, we wanted to add location information (city and state) in the page title for a post type that has locations for each post.

Okay, that’s a little hard to follow. Here’s what the titles looked like (the real names have been obscured because, well, NDAs and whatnot):

Full Day Guided Tour | Bob’s Tours

But what I really wanted is something like this:

Full Day Guided Tour | Orlando, FL | Bob’s Tours

Normally, we’d just set those things in Yoast on each page and move on with our lives, but this site happens to have hundreds of these tour pages – each generated by folks that have signed up for the site and posted their own tours. Hopefully you see the dilemma we have…

The Solution

Thankfully, Yoast SEO has some built in features that help us accomplish the task at hand! While it’s not immediately obvious from within the WordPress interface, the documentation gives us exactly what we need – a list of variables we can use to inject a custom field pattern into our post type page titles!

First things first, let’s get to where the site-wide page titles are set so we can add our custom field. In the WordPress admin, surf to the “Search Appearance” section under the SEO menu item.

Once there, make your way to the “Content Types” tab.

Scroll down to the content type that you want to modify. Find the section that mentions the “SEO title”. That’s what we’ll be modifying.

Feel free to do any quick cleanup first (I removed the “Page” variable since I don’t need it for this post type) and then you can add your custom field variable.

Quick side note: even though I’m using Advanced Custom Fields, this works with any custom field plugin or hand-rolled custom fields. Because of the way WordPress stores post meta data, any custom fields will work… I just happen to really like Advanced Custom Fields.

Okay, back to the page title. The pattern for custom fields in a Yoast SEO page title looks like this:


Start by adding two percent symbols (%) and then “cf_” (for custom field). You’ll then need to add your custom field’s unique machine name. You can find this in the settings for your field. Finish it off by adding two more percent symbols.

When you finish it off, Yoast SEO actually converts your code to a variable, putting it in the purple pill shape you see below:

There you go! Feel free to add as many as you need (within reason) to get some additional keywords in your page title!

Download the Plugins

Wanna chat about this article or any others? Feel free to DM me or mention me on Twitter @marcusdburnette to start a conversation!

Leave a Reply

Your email address will not be published. Required fields are marked *