这是我的第一个WP插件。目标是将JSON-LD插入特定站点每个页面的头部。到目前为止,我已经完成了更高级的简单PHP。它可以验证,但可能存在其他问题。评论?
<?php
/*
Plugin Name: SEO (JSON-LD) Insert
Plugin URI: http://www.realizetech.com/
Description: Plugin to hold SEO functions maybe more...
Version: 1.0.0
Author: auth name
Author URI: http://www.authname.com/
Text Domain: our-seo-insert
*/
defined(\'ABSPATH\') or die(\'No direct file access allowed!\');
// Modify post content
function myplugin_filter_content($content)
{
return $content . \'<p>Almost an error message but not quite.</p>\';
}
add_filter(\'the_content\', \'myplugin_filter_content\');
function wpse238918_allow_schema($in)
{
if (!empty($in[\'extended_valid_elements\']))
$in[\'extended_valid_elements\'] .= \',\';
$in[\'extended_valid_elements\'] .= \'@[id|class|style|title|itemscope|itemtype|itemprop|datetime|rel],div,dl,ul,dt,dd,li,span,a|rev|charset|href|lang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur]\';
return $in;
}
add_filter(\'tiny_mce_before_init\', \'wpse238918_allow_schema\');
add_action(\'wp_head\', \'wpse_43672_wp_head\');
function wpse_43672_wp_head()
{
//Close PHP tags
?>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "LocalBusiness",
"additionalType": "http://www.productontology.org/id/Computer_repair_technician",
"additionalType": "http://www.productontology.org/id/Computer_network",
"additionalType": "http://www.productontology.org/id/Computer_security",
"additionalType": "http://www.productontology.org/id/Computer_hardware",
"priceRange" : "$500 - $20,000",
"address": {
"@type": "PostalAddress",
"addressLocality": "Tulsa",
"addressRegion": "OK",
"postalCode":"74135",
"streetAddress": "3303 S. Harvard Ave., Ste. D"
},
"description": "Computer repair, computer networking, computer security, computer hardware",
"name": "Realize Information Technology, LLC",
"email":"info@realizetech.com",
"telephone": "918-508-2228",
"faxNumber": "918-508-2277",
"openingHours": "Mo,Tu,We,Th,Fr 08:00-17:00",
"image":"http://www.realizetech.com/wp-content/uploads/2017/01/LOGO-COLOR_2594x922.jpg"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": "36.11",
"longitude": "-95.94"
},
"sameAs" : [ "https://www.facebook.com/Realize-Information-Technology-155305947842689/"]
}
</script>
<?php //Open PHP tags
}
/* Stop Adding Functions Below this Line */
?>