Skip to content

Instantly share code, notes, and snippets.

@csymlstd
Created February 19, 2018 18:04
Show Gist options
  • Save csymlstd/a3be836e7a59631be9469246843f8294 to your computer and use it in GitHub Desktop.
Save csymlstd/a3be836e7a59631be9469246843f8294 to your computer and use it in GitHub Desktop.
Add Yoast Meta
<?php
function add_to_yoast_seo($post_id, $metatitle, $metadesc, $metakeywords){
$ret = false;
// Include plugin library to check if Yoast Seo is presently active
include_once( ABSPATH.'panel/includes/plugin.php' );
if(is_plugin_active(ABSPATH.'wp-content/plugins/wordpress-seo/wp-seo.php')) {
//plugin is activated
$updated_title = update_post_meta($post_id, '_yoast_wpseo_title', $metatitle);
$updated_desc = update_post_meta($post_id, '_yoast_wpseo_metadesc', $metadesc);
$updated_kw = update_post_meta($post_id, '_yoast_wpseo_metakeywords', $metakeywords);
if($updated_title && $updated_desc && $updated_kw){
$ret = true;
}
}
return $ret;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment