Created
November 14, 2017 17:22
-
-
Save mcfarhat/64c3e0d4334e8ef58a76aa016f2d1c37 to your computer and use it in GitHub Desktop.
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 | |
/* overriding og:title format for bank entry post types */ | |
function gk_bank_entry_wpseo_og_title( $title ) { | |
//only perform this action on single posts | |
if ( is_singular() ) { | |
//grab currently available post | |
$post = get_queried_object(); | |
//check for match of the intended post type | |
if (get_post_type($post) == 'bank_entry'){ | |
//append the post type to the title | |
$title .= ' '.get_post_type($post); | |
} | |
} | |
return $title; | |
} | |
add_filter( 'wpseo_opengraph_title', 'gk_bank_entry_wpseo_og_title' ); | |
/* overriding og:description field with custom content from a custom field */ | |
function gk_bank_entry_wpseo_opengraph_desc( $desc ) { | |
//only perform this action on single posts | |
if ( is_singular() ) { | |
//grab currently available post | |
$post = get_queried_object(); | |
//check for match of the intended post type | |
if (get_post_type($post) == 'bank_entry'){ | |
//replace the description with the content of the custom field if the field has content, otherwise use the default value | |
$overriding_desc = get_post_meta( $post->ID, 'bank_entry_sharing_description', true ); | |
if (!empty($overriding_desc) && $overriding_desc != ''){ | |
$desc = $overriding_desc; | |
} | |
} | |
} | |
return $desc; | |
} | |
add_filter( 'wpseo_opengraph_desc', 'gk_bank_entry_wpseo_og_desc' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment