正确的结构为第一个可湿性粉剂插件?

时间:2017-06-23 作者:Luke 5 Dev

这是我的第一个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 */
?>

1 个回复
最合适的回答,由SO网友:Luke 5 Dev 整理而成

在Wordpress Codex和相关网站上对当前(2016/2017)解决方案进行更多研究。。。以下经过测试,效果良好。。。

`已定义(\'ABSPATH\')或die(\'No direct file access allowed!\');//修改post contentfunction myplugin_filter_content($content){return$content\'。几乎是一条错误消息,但不完全是。

“;}添加\\u filter(\'the\\u content\',\'myplugin\\u filter\\u content\');

函数schema\\u TinyMCE\\u init($in){$props=\'@[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]\';if(isset($在[\'extended\\u valid\\u elements\'中]){if(!empty($在[\'extended\\u valid\\u elements\'中]){$在[\'extended\\u valid\\u elements\'中])].=\',\';}$在[\'extended\\u valid\\u elements\']中。=$道具;}else{$in[\'extended\\u valid\\u elements\']=$props;}返回$in;}add\\u filter(\'tiny\\u mce\\u before\\u init\',\'schema\\u TinyMCE\\u init\');

添加\\u操作(“wp\\u头”,“wpse\\u 43672\\u wp\\u头”);函数wpse\\u 43672\\u wp\\u head(){//关闭PHP标记?>

{此处正确的JSON语法}

<?php //Open PHP tags
}/*停止在此行下方添加函数*/?>`

结束

相关推荐