how to execute custom field for structured data?

Question

newbie here,
Through research, I came up with the article focusing the use of the custom field to implement json+ld schema markup for a WordPress page/ post. The code is

$schemamarkup = get_post_meta(get_the_ID(), ' nameofyourcustomfield ', true);
if(!empty($nameofyourcustomfield)) {
  echo $ nameofyourcustomfield ;
}

It says to put in within tag but when I do that I only get the code is published in the frontend.

Any Suggestions for me. Would be glad. Thanks in advance

Article:https://www.elegantthemes.com/blog/tips-tricks/how-to-add-schema-markup-to-wordpress


I created a custom field with name “schema” and in value, I inserted json+ld for the post.

Then in header.php, I insert this code:

$schemamarkup = get_post_meta(get_the_ID(), 'schema', true);
    if(!empty($schema)) {
      echo $ schema ;
    }

*result i get the code displayed in the frontend

when I re-edited the code with:

<?php $schemamarkup = get_post_meta(get_the_ID(), 'schema', true);
    if(!empty($schema)) {
      echo $ schema ;
    }
?>

*result= the code is not displayed but google structured data testing tool doesn’t show the schema markup

0
, Abindra Raj Dangol 5 years 2019-01-31T02:29:29-05:00 0 Answers 51 views 0

Leave an answer

Browse
Browse