0

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

  • Can you share your complete code when you adding them into HTML tag? – Chinmoy Kumar Paul Jan 31 at 8:31
  • @ChinmoyKumarPaul the later part was what i did? – Abindra Raj Dangol Jan 31 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.