Site icon Hip-Hop Website Design and Development

Firing schema via code in functions.php doesn’t work

I’ve been banging my head against the wall trying to get schema figured out, so if anyone can help me, I’d appreciate it greatly.

I’m trying to manually add my schema via custom fields, and then firing the schema via a function in my child theme’s functions.php.

Well,

When I input this code

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

into my functions.php, I’m met with this error.

Your PHP code changes were rolled back due to an error on line 27 of file wp-content/themes/astra-child/functions.php. Please fix and try saving again.

syntax error, unexpected '<', expecting end of file

I then realized that the code needs to be in my header.php file, but I don’t have a header.php file in my child theme, and copying that content over into a new header.php file in my child theme may not be ideal, as when the creator updates their theme, I wouldn’t get the benefits of their updated code.

How would I go about resolving this issue? All I want to do is fire my schema via custom fields.

Also, is it a problem that I have different schemas on each page, but each custom field is named ‘schema’?

Anyways, I hope this isn’t too much to ask. I appreciate any help you can offer.