[Resolved] Schema Markup with Elements

Home Forums Support [Resolved] Schema Markup with Elements

Home Forums Support Schema Markup with Elements

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1340699
    Reza

    Hi,

    I would like to add Schema markups to my articles using a hook. I am not using any SEO or page building plugins, if possible I would like to keep it that way..

    <script type=”application/ld+json”>
    {“@context”:”http://schema.org&#8221;,
    “@type”:”—–”,
    mainEntityOfPage”:”—–“,
    “url”:”—–“,
    “headline”:”—–“,
    “description”:”—–“,
    “logo”:{“@type”:”ImageObject”,”url”:”—–“,”width”:xxx,”height”:xx}},
    “articleSection”:”—–“,
    “keywords”:[“—–“,”—–“,”—–“],
    “image”:[{“@type”:”ImageObject”,”url”:”—–“,”width”:xxx,”height”:xxx},
    </script>

    I understand that this is the script I have to insert in the header.

    Could anyone please help on how to best implement this on my posts AND how to automatically fill out the blanks. I would like to use the post’s excerpt for “description”. If I am not mistaken, WordPress automatically creates an excerpt if the manual excerpt box is empty.

    As far as keywords are concerned, is there a way to add them without using a plugin like ACF?

    Also is there a practical way to change “@type” depending on tags? Like the default being “Article” and if the article has a tag called “News”, the value will be “NewsArticle” instead.

    Thanks in advance

    #1340756
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You could use a Hook Element for this, but it will require a certain amount of PHP/WordPress knowledge.

    To get the excerpt, you can use this function: https://developer.wordpress.org/reference/functions/get_the_excerpt/

    When it comes to getting the logo URL, width and height, this should help: https://wordpress.stackexchange.com/a/356961/90661

    The same applies for the featured image, but you’d replace $logo with get_the_ID() to get the featured image.

    Keywords could be tough depending on where they’re coming from.

    As for the type, you could try something like:

    $type = 'Article';
    
    if ( has_tag( 'News' ) ) {
        $type = 'NewsArticle';
    }
    #1340778
    Reza

    Hi,

    So it is not possible to add template tags like “headline”:”{{post_title}}“, to fill out the fields?

    #1341194
    David
    Staff
    Customer Support

    Hi there,

    Template Tags only work if they are output within a Header Element, they’re not a global thing.

    #1341661
    Reza

    Hi,

    Is this approach a good idea or should I look for a way using the Loop? Not that I yet know what to do in both cases but using hooks seems more appealing.

    Any guidance would be much appreciated, I have nothing against detailed guides 😉

    #1341683
    David
    Staff
    Customer Support

    This is where SEO and other plugins make stuff easier. If you’re not after a full blown SEO plugin then maybe this:

    https://en-gb.wordpress.org/plugins/wp-structuring-markup/

    If you want to pursue the manual route then maybe this users example will help:

    https://help.gulshankumar.net/t/add-blogposting-article-schema-markup-in-wordpress-without-any-plugin/2099

    #1342399
    Reza

    I’ll try to wrap my head around the code and get back to you if there are any theme related questions.

    Thanks for the help.

    #1342412
    David
    Staff
    Customer Support

    That code looks like it should work as it is, its not theme specific.
    You’re welcome

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