Title: Adding schema code to header
Last modified: March 28, 2022

---

# Adding schema code to header

 *  Resolved [ana220](https://wordpress.org/support/users/ana220/)
 * (@ana220)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/adding-schema-code-to-header/)
 * Hi, I am not a developer but I trying to add a schema to my new website without
   a plugin and I want to add this code I read in an article:
 *     ```
       <?php
   
       add_action( 'wp_head', function () { ?>
   
       $schema = get_post_meta(get_the_ID(), 'schema', true);
   
       if(!empty($schema)) {
        echo $schema;
       }
   
       <?php } );
       ```
   
 * But, when I try to do this in the code snippet plugin it doesn’t work, it shows
   me the code in the frontend like text. Could you please let me know what is wrong?
   Thank you for your time.
 * * when I add this code manually in the theme editor file it works that’s why 
   I don’t know why it doesn’t with the plugin 🙁

Viewing 1 replies (of 1 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/adding-schema-code-to-header/#post-15621569)
 * You need to make sure you are using `return` to send your content instead of `
   echo` when working with shortcodes:
 *     ```
       add_action( 'wp_head', function () {
   
       	$schema = get_post_meta( get_the_ID(), 'schema', true );
   
       	if ( ! empty( $schema ) ) {
       		return $schema;
       	}
   
       	return '';
       } );
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Adding schema code to header’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [header](https://wordpress.org/support/topic-tag/header/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 1 reply
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [4 years, 1 month ago](https://wordpress.org/support/topic/adding-schema-code-to-header/#post-15621569)
 * Status: resolved