JSON-LD: creating an AggregateOffer from many shortcode

I've created a shortcode which outputs product schema in JSON-LD format.1 schortcode = 1 product = 1 product schem

I've created a shortcode which outputs product schema in JSON-LD format.

1 schortcode = 1 product = 1 product schema output 2 schortcode = 2 product = 2 product schema output

The problem is that then I've realized that all the products in an article should create a single JSON-LD (see the image).

2 schortcode = 2 product = 1 product schema output

This means that the schema output should be outputted only by the last shortcode of this kind.

The question

Shortcodes output in wordpress are usually independent one from the others, they are "stateless" (the output depends only on the input parameters). But can I force them to a different behaviour? I've thought of using global variables inside the shortcode handler and output the aggregated JSON only after the last shortcode has been called).

Is this a good solution?

I've created a shortcode which outputs product schema in JSON-LD format.

1 schortcode = 1 product = 1 product schema output 2 schortcode = 2 product = 2 product schema output

The problem is that then I've realized that all the products in an article should create a single JSON-LD (see the image).

2 schortcode = 2 product = 1 product schema output

This means that the schema output should be outputted only by the last shortcode of this kind.

The question

Shortcodes output in wordpress are usually independent one from the others, they are "stateless" (the output depends only on the input parameters). But can I force them to a different behaviour? I've thought of using global variables inside the shortcode handler and output the aggregated JSON only after the last shortcode has been called).

Is this a good solution?

Share Improve this question edited Jun 15, 2020 at 8:21 CommunityBot 1 asked Jul 9, 2019 at 22:05 ReviousRevious 3233 silver badges16 bronze badges 2
  • I have no idea what you are talking about. – Justin Waulters Commented Jul 10, 2019 at 2:06
  • @JustinWaulters: can you see if now the question is clear? – Revious Commented Jul 10, 2019 at 7:25
Add a comment  | 

1 Answer 1

Reset to default 1

If you have full control over the system, it would be best to get all of the data by some other means.

If you must concatenate the shortcodes, you can parse the content to get the shortcodes with get_shortcode_regex().

You can save all the matches, and their attributes, and remove them from the content. Then, you can either move them all to the end (or where ever you want them) or process them to get whatever data you need.

On the other hand, you could just use microdata schema markup in your html instead of the JSON-LD format. For an example, see Example 1 here and click the microdata tab.

Hope this helps

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745306543a4621744.html

相关推荐

  • JSON-LD: creating an AggregateOffer from many shortcode

    I've created a shortcode which outputs product schema in JSON-LD format.1 schortcode = 1 product = 1 product schem

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信