Created
October 25, 2017 20:09
-
-
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/
This file contains hidden or 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 //* 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