使用PHP为wordpress页面增加creativework结构化SEO数据
发表于更新于
广州
woocommerceSEO使用PHP为wordpress页面增加creativework结构化SEO数据
❄️2winter使用PHP为wordpress页面增加creativework结构化SEO数据
这个不太常用,建议还是使用普通的article更具体。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| function creativework_structured_data() { if (is_page()) { $page_title = get_the_title(); $page_content = get_the_content(); $page_content = strip_shortcodes($page_content); $date_published = get_the_date('Y-m-d'); $date_modified = get_the_modified_date('Y-m-d'); $author_name = get_the_author(); $page_url = get_permalink(); $site_name = get_bloginfo('name'); $site_logo_url = get_site_icon_url();
$structured_data = ' <script type="application/ld+json"> { "@context": "https://schema.org", "@type": "CreativeWork", "name": "' . esc_js($page_title) . '", "text": "' . esc_js(strip_tags($page_content)) . '", "datePublished": "' . esc_js($date_published) . '", "dateModified": "' . esc_js($date_modified) . '", "author": { "@type": "Organization", "name": "你的站点名称" }, "publisher": { "@type": "Organization", "name": "' . esc_js($site_name) . '", "logo": { "@type": "ImageObject", "url": "' . esc_url($site_logo_url) . '" } }, "mainEntityOfPage": "' . esc_url($page_url) . '" } </script> '; echo $structured_data; } } add_action('wp_head', 'creativework_structured_data');
|
❄️2winter
ReactNative FullStack Developer
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 ❄️2winter!