Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1487532

    I need to add some structured data (schema markup) to 1 page only, lets say the homepage, but maybe to another ones.

    An example for google:

    
    <script type="application/ld+json">
        {
          "@context": "https://schema.org/",
          "@id": "https://www.example.com/advancedCpp",
          "@type": "Course",
          "name": "Learn Advanced C++ Topics",
          "description": "Improve your C++ skills by learning advanced topics.",
          "publisher": {
            "@type": "Organization",
            "name": "CourseWebsite",
            "url": "www.examplecoursewebsite.com"
          },
          "provider": {
            "@type": "Organization",
            "name": "Example University",
            "url": "www.example.com"
          }
        </script>
    

    How can I add that just to 1 page (homepage) or another page using functions?

    Thank you.

    #1487538

    Hey peterolle,

    Thank you for the inquiry.

    You can use the wp_head or wp_footer hook to add the script to a specific page.

    Example:

    function ava_json_ld_mod() {
        /// replace placeholder slug-of-your-page with the actual slug or ID of the page
        if (is_page('slug-of-your-page')) { 
            ?>
            <script type="application/ld+json">
            {
              "@context": "https://schema.org/",
              "@id": "https://www.example.com/advancedCpp",
              "@type": "Course",
              "name": "Learn Advanced C++ Topics",
              "description": "Improve your C++ skills by learning advanced topics.",
              "publisher": {
                "@type": "Organization",
                "name": "CourseWebsite",
                "url": "https://www.examplecoursewebsite.com"
              },
              "provider": {
                "@type": "Organization",
                "name": "Example University",
                "url": "https://www.example.com"
              }
            }
            </script>
            <?php
        }
    }
    add_action('wp_head', 'ava_json_ld_mod');
    

    Make sure to the adjust the value of the is_page conditional function.

    Best regards,
    Ismael

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.