{"id":650811,"date":"2025-07-25T12:50:32","date_gmt":"2025-07-25T04:50:32","guid":{"rendered":"http:\/\/puo.cn\/?p=650811"},"modified":"2025-07-27T17:02:42","modified_gmt":"2025-07-27T09:02:42","slug":"wordpress-%e6%96%87%e7%ab%a0%e6%b7%bb%e5%8a%a0%e5%89%af%e6%a0%87%e9%a2%98","status":"publish","type":"post","link":"http:\/\/puo.cn\/?p=650811","title":{"rendered":"WordPress \u6587\u7ae0\u6dfb\u52a0\u526f\u6807\u9898"},"content":{"rendered":"<p>\u540e\u53f0\u7f16\u8f91\u533a\u6dfb\u52a0\u81ea\u5b9a\u4e49\u526f\u6807\u9898\u5b57\u6bb5<\/p>\n<p>\/**<br \/>\n* Add Subtitle in all post<br \/>\n*\/<br \/>\nfunction article_subtitle( $post ) {<br \/>\nif ( ! in_array( $post-&gt;post_type, [ &#8216;post&#8217;, &#8216;page&#8217;, &#8216;knowledgebase&#8217; ], true ) ) {<br \/>\nreturn;<br \/>\n}<br \/>\n\/\/ The subtitle field.<br \/>\n$_stitle = sanitize_text_field( get_post_meta( $post-&gt;ID, &#8216;_article_subtitle&#8217;, true ) );<br \/>\necho &#8216;&lt;label for=&#8221;article_subtitle&#8221;&gt;&#8217; . __( &#8216;Sub Title &#8216; ) . &#8216;&lt;\/label&gt;&#8217;;<br \/>\necho &#8216;&lt;input type=&#8221;text&#8221; name=&#8221;article_subtitle&#8221; id=&#8221;article_subtitle&#8221; value=&#8221;&#8216; . $_stitle . &#8216;&#8221; size=&#8221;100&#8243; spellcheck=&#8221;true&#8221; autocomplete=&#8221;off&#8221; \/&gt;&#8217;;<br \/>\n}<\/p>\n<p>function article_save_subtitle( $post_ID, $post, $update ) {<br \/>\nif ( ! in_array( $post-&gt;post_type, [ &#8216;post&#8217;, &#8216;page&#8217;, &#8216;knowledgebase&#8217; ], true ) ) {<br \/>\nreturn;<br \/>\n}<br \/>\n\/\/ Prevent to execute twice.<br \/>\nif ( defined( &#8216;DOING_AJAX&#8217; ) &amp;&amp; DOING_AJAX ) {<br \/>\nreturn;<br \/>\n}<br \/>\nif (defined(&#8216;DOING_AUTOSAVE&#8217;) &amp;&amp; DOING_AUTOSAVE) {<br \/>\nreturn;<br \/>\n}<br \/>\n\/\/ Get the subtitle value from $_POST.<br \/>\n$_stitle = filter_input( INPUT_POST, &#8216;article_subtitle&#8217;, FILTER_SANITIZE_STRING );<br \/>\nif ( $update ) {<br \/>\n\/\/ Update the post meta.<br \/>\nupdate_post_meta( $post_ID, &#8216;_article_subtitle&#8217;, sanitize_text_field( $_stitle ) );<br \/>\n} else if ( ! empty ( $_stitle ) ) {<br \/>\n\/\/ Add unique post meta.<br \/>\nadd_post_meta( $post_ID, &#8216;_article_subtitle&#8217;, sanitize_text_field( $_stitle ), true );<br \/>\n}<br \/>\n}<br \/>\nadd_action( &#8216;edit_form_after_title&#8217;, &#8216;article_subtitle&#8217;, 20 );<br \/>\nadd_action( &#8216;wp_insert_post&#8217;, &#8216;article_save_subtitle&#8217;, 20, 3 );<\/p>\n<p>&nbsp;<\/p>\n<p>\u4fdd\u5b58\u6216\u9884\u89c8\u6587\u7ae0\uff0c\u4f1a\u5c06\u526f\u6807\u9898\u5b57\u6bb5\u63d2\u5165\u5230\u6570\u636e\u5e93\u4e2d\u7684 wp_postmeta \u8868\u4e2d\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-650812\" title=\"20250725124948792\" src=\"http:\/\/loc-wp-cdnimg.jiyun.net\/blogtest\/2025\/07\/20250725124948792.png\" alt=\"20250725124948792\" width=\"615\" height=\"261\" srcset=\"http:\/\/loc-wp-cdnimg.jiyun.net\/blogtest\/2025\/07\/20250725124948792.png 615w, http:\/\/loc-wp-cdnimg.jiyun.net\/blogtest\/2025\/07\/20250725124948792-300x127.png 300w\" sizes=\"auto, (max-width: 615px) 100vw, 615px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u9700\u8981\u5728\u6587\u7ae0\u6a21\u677f\u9875\u9762\u4e2d\u6dfb\u52a0\u526f\u6807\u9898\u663e\u793a\u7684\u6837\u5f0f\u7b49\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-650813\" title=\"20250725124948120\" src=\"http:\/\/loc-wp-cdnimg.jiyun.net\/blogtest\/2025\/07\/20250725124948120.png\" alt=\"20250725124948120\" width=\"1071\" height=\"501\" srcset=\"http:\/\/loc-wp-cdnimg.jiyun.net\/blogtest\/2025\/07\/20250725124948120.png 1071w, http:\/\/loc-wp-cdnimg.jiyun.net\/blogtest\/2025\/07\/20250725124948120-300x140.png 300w, http:\/\/loc-wp-cdnimg.jiyun.net\/blogtest\/2025\/07\/20250725124948120-1024x479.png 1024w, http:\/\/loc-wp-cdnimg.jiyun.net\/blogtest\/2025\/07\/20250725124948120-768x359.png 768w\" sizes=\"auto, (max-width: 1071px) 100vw, 1071px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u6700\u7ec8\u6548\u679c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-650814\" title=\"20250725124948530\" src=\"http:\/\/loc-wp-cdnimg.jiyun.net\/blogtest\/2025\/07\/20250725124948530.png\" alt=\"20250725124948530\" width=\"921\" height=\"649\" srcset=\"http:\/\/loc-wp-cdnimg.jiyun.net\/blogtest\/2025\/07\/20250725124948530.png 921w, http:\/\/loc-wp-cdnimg.jiyun.net\/blogtest\/2025\/07\/20250725124948530-300x211.png 300w, http:\/\/loc-wp-cdnimg.jiyun.net\/blogtest\/2025\/07\/20250725124948530-768x541.png 768w\" sizes=\"auto, (max-width: 921px) 100vw, 921px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u540e\u53f0\u7f16\u8f91\u533a\u6dfb\u52a0\u81ea\u5b9a\u4e49\u526f\u6807\u9898\u5b57\u6bb5 \/** * Add Subtitle in all post *\/ function article_subtitle( $post ) { if ( ! in_array( $post-&gt;post_t&#8230;<\/p>\n","protected":false},"author":1,"featured_media":650812,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[136],"tags":[31],"topic":[342],"class_list":["post-650811","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-136","tag-wordpress","topic-wordpress"],"_links":{"self":[{"href":"http:\/\/puo.cn\/index.php?rest_route=\/wp\/v2\/posts\/650811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/puo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/puo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/puo.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/puo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=650811"}],"version-history":[{"count":1,"href":"http:\/\/puo.cn\/index.php?rest_route=\/wp\/v2\/posts\/650811\/revisions"}],"predecessor-version":[{"id":650815,"href":"http:\/\/puo.cn\/index.php?rest_route=\/wp\/v2\/posts\/650811\/revisions\/650815"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/puo.cn\/index.php?rest_route=\/wp\/v2\/media\/650812"}],"wp:attachment":[{"href":"http:\/\/puo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=650811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/puo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=650811"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/puo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=650811"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/puo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=650811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}