Skip to content

Instantly share code, notes, and snippets.

@schemapress
Created October 25, 2017 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schemapress/5b8d2ecda98aff162e036ef480f7ea48 to your computer and use it in GitHub Desktop.
Save schemapress/5b8d2ecda98aff162e036ef480f7ea48 to your computer and use it in GitHub Desktop.
Add schema.org markup generated by Schema plugin to the content https://schema.press/
<?php //* do not include php tag
add_filter('the_content','my_schema_wp_markup_output_in_content_6876867');
/**
* Add schema.org markup generated by Schema plugin to the content
*
* return string
*/
function my_schema_wp_markup_output_in_content_6876867( $content ) {
global $post;
// get markup from post meta
$schema_json = get_post_meta( $post->ID, '_schema_json', true );
/*
* You can do it this way...
*
ob_start();
echo '<script type="application/ld+json">' . json_encode($schema_json, JSON_UNESCAPED_UNICODE) . '</script>';
$final_script = ob_get_contents();
ob_end_clean();
*
*/
// or simply do it liek this
$final_script = '<script type="application/ld+json">' . json_encode($schema_json, JSON_UNESCAPED_UNICODE) . '</script>';
// return the content and final script
return $content . $final_script;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment