Last active
April 4, 2020 21:25
-
-
Save Shelob9/7882861 to your computer and use it in GitHub Desktop.
Example code, to be added to a Pods Page Precode field, to output meta tags and Open Graph tags for Pods Advanced Content Type SEO. SEE: http://pods.io/tutorials/seo-advanced-content-types/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ). ' | '; | |
/*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]; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment