如何在Blogger模板的Google结构化数据JSON中使用if else判断
你当前的写法不符合Blogger模板语法规则,将条件逻辑作为JSON属性写入会导致结构化数据校验失败,正确实现方式如下:
"image": { "@type": "ImageObject", "width": 1920, "height": 1080, "url": "<b:if cond='data:post.firstImageUrl'><data:post.firstImageUrl/><b:else/>https://example.com/logo.png</b:if>", "caption": "<data:post.title/>" }
补充说明:
- 该写法使用Blogger原生
<b:if>条件标签在模板渲染阶段直接输出符合条件的url值,最终生成的JSON无多余属性,完全符合Google结构化数据规范 - 如需要严格过滤空字符串场景,可将判断条件调整为
<b:if cond='data:post.firstImageUrl and data:post.firstImageUrl != ""'
内容的提问来源于stack exchange,提问作者0x00000dead
相关产品推荐
相关产品推荐

