• cuenca

    (@cuenca)


    I’m having a new problem with custom fields as they are officially documented here: Assign custom fields – Documentation – www.ads-software.com

    For years I have been adding a custom field called “schemamarkup” into which I paste and save the output generated by the Google Structured Data Markup Helper tool.

    I have gone several months without posting on my site. Today for a new post, the block editor will no longer save the output from the Google Structured Data Markup Helper tool in a custom field. I paste it into the value input field and click Add Custom Field or Update and the pasted data vanishes and cannot be saved. If I just put the word “test” in the value input field, that is saved. However, I need to save the schema markup. My WordPress installation is fully up to date along with all plugins.

    The output I have from the Google Schema Markup Helper tool is of the form:

    <!-- JSON-LD markup generated by Google Structured Data Markup Helper. -->
    <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "Article",
      "headline": "My WordPress Post Title",
      "name": "My WordPress Post Title",
      "author": {
        "@type": "Person",
        "name": "Author's Name"
      },
      "datePublished": "2023-11-01",
      "dateModified": "2023-11-01",
      "image": "[image URL]",
      "articleSection": "(WordPress post category)",
      "url": "[post URL]",
      "publisher" : {
        "@type" : "Organization",
        "name" : "my organization's name",
    "logo": {
    "@type": "ImageObject",
    "name": "site logo name",
    "width": "600",
    "height": "60",
    "url": "[logo URL]"
    }
      }
    }
    </script>

    I have added this type of markup via custom fields successfully for years, starting with the classic editor and then with the block editor once it supported adding custom fields.

    Yesterday I edited and saved an existing post with markup data in a custom field and the markup data remained intact. However, I imagine that I’d have trouble if I wanted to edit existing markup data in a custom field and save the updated data.

    I’m using a child theme that has this added to header.php to pick up the markup data from the custom field. It’s the last thing included in before the closing tag of the <head> section.

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

    The above description has been my routine workflow for years. Something has broken it. How can this be fixed?

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • joecoyle

    (@joecoyle)

    Hello @cuenca

    I be more than happy to assist. I tried to reproduce the issue you are reporting but I was able to add your Data Markup Script using a “Custom HTML” block. You can Visit this page and inspect as proof. https://test.coyle.us/data-markup/

    I have added an image of the html from the Google inspect tool

    Thread Starter cuenca

    (@cuenca)

    Hello, @joecoyle,

    Thanks for your kind assistance. You led me to learn that the JSON-LD schema markup does not have to be in a custom field now. I tried adding it in a Custom HTML block as you mentioned. It works fine, validated by the Google Rich Results Test tool.

    Adding the JSON-LD schema markup via a Custom HTML block puts the markup into the body of the post rather than the head section. Today I learned that Google now says it’s okay to have it in either the head or the body. When I first started adding schema markup many years ago, all of the instructions I found at that time recommended adding it in a custom field and adding the PHP snippet to header.php in the head section to pull the markup into the head of the HTML page.

    Using the Custom HTML block for the JSON-LD markup data gives me a solution to use from now going forward. I still have a few questions for anyone who can answer.

    1. Will it be okay to leave all prior posts unchanged which used the method with custom fields as described in my original post above?

      Even those posts that already have the schema markup in a custom field that the PHP snippet is supposed to pull into the head section exhibit an unexpected behavior. That schema markup now ends up in the body, not the head. Only the comment line (first line) of the JSON-LD markup appears in the head section. The actual script with the schema data is being put into the body. I wonder how that’s happening.
    2. Why does the block editor no longer save JSON-LD schema markup data?

      While it appears that I no longer need this capability, it’s puzzling as to why it quit working. I can even copy the JSON-LD data saved in a custom field back in January and paste it into a new custom field in a new post and it will NOT be saved. When new data is saved in the value field, it kind of flashes yellow while saving. However, for the JSON-LD schema markup, it will no longer flash yellow and will not save anything.
    3. Why does the schema markup data imported into the head section of the document via the PHP snippet (see original post above) get moved into the body section? Only the comment line appears in the head. All data from the <script> tag to the </script> tag is found in the body when viewing the source of the rendered page.

    Thanks! And thanks again to @joecoyle for his kind assistance.

    joecoyle

    (@joecoyle)

    Question #1. I am guessing that you may need to migrate your previous pages to using Custom HTML blocks to handle your script if you are seeing errors

    Question #2. It does save the data from my testing but you have to switch from blocks to custom HTML

    Questions #3. Have you tried adding a custom HTML in the Header for the script?

    Thread Starter cuenca

    (@cuenca)

    Thanks, @joecoyle,

    1. These pages and posts are fine for now. I guess if any troubles arise, I’ll change to the new Custom HTML block method.
    2. The place I’ve always used for adding new custom fields and data is outside of the block editor. It is just below the bottom of the block editor panel and is hidden by default. To enable it, go to the vertical three dots in the upper right corner, then choose “preferences” and then “panels”. Custom fields should show at the bottom of the list of panels. The custom fields editor will no longer save the JSON-LD schema markup data for me. It will still save other data for other custom fields.
    3. I don’t think the block editor can put anything in the head section. The header.php file can be edited outside of WordPress to add things to the header, like the PHP snippet in my original post does. It’s pulling the script in at that position. But somehow only the comment line (first line) shows in the head section. The following lines, the JSON-LD script, show up way down in the body. It’s an unexpected outcome!

    I appreciate your interest and assistance. Thanks again.

    joecoyle

    (@joecoyle)

    Have you tried using the “Theme File Editor” under the Themes section. Once there on the right side of the page select “Theme Header”. If you add it here would this not apply to all pages?

    Make sure you back your theme header.php file because in my case I received the following error after trying to “Update File”.

    “Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.”

    After the error my header.php file was empty and I had to restore from backup. To fix this issue if you have it, you can edit “file.php” found /wp-admin/includes folder.

    Replace

    if ( $is_active && ‘php’ === $extension )

    with

    if ( $is_active && ‘php’ === $extension && false )

    Thread Starter cuenca

    (@cuenca)

    Thanks for the suggestion, @joecoyle. I don’t use the Theme File Editor because I edit the header.php outside of WordPress using a text editor. The PHP snippet has been successfully added to my header.php, which is in a child theme. That PHP snippet picks up the schema data from the custom field associated with the individual post. What I’m experiencing is that I can’t get the schema data into the custom field because WordPress will not save it there anymore. The other interesting phenomenon is that for the older posts that already have schema data in a custom field, the comment line is present in the head section where expected, but the rest of the data, the actual JSON-LD script for schema markup has been separated from the comment line and placed in the body section.

    I wouldn’t want to hardcode the JSON-LD schema markup into the header.php file because the data is different for each post and page.

    I’m sorry to learn that you lost the contents of your header.php file and had to restore it from a backup. I’m thankful that you had a backup. If you need to make changes to your header.php or other theme files, I strongly recommend that you create a child theme and also stay away from the Theme File Editor.

    Thanks again for all your willingness to help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘no longer can save schema markup data in Custom Field’ is closed to new replies.