SEO For Pods Advanced Content Types

Pods Advanced Content Types (ACT) do not work automatically with Yoast’s WordPress SEO or any other SEO plugin since they are not WordPress content types. Custom Post Types on the other hand do not share these issues. This tutorial is only applicable to ACTs and Pods Pages. I will be addressing three separate SEO concerns:

  1. XML Site Maps
  2. Meta fields, such as title and description
  3. Open graph fields.

Be sure to also check out my screencast on SEO for Advanced Content Types.

XML Site Maps

XML site maps is the easiest issue to solve. There is a plugin called Pods SEO that will allow Yoast’s WordPress SEO plugin to include ACTs in XML site maps. The plugin also enables you to choose which of your ACTs to include in the site map. You must  have a detail page created for each ACT. For more information on how to do this, see my tutorial or screencast on creating Pods Pages.

Creating Meta Tags and Open Graph Tags In Pods Pages

You can handle meta/ open graph in the Pods Pages precode. In this section I will be explaining how to manually create these fields manually so you understand how they work. These techniques are fine for Pods list pages, but for detail pages they are inadequate for the job. In the next section we will build on what we are learning in this section to allow you to set the values of the meta tags and open graph tags from custom fields or dynamically.

The two most important meta tags to include for SEO purposes are meta title and meta description. You can output these fields by setting their values in the precode section of the Pods Page. To create the meta tag for meta title, simply add `$pods->meta[  ‘title’  ] = ‘Title You Want’;  to your Pods Page precode. To output any meta tag, you use $pods->meta[ 'meta_tag_name' ] = 'meta tag content';

For example, $pods->meta[ 'description' ] = 'This page is about apples.'; will create this meta tag: <meta name="description" content="This page is about apples." /> in the header of the page. Similarly, you can output an open graph tag like this: $pods->meta_properties[ 'og:tag_name' ] = 'tag content'; which becomes  <meta property="og:tag_name" content="tag content" />.

Dynamically Generated Meta Tags

In order to be able to set these values separately for each post in the ACT, you can create fields and use their values to output the meta content. So for example, you could create a field called meta_description, and then in the precode do: $pods->meta[ 'description' ] = $pods->field( 'meta_description' ); $pods->meta_properties[ 'og:description' ] = $pods->field( 'meta_description' ); You can also use existing fields to populate the meta tags. For example, if you have a create a field to act like the post thumbnail called ‘page_thumbnail’ in regular WordPress posts and wanted to use it as the open graph image, you could. The precode to do this would be: $pods->meta_properties[ 'og:image' ] = wp_get_attachment_image( $pods->field( 'page_thumbnail' ), 'full' ); This code will use the original image size, opposed to the default size, which is thumbnail. You can optionally specify the image dimensions in an array, in the form of array( width, height );.

Please keep in mind that before you can do any of this you must put a Pods object in $pods in the precode. I describe how to create a Pods object with Pods pages in the Pods Pages tutorial and you can use the same process in the precode.

Example

The example code below shows you how to output meta title and meta descriptions in the head of your document as well as open graph tags for image and description. It also shows how to output the proper link for author’s Google+ profile. It’s not WordPress SEO by Yoast, but it’s a start.

You will need to add two text fields to your ACT. Call one ‘meta’ title and give it a maximum length of 70 characters. Call the other one ‘meta_desc’ and give it a max length of 154 characters. Those lengths are what Yoast uses for those fields in their plugin.

In this example I’m using an image field called ‘picture’ that functions like a post thumbnail for the open graph image tag og:image. Be sure to create a comparable field. Even if you don’t use the image anywhere on your site, it’s important to be able to control what image shows up when the page is shared on Facebook.

The other important thing to do is to extend Users and add a Google+ field to it. You can learn how to do this in the first two steps of my tutorial on creating a users directory with Pods. Once that new field exists, you can create a relationship field in your ACT to it called ‘page_author’. This allows you to get the ID of the page’s author and then get the value of that field with get_the_author_meta( 'google_plus', $author['ID'] );. For some people the link to the Google+ profile may be better set statically, it depends on your needs.

Here is the complete precode, all together:


<?php
/**Setup Pods Object**/
//get current url
$slug = pods_v_sanitized( 'last', 'url' );
//get pod name
$pod_name = pods_v_sanitized( 0, 'url');
//get pods object for current item
$pods = pods( $pod_name, $slug );
//verify $pods is an object and of the right Pod
if ( is_object( $pods ) && $pod_name = $pods->pod ) {
/*title field*/
//assumes field name of meta_title exists
$pods->meta[ 'title' ] = __( $pods->field( 'meta_title' ), 'translation-domain' ). '&nbsp;|&nbsp;';
/*meta description*/
//presumes field name of 'meta_desc' exists
$pods->meta[ 'description' ] = __($pods->field( 'meta_desc' ), 'translation-domain' );
$pods->meta_properties[ 'og:description' ] = __($pods->field( 'meta_desc', 'translation-domain' ));
/**Google+ Profile Link**/
//Presumes users is extended with a field called 'google_plus'
//Also presumes ACT has a field called page_author, related to Users
$author = $pods->field('page_author');
echo '<link rel="author" href="'.esc_url( get_the_author_meta( 'google_plus', $author['ID'] ) ).' "/>';
/*OpenGrpah Image*/
//presumes image field called 'picture' exists
//Put the url/ height/ width of imagine into $img
$img = wp_get_attachment_image_src( $pods->field( 'picture.ID' ), 'full' );
//output values from the variables
$pods->meta_properties[ 'og:image' ] = $img[0];
$pods->meta_properties[ 'og:image:width' ] = $img[1];
$pods->meta_properties[ 'og:image:height' ] = $img[2];
}
?>


<?php
//setup pods object
$params = array( 'limit' => 1 );
$pods = pods( 'spaceship', $params );
//verify $pods is an object and of the right Pod
if ( is_object( $pods ) && 'spaceship' = $pods->pod ) {
//meta title
$pods->meta['title'] = __( 'Your Meta Title Here', 'text-domain' );
//meta descrioption
$pods->meta['description'] = __( 'Your Meta Description Here', 'text-domain' );
}