• Resolved wollyroger

    (@wollyroger)


    Hi there,

    I’d like to use the schema.org ‘sameas’ code in my website, but can’t seem to get it to work. In the google article it talks about adding the code to either the head or body:

    https://developers.google.com/structured-data/customize/social-profiles

    I know i’d need to paste this into the functions.php of my child theme, but not sure exactly what code to use to get it working (i.e: add action ‘wp_head’ etc)

    Can anyone help?

    Thanks in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • Add this to the functions.php of your child theme.

    <?php
      add_action('wp_head','my_code', 20);
      function my_code() {
        ?>
        /* Add script here */
        <?php
      }
    ?>
    Thread Starter wollyroger

    (@wollyroger)

    Thanks for this,

    I found it worked if I removed the opening <?php (as this gave a syntax error). For reference, the full code read like this:

    add_action('wp_head','sameas_code', 20);
      function sameas_code() {
        ?>
        <script type="application/ld+json">
    {
      "@context" : "https://schema.org",
      "@type" : "Organization",
      "name" : "Your Organization Name",
      "url" : "https://www.your-site.com",
      "sameAs" : [
        "https://www.facebook.com/your-profile",
        "https://www.twitter.com/yourProfile",
        "https://plus.google.com/your_profile"
      ]
    }
    </script>
        <?php
      }

    HI,
    Can you mark this topic as resolved?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding 'sameas' code to head or body’ is closed to new replies.