{"id":1046,"date":"2013-01-21T06:02:00","date_gmt":"2013-01-20T22:02:00","guid":{"rendered":"https:\/\/www.wpdaxue.com\/?p=1046"},"modified":"2013-10-13T13:13:21","modified_gmt":"2013-10-13T05:13:21","slug":"wordpress-shortcode","status":"publish","type":"post","link":"https:\/\/www.wpdaxue.com\/wordpress-shortcode.html","title":{"rendered":"WordPress Shortcode\uff08\u7b80\u7801\uff09\u4ecb\u7ecd\u53ca\u4f7f\u7528\u8be6\u89e3"},"content":{"rendered":"<p>WordPress \u4ece 2.5 \u7248\u672c\u5f00\u59cb\u589e\u52a0\u4e86\u4e00\u4e2a\u7c7b\u4f3c BBCode \u6807\u7b7e\u7684 <a href=\"https:\/\/www.wpdaxue.com\/tag\/shortcode\" title=\"\u67e5\u770b\u4e0e\u3010Shortcode\u3011\u76f8\u5173\u7684\u6587\u7ae0\" target=\"_blank\">Shortcode<\/a> API\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b83\u5728\u65e5\u5fd7\u7684\u5185\u5bb9\u4e2d\u6765\u7ed9\u65e5\u5fd7\u5185\u5bb9\u6dfb\u52a0\u5404\u79cd\u529f\u80fd\u3002<a href=\"https:\/\/www.wpdaxue.com\/tag\/shortcode\" title=\"\u67e5\u770b\u4e0e\u3010Shortcode\u3011\u76f8\u5173\u7684\u6587\u7ae0\" target=\"_blank\">Shortcode<\/a> \u8fd9\u4e2a\u63a5\u53e3\u975e\u5e38\u5bb9\u6613\u4f7f\u7528\uff0c\u5e76\u4e14\u529f\u80fd\u975e\u5e38\u5f3a\u5927\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px\" title=\"wpdaxue.com-201301300\" border=\"0\" alt=\"wpdaxue.com-201301300\" src=\"https:\/\/www.wpdaxue.com\/img\/2013\/01\/wpdaxue.com-201301300.png\" width=\"550\" height=\"250\" \/><\/p>\n<p>\u7b80\u5355\u8bf4 WordPress Shortcode \u6307\u7684\u662f\u4e00\u4e9b\u4f7f\u7528[]\u5305\u542b\u7684\u77ed\u4ee3\u7801\uff0cWordPress\u4f1a\u8bc6\u522b\u8fd9\u4e9b\u77ed\u4ee3\u7801\u5e76\u6839\u636e\u77ed\u4ee3\u7801\u7684\u5b9a\u4e49\u8f93\u51fa\u4e3a\u7279\u5b9a\u7684\u5185\u5bb9\u3002<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u6587\u7ae0\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #333333;color:#333333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #333333;color:#333333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.wpdaxue.com\/wordpress-shortcode.html\/#Shortcode_%E7%B1%BB%E5%9E%8B\" >Shortcode \u7c7b\u578b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.wpdaxue.com\/wordpress-shortcode.html\/#Shortcode_%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5\" >Shortcode \u57fa\u672c\u6982\u5ff5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.wpdaxue.com\/wordpress-shortcode.html\/#Shortcode_%E7%9B%B8%E5%85%B3%E7%9A%84%E6%89%80%E6%9C%89%E5%87%BD%E6%95%B0\" >Shortcode \u76f8\u5173\u7684\u6240\u6709\u51fd\u6570<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.wpdaxue.com\/wordpress-shortcode.html\/#%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E7%9A%84_Shortcode_%E4%BE%8B%E5%AD%90\" >\u4e00\u4e2a\u7b80\u5355\u7684 Shortcode \u4f8b\u5b50<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.wpdaxue.com\/wordpress-shortcode.html\/#%E4%BD%BF%E7%94%A8_Shortcode_%E6%8A%95%E6%94%BE_Google_Adsense_%E5%B9%BF%E5%91%8A\" >\u4f7f\u7528 Shortcode \u6295\u653e Google Adsense \u5e7f\u544a<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.wpdaxue.com\/wordpress-shortcode.html\/#%E5%9C%A8%E4%BE%A7%E8%BE%B9%E6%A0%8F_Widgets_%E4%B8%AD%E4%BD%BF%E7%94%A8_Shortcode\" >\u5728\u4fa7\u8fb9\u680f Widgets \u4e2d\u4f7f\u7528 Shortcode<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.wpdaxue.com\/wordpress-shortcode.html\/#%E5%9C%A8%E4%B8%BB%E9%A2%98%E7%9A%84%E6%96%87%E4%BB%B6%E4%B8%AD%E4%BD%BF%E7%94%A8_Shortcode\" >\u5728\u4e3b\u9898\u7684\u6587\u4ef6\u4e2d\u4f7f\u7528 Shortcode<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.wpdaxue.com\/wordpress-shortcode.html\/#%E8%A7%A3%E5%86%B3_Shortcode_%E4%B8%AD%E8%87%AA%E5%8A%A8%E6%B7%BB%E5%8A%A0%E7%9A%84_br_%E6%88%96%E8%80%85_p_%E6%A0%87%E7%AD%BE\" >\u89e3\u51b3 Shortcode \u4e2d\u81ea\u52a8\u6dfb\u52a0\u7684 br \u6216\u8005 p \u6807\u7b7e<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Shortcode_%E7%B1%BB%E5%9E%8B\"><\/span>Shortcode \u7c7b\u578b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Shortcode API \u652f\u6301\u51e0\u4e4e\u6240\u6709\u53ef\u80fd\u7684\u7ec4\u5408\u5f62\u5f0f\uff1a\u81ea\u5173\u95ed\u6807\u7b7e\uff0c\u5f00\u653e\u6807\u7b7e\uff0c\u542b\u6709\u53c2\u6570\u7684\u6807\u7b7e\u7b49\u3002<\/p>\n<pre lang=\"html4strict\" escaped=\"true\" line=\"1\">[mycode]\n[mycode foo=&quot;bar&quot; id=&quot;123&quot; color=&quot;red&quot; something=&quot;data&quot;]\n[mycode]Some Content[\/mycode]\n[mycode]&lt;p&gt;&lt;a href=&quot;http:\/\/example.com\/&quot;&gt;HTML Content&lt;\/a&lt;&gt;\/p&gt;[\/mycode]\n[mycode]Content [another-shotcode] more content[\/mycode]\n[mycode foo=&quot;bar&quot; id=&quot;123&quot;]Some Content[\/mycode]<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Shortcode_%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5\"><\/span>Shortcode \u57fa\u672c\u6982\u5ff5<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u9996\u5148\u4f60\u8981\u53bb\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\uff0c\u6765\u5904\u7406\u4f60\u5b9a\u4e49\u7684 Shortcode\uff0c\u548c\u5b83\u7684\u5c5e\u6027\u53c2\u6570\u4ee5\u53ca\u5f15\u7528\u7684\u5185\u5bb9\u3002<\/p>\n<pre lang=\"php\" escaped=\"true\" line=\"1\">function my_shortcode_func($attr, $content) {\n    \/\/ $attr $key=&gt;$value \u7684\u6570\u7ec4\n    \/\/ $content \u662f shortcode \u4e2d\u5305\u542b\u7684\u5b57\u7b26\u4e32\n    \/\/ \u5bf9 $attr \u548c $content \u8fdb\u884c\u5904\u7406\n    \/\/ \u8fd4\u56de\u9884\u671f\u7684\u503c\n}<\/pre>\n<p>\u7136\u540e\u628a\u81ea\u5df1\u5b9a\u4e49\u7684 Shortcode \u548c\u5176\u5904\u7406\u51fd\u6570\u7ba1\u7406\u8d77\u6765\uff0c\u4ee5\u4fbf [mycode attr=&quot;value&quot;]content[\/mycode] \u80fd\u591f\u6309\u7167\u9884\u671f\u6267\u884c\u3002<\/p>\n<pre lang=\"php\" escaped=\"true\" line=\"1\">add_shortcode('mycode', 'my_shortcode_func')<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Shortcode_%E7%9B%B8%E5%85%B3%E7%9A%84%E6%89%80%E6%9C%89%E5%87%BD%E6%95%B0\"><\/span>Shortcode \u76f8\u5173\u7684\u6240\u6709\u51fd\u6570<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>WordPress \u5b9a\u4e49\u4e86\u4ee5\u4e0b\u548c Shortcode \u76f8\u5173\u7684\u51fd\u6570\uff1a<\/p>\n<pre lang=\"php\" escaped=\"true\" line=\"1\">add_shortcode('mycode', 'function_name'); \/\/ \u5b9a\u4e49\u4e00\u4e2a\u65b0\u7684 Shortcode\nremove_shortcode('mycode'); \/\/ \u79fb\u9664\u4e00\u4e2a Shortcode\nremove_all_shortcodes(); \/\/ \u79fb\u9664\u6240\u6709\u7684 Shortcode\n$return = do_shortcode($content); \/\/ \u5e94\u7528 Shortcode \u5230\u5185\u5bb9\u800c\u4e0d\u8f93\u51fa<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E7%9A%84_Shortcode_%E4%BE%8B%E5%AD%90\"><\/span>\u4e00\u4e2a\u7b80\u5355\u7684 Shortcode \u4f8b\u5b50<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u4ee5\u6211\u7231\u6c34\u716e\u9c7c\u5199\u7684 Antispambot ShortCode \u63d2\u4ef6\u4e3a\u4f8b\uff0c\u5185\u5bb9\u5c31\u662f\u90ae\u7bb1\u5730\u5740\uff0c\u6709\u4e2a\u53c2\u6570 <code>$link<\/code> \u4e3a 1 \u65f6\u5019\uff0c\u628a\u90ae\u7bb1\u663e\u793a\u53ef\u70b9\u51fb\uff0c\u53c2\u6570\u5982\u4e0b\uff1a<\/p>\n<pre lang=\"php\" escaped=\"true\" line=\"1\">function antispambot_shortcode_handler($atts, $content='') {\n\textract( shortcode_atts( array(\n\t\t'link' =&gt; '0'\n\t), $atts ) );\n\t\n\tif($link){\n\t\treturn '&lt;a href=&quot;mailto:'.antispambot($content,1).'&quot; title=&quot;mail to '.antispambot($content,0).'&quot;&gt;'.antispambot($content,0).'&lt;\/a&gt;';\n\t}else{\n\t\treturn antispambot( $content,0);\n\t}\n}\nadd_shortcode('email', 'antispambot_shortcode_handler');<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"%E4%BD%BF%E7%94%A8_Shortcode_%E6%8A%95%E6%94%BE_Google_Adsense_%E5%B9%BF%E5%91%8A\"><\/span>\u4f7f\u7528 Shortcode \u6295\u653e Google Adsense \u5e7f\u544a<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u628a\u4e0b\u9762\u7684\u4ee3\u7801\u4fdd\u5b58\u5230\u4f60\u5f53\u524d\u7684\u4e3b\u9898\u7684 <code>functions.php<\/code>\uff0c\u6216\u8005\u4e0a\u4f20\u5230\u63d2\u4ef6\u76ee\u5f55\u4e0b\u5e76\u6fc0\u6d3b\u3002<\/p>\n<pre lang=\"php\" escaped=\"true\" line=\"1\">&lt;?php\n\/*\nPlugin Name: Shorcode for Google Adsense\nPlugin URI:  http:\/\/blog.wpjam.com\/m\/shortcode-google-adsense\/\nDescription: \u4f7f\u7528 Shortcode \u6295\u653e Google Adsense \u5e7f\u544a\nVersion: 0.1\nAuthor: Denis\n*\/\nadd_shortcode('adsense', 'adsense_shortcode');\nfunction adsense_shortcode($atts) {\n\textract(shortcode_atts(array(\n\t'type' =&gt; '468x60',\n\t), $atts));\n\tswitch ($type) {\n\t\tcase '468x60' :\n\t\treturn \n\t\t\t\/\/468x60 \u7684\u5e7f\u544a\u4ee3\u7801\n\t\tcase '300x250' :\n\t\treturn \n\t\t\t\/\/300x250 \u7684\u5e7f\u544a\u4ee3\u7801\n\t}\n}<\/pre>\n<p>\u7136\u540e\u4f60\u5c31\u53ef\u4ee5\u901a\u8fc7\u64b0\u5199\u6587\u7ae0\u7684\u65f6\u5019\uff0c\u5728\u76f8\u5e94\u7684\u4f4d\u7f6e\u8f93\u5165 <code>[adsense]<\/code> \u4f60\u7684 468\u00d760 \u7684\u5e7f\u544a\u4ee3\u7801\uff08\u9ed8\u8ba4\u7684\u5e7f\u544a\u4ee3\u7801\uff09\uff0c\u5982\u679c\u4f60\u60f3\u63d2\u5165 300\u00d7250 \u7684\u5e7f\u544a\u4ee3\u7801\uff0c\u5728\u6587\u7ae0\u5185\u5bb9\u4e2d\u63d2\u5165 <code>[adsense type=&quot;300x250&quot;]<\/code>\uff0c\u5f53\u7136\u4f60\u4e5f\u53ef\u4ee5\u6269\u5c55\u4e0a\u9762\u7684\u4ee3\u7801\u589e\u52a0\u66f4\u591a\u5e7f\u544a\u7684\u683c\u5f0f\u548c\u7c7b\u578b\u3002<\/p>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u60f3\u628a\u5e7f\u544a\u63d2\u5728\u6587\u7ae0\u4e2d\u7684\u54ea\u4e2a\u4f4d\u7f6e\uff0c\u5c31\u80fd\u63d2\u5728\u54ea\u4e2a\u4f4d\u7f6e\u4e86\uff0c&#160; \u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E5%9C%A8%E4%BE%A7%E8%BE%B9%E6%A0%8F_Widgets_%E4%B8%AD%E4%BD%BF%E7%94%A8_Shortcode\"><\/span>\u5728\u4fa7\u8fb9\u680f Widgets \u4e2d\u4f7f\u7528 Shortcode<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Shortcode \u5f88\u65b9\u4fbf\uff0c\u4f46\u662f\u53ea\u80fd\u7528\u5728\u65e5\u5fd7\u5185\u5bb9\u4e2d\uff0c\u90a3\u4e48\u5982\u4f55\u5728 WordPress \u7684\u4fa7\u8fb9\u680f\u7684 Widgets \u4e2d\u4f7f\u7528 Shortcode\uff0c\u5728\u5f53\u524d\u4e3b\u9898\u7684 <code>functions.php<\/code> \u4e2d\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre lang=\"php\" escaped=\"true\" line=\"1\">add_filter('widget_text', 'do_shortcode');<\/pre>\n<p>\u7136\u540e\u4f60\u5728 WordPress \u540e\u53f0 &gt; \u5916\u89c2 &gt; Widgets \u754c\u9762\u6dfb\u52a0\u4e00\u4e2a\u6587\u672c Widget\uff0c\u7136\u540e\u63d2\u5165\u535a\u5ba2\u4e2d\u7ecf\u542f\u7528 shortcode \u5373\u53ef\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E5%9C%A8%E4%B8%BB%E9%A2%98%E7%9A%84%E6%96%87%E4%BB%B6%E4%B8%AD%E4%BD%BF%E7%94%A8_Shortcode\"><\/span>\u5728\u4e3b\u9898\u7684\u6587\u4ef6\u4e2d\u4f7f\u7528 Shortcode<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u5982\u679c\u4f60\u60f3\u7528\u5728\u4e3b\u9898\u6587\u4ef6\u4e2d\u4f7f\u7528\u540d\u4e3a [my_shortcode] \u7684 Shortcode\uff0c\u4f60\u53ea\u9700\u8981\u6309\u7167\u4e0b\u9762\u7684\u65b9\u5f0f\u4f7f\u7528<code>do_shortcode()<\/code> \u51fd\u6570\u5373\u53ef\uff1a<\/p>\n<pre lang=\"php\" escaped=\"true\" line=\"1\">&lt;?php echo do_shortcode(&quot;[my_shortcode]&quot;); ?&gt;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"%E8%A7%A3%E5%86%B3_Shortcode_%E4%B8%AD%E8%87%AA%E5%8A%A8%E6%B7%BB%E5%8A%A0%E7%9A%84_br_%E6%88%96%E8%80%85_p_%E6%A0%87%E7%AD%BE\"><\/span>\u89e3\u51b3 Shortcode \u4e2d\u81ea\u52a8\u6dfb\u52a0\u7684 br \u6216\u8005 p \u6807\u7b7e<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u6211\u4eec\u5728\u4f7f\u7528 WordPress Shortcode API \u5f00\u53d1\u63d2\u4ef6\u7684\u65f6\u5019\uff0c\u6709\u4e2a\u6bd4\u8f83\u9ebb\u70e6\u7684\u95ee\u9898\uff0c\u5c31\u662f WordPress \u4f1a\u81ea\u52a8\u5728 shortcode \u5185\u6dfb\u52a0 br \u6216\u8005 p \u6807\u7b7e\uff0c\u8fd9\u6837\u53ef\u80fd\u4f1a\u6253\u4e71\u4f60\u7684\u539f\u5148\u9884\u60f3\u7684 HTML \u7ed3\u6784\u548c\u5e03\u5c40\u3002<\/p>\n<p>\u9020\u6210\u8fd9\u4e2a\u95ee\u9898\u7684\u539f\u56e0\u662f WordPress \u9ed8\u8ba4\u7684\u65e5\u5fd7\u5185\u5bb9\u5904\u7406\u6d41\u7a0b\u4e2d\uff0cwpautop\uff08\u5c06\u56de\u8f66\u8f6c\u6362\u6210 p \u6216\u8005 br \u6807\u7b7e\u7684\u51fd\u6570\uff09\u662f\u5728 Shortcode \u524d\u9762\u8fd0\u884c\u7684\u3002\u6240\u4ee5\u6211\u4eec\u7684\u89e3\u51b3\u65b9\u6848\u4e5f\u662f\u975e\u5e38\u7b80\u5355\uff0c\u6539\u53d8\u5b83\u4eec\u6267\u884c\u7684\u987a\u5e8f\uff0c\u5728\u5f53\u524d\u4e3b\u9898\u7684 <code>functions.php<\/code> \u6587\u4ef6\u4e2d\u6dfb\u52a0\uff1a<\/p>\n<pre lang=\"php\" escaped=\"true\" line=\"1\">remove_filter( 'the_content', 'wpautop' );\nadd_filter( 'the_content', 'wpautop' , 12);<\/pre>\n<p>\u8fd9\u6837\u8c03\u6574\u987a\u5e8f\u4e4b\u540e\uff0c\u4f60\u7684 shortcode \u91cc\u9762\u7684\u5185\u5bb9\uff0c\u5c31\u4e0d\u4f1a\u6709\u81ea\u52a8\u6dfb\u52a0\u7684 p \u6216\u8005 br \u6807\u7b7e\uff0c\u4f46\u662f\u5982\u679c shortcode \u4e2d\u90e8\u5206\u7684\u5185\u5bb9\u4f60\u53c8\u9700\u8981\u4e00\u4e9b p \u6216\u8005 br \u6807\u7b7e\u7528\u6765\u6362\u884c\u7684\u8bdd\uff0c\u4f60\u9700\u8981\u81ea\u5df1\u624b\u52a8\u5728\u81ea\u5df1 shortcode \u5904\u7406\u7a0b\u5e8f\u4e2d\u6dfb\u52a0 wpautop \u6765\u5904\u7406\u4e86\u3002<\/p>\n<pre lang=\"php\" escaped=\"true\" line=\"1\">function bio_shortcode($atts, $content = null) {\n   $content = wpautop(trim($content));\n   return '&lt;div class=&quot;bio&quot;&gt;' . $content . '&lt;\/div&gt;';\n}\nadd_shortcode('bio', 'bio_shortcode');<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>WordPress \u4ece 2.5 \u7248\u672c\u5f00\u59cb\u589e\u52a0\u4e86\u4e00\u4e2a\u7c7b\u4f3c BBCode \u6807\u7b7e\u7684 Shortcode API\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b83\u5728\u65e5\u5fd7\u7684\u5185\u5bb9\u4e2d\u6765\u7ed9\u65e5\u5fd7\u5185\u5bb9\u6dfb\u52a0\u5404\u79cd\u529f\u80fd\u3002Shortcode \u8fd9\u4e2a\u63a5\u53e3\u975e\u5e38\u5bb9\u6613\u4f7f\u7528\uff0c\u5e76\u4e14\u529f\u80fd\u975e\u5e38\u5f3a\u5927\u3002 \u7b80\u5355\u8bf4 WordPress Shortcode \u6307\u7684\u662f\u4e00\u4e9b\u4f7f\u7528<\/p>\n","protected":false},"author":1,"featured_media":22609,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_gspb_post_css":"","footnotes":""},"categories":[4],"tags":[42,198],"collection":[],"class_list":["post-1046","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-develop","tag-shortcode","tag-198"],"_links":{"self":[{"href":"https:\/\/www.wpdaxue.com\/wp-json\/wp\/v2\/posts\/1046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wpdaxue.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wpdaxue.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wpdaxue.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wpdaxue.com\/wp-json\/wp\/v2\/comments?post=1046"}],"version-history":[{"count":0,"href":"https:\/\/www.wpdaxue.com\/wp-json\/wp\/v2\/posts\/1046\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wpdaxue.com\/wp-json\/wp\/v2\/media\/22609"}],"wp:attachment":[{"href":"https:\/\/www.wpdaxue.com\/wp-json\/wp\/v2\/media?parent=1046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wpdaxue.com\/wp-json\/wp\/v2\/categories?post=1046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wpdaxue.com\/wp-json\/wp\/v2\/tags?post=1046"},{"taxonomy":"collection","embeddable":true,"href":"https:\/\/www.wpdaxue.com\/wp-json\/wp\/v2\/collection?post=1046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}