{"id":4755,"date":"2025-10-20T18:39:12","date_gmt":"2025-10-20T10:39:12","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4755.html"},"modified":"2025-11-20T19:28:48","modified_gmt":"2025-11-20T11:28:48","slug":"wordpress%e5%90%91%e6%8c%87%e5%ae%9a%e6%96%87%e7%ab%a0%e7%b1%bb%e5%9e%8b%e5%8d%95%e7%8b%ac%e6%b7%bb%e5%8a%a0bootstrap%e6%a0%b7%e5%bc%8f%e8%a1%a8%e7%9a%84%e6%96%b9%e6%b3%95%e5%92%8c%e4%bb%a3%e7%a0%81","status":"publish","type":"bjjc","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4755.html","title":{"rendered":"WordPress\u5411\u6307\u5b9a\u6587\u7ae0\u7c7b\u578b\u5355\u72ec\u6dfb\u52a0CSS\u6837\u5f0f\u8868\u5230\u7f51\u7ad9\u524d\u53f0\u53ca\u540e\u53f0"},"content":{"rendered":"<p>\u5c06\u901a\u8fc7\u4fee\u6539\u4e3b\u9898\u7684 <code>functions.php<\/code> \u6587\u4ef6\u6765\u5b9e\u73b0\u529f\u80fd\uff0c\u8fd9\u662f\u4e00\u79cd\u5e38\u89c1\u4e14\u76f8\u5bf9\u9ad8\u6548\u7684\u65b9\u6cd5\u3002<\/p><h2 class=\"wp-block-heading\">\u5b9e\u73b0\u65b9\u6848\u6982\u8ff0<\/h2><p>\u901a\u8fc7\u4fee\u6539\u4e3b\u9898\u7684 <code>functions.php<\/code> \u6587\u4ef6\uff08\u6216\u4f7f\u7528\u81ea\u5b9a\u4e49\u529f\u80fd\u63d2\u4ef6\uff09\uff0c\u60a8\u53ef\u4ee5\u6761\u4ef6\u5316\u5730\u4e3a &#8220;bsv5&#8221; \u6587\u7ae0\u7c7b\u578b\u5f15\u5165\u81ea\u5b9a\u4e49\u7684 Bootstrap \u6837\u5f0f\u8868\u3002\u5b9e\u73b0\u6b64\u529f\u80fd\u4e3b\u8981\u6d89\u53ca\u4ee5\u4e0b\u4e24\u4e2a\u6b65\u9aa4\uff1a<\/p><ol class=\"wp-block-list\">\n<li><strong>\u6761\u4ef6\u5316\u5730\u5411\u5757\u7f16\u8f91\u5668\uff08Gutenberg\uff09\u5f15\u5165\u6837\u5f0f<\/strong>\uff1a\u5728\u7f16\u8f91 <code>bsv5<\/code> \u6587\u7ae0\u7c7b\u578b\u65f6\uff0c\u5c06\u60a8\u7684\u81ea\u5b9a\u4e49\u6837\u5f0f\u8868\u52a0\u8f7d\u5230\u7f16\u8f91\u5668\u4e2d\u3002<\/li>\n\n\n\n<li><strong>\u6761\u4ef6\u5316\u5730\u5411\u524d\u7aef\u6587\u7ae0\u9875\u9762\u5f15\u5165\u6837\u5f0f<\/strong>\uff1a\u5f53\u8bbf\u95ee <code>bsv5<\/code> \u6587\u7ae0\u7c7b\u578b\u7684\u5355\u7bc7\u6587\u7ae0\u9875\u9762\u65f6\uff0c\u5728\u524d\u7aef\u52a0\u8f7d\u540c\u6837\u7684\u6837\u5f0f\u8868\u3002<\/li>\n<\/ol><p>\u4ee5\u4e0b\u662f\u5177\u4f53\u7684\u4ee3\u7801\u5b9e\u73b0\u6b65\u9aa4\u548c\u8bf4\u660e\u3002<\/p><h2 class=\"wp-block-heading\">\u4ee3\u7801\u5b9e\u73b0<\/h2><p>\u5c06\u4ee5\u4e0b\u4ee3\u7801\u6dfb\u52a0\u5230\u60a8\u5f53\u524d\u4e3b\u9898\u7684 <code>functions.php<\/code> \u6587\u4ef6\u4e2d\uff08\u5efa\u8bae\u5148\u5907\u4efd\uff09\u3002\u5982\u679c\u60a8\u4e0d\u719f\u6089\u4ee3\u7801\u64cd\u4f5c\uff0c\u5efa\u8bae\u4f7f\u7528\u5b50\u4e3b\u9898\u8fdb\u884c\u64cd\u4f5c\uff0c\u4ee5\u907f\u514d\u4e3b\u9898\u66f4\u65b0\u65f6\u4fee\u6539\u88ab\u8986\u76d6\u3002<\/p><pre class=\"wp-block-code\"><code>\/**\n * \u6839\u636e\u6587\u7ae0\u7c7b\u578b\u6761\u4ef6\u5316\u5730\u5411WordPress\u5757\u7f16\u8f91\u5668\u548c\u524d\u7aef\u6dfb\u52a0\u81ea\u5b9a\u4e49Bootstrap\u6837\u5f0f\u8868\n *\/\n\n\/\/ 1. \u5411\u6587\u7ae0\u7c7b\u578b\u4e3a'bsv5'\u7684\u540e\u53f0\u5757\u7f16\u8f91\u5668\u5f15\u5165\u81ea\u5b9a\u4e49bootstrap\u6837\u5f0f\u8868\nfunction add_bootstrap_diy_to_editor() {\n    global $post;\n    \/\/ \u68c0\u67e5\u662f\u5426\u5728\u7f16\u8f91\u9875\u9762\u4e14\u5f53\u524d\u6587\u7ae0\u7c7b\u578b\u662f'bsv5'\n    if ( is_admin() &amp;&amp; ! empty( $post ) &amp;&amp; 'bsv5' === $post-&gt;post_type ) {\n        \/\/ \u83b7\u53d6\u7f51\u7ad9\u6839\u76ee\u5f55\u8def\u5f84\uff08\u9002\u7528\u4e8e\u4e0d\u540c\u670d\u52a1\u5668\u73af\u5883\uff09\n        $bootstrap_diy_css_path = get_home_path() . 'css\/bootstrap.css';\n        \/\/ \u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff0c\u5b58\u5728\u624d\u5f15\u5165\n        if ( file_exists( $bootstrap_diy_css_path ) ) {\n            \/\/ \u83b7\u53d6\u6587\u4ef6\u4fee\u6539\u65f6\u95f4\u7528\u4e8e\u7248\u672c\u63a7\u5236\uff0c\u907f\u514d\u7f13\u5b58\n            $version = filemtime( $bootstrap_diy_css_path );\n            \/\/ \u6784\u5efa\u6587\u4ef6URL\n            $bootstrap_diy_css_url = home_url( '\/css\/bootstrap.css' );\n            \/\/ \u5411\u7f16\u8f91\u5668\u6dfb\u52a0\u6837\u5f0f\u3002\n            wp_enqueue_style( \n                'bootstrap-editor', \n                $bootstrap_diy_css_url, \n                array(), \n                $version \n            );\n        }\n    }\n}\n\/\/ \u94a9\u5b50\uff1a\u5728\u7f16\u8f91\u5668\u52a0\u8f7d\u8d44\u6e90\u65f6\u6267\u884c\nadd_action( 'enqueue_block_editor_assets', 'add_bootstrap_diy_to_editor' );\n\n\/\/ 2. \u5411\u6587\u7ae0\u7c7b\u578b\u4e3a'bsv5'\u7684\u524d\u7aef\u6587\u7ae0\u9875\u9762\u5f15\u5165\u81ea\u5b9a\u4e49bootstrap\u6837\u5f0f\u8868\nfunction add_bootstrap_diy_to_frontend() {\n    \/\/ \u68c0\u67e5\u662f\u5426\u5728\u5355\u7bc7\u6587\u7ae0\u9875\u9762\u4e14\u6587\u7ae0\u7c7b\u578b\u662f'bsv5'\n    if ( is_singular( 'bsv5' ) ) {\n        \/\/ \u83b7\u53d6\u7f51\u7ad9\u6839\u76ee\u5f55\u8def\u5f84\n        $bootstrap_diy_css_path = get_home_path() . 'css\/bootstrap.css';\n        \/\/ \u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff0c\u5b58\u5728\u624d\u5f15\u5165\n        if ( file_exists( $bootstrap_diy_css_path ) ) {\n            \/\/ \u83b7\u53d6\u6587\u4ef6\u4fee\u6539\u65f6\u95f4\u7528\u4e8e\u7248\u672c\u63a7\u5236\n            $version = filemtime( $bootstrap_diy_css_path );\n            \/\/ \u6784\u5efa\u6587\u4ef6URL\n            $bootstrap_diy_css_url = home_url( '\/css\/bootstrap.css' );\n            \/\/ \u5411\u524d\u7aef\u6dfb\u52a0\u6837\u5f0f\n            wp_enqueue_style( \n                'bootstrap-frontend', \n                $bootstrap_diy_css_url, \n                array(), \n                $version \n            );\n        }\n    }\n}\n\/\/ \u94a9\u5b50\uff1a\u5728\u524d\u7aef\u52a0\u8f7d\u8d44\u6e90\u65f6\u6267\u884c\nadd_action( 'wp_enqueue_scripts', 'add_bootstrap_diy_to_frontend' );<\/code><\/pre><h2 class=\"wp-block-heading\">\u4ee3\u7801\u8bf4\u660e<\/h2><ul class=\"wp-block-list\">\n<li><strong><code>get_home_path()<\/code> \u51fd\u6570<\/strong>\uff1a\u7528\u4e8e\u83b7\u53d6 WordPress \u5b89\u88c5\u7684\u6839\u76ee\u5f55\u8def\u5f84\u3002\u8fd9\u53ef\u80fd\u9700\u8981\u5728\u60a8\u7684 <code>functions.php<\/code> \u6587\u4ef6\u9876\u90e8\uff08\u5728 <code>&lt;?php<\/code> \u4e4b\u540e\uff09\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801 if it&#8217;s not already available\uff1a<br><code>php if ( ! function_exists( 'get_home_path' ) ) { require_once ABSPATH . 'wp-admin\/includes\/file.php'; }<\/code><\/li>\n\n\n\n<li><strong>\u6587\u4ef6\u5b58\u5728\u6027\u68c0\u67e5 (<code>file_exists<\/code>)<\/strong>: \u5728\u5c1d\u8bd5\u52a0\u5165\u6837\u5f0f\u8868\u4e4b\u524d\uff0c\u4ee3\u7801\u4f1a\u68c0\u67e5 <code>bootstrap-diy.css<\/code> \u6587\u4ef6\u662f\u5426\u5b58\u5728\uff0c\u4ee5\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u9519\u8bef\u3002<\/li>\n\n\n\n<li><strong>\u7248\u672c\u63a7\u5236 (<code>filemtime<\/code>)<\/strong>: \u4f7f\u7528\u6587\u4ef6\u7684\u6700\u540e\u4fee\u6539\u65f6\u95f4\u4f5c\u4e3a\u7248\u672c\u53f7\uff0c\u53ef\u4ee5\u786e\u4fdd\u5728\u60a8\u66f4\u65b0 CSS \u6587\u4ef6\u540e\uff0c\u6d4f\u89c8\u5668\u80fd\u52a0\u8f7d\u6700\u65b0\u7684\u6837\u5f0f\uff0c\u800c\u4e0d\u4f1a\u4f7f\u7528\u7f13\u5b58\u7684\u65e7\u7248\u672c\u3002<\/li>\n\n\n\n<li><strong>\u6761\u4ef6\u903b\u8f91<\/strong>:\n<ul class=\"wp-block-list\">\n<li>\u5bf9\u4e8e\u7f16\u8f91\u5668 (<code>enqueue_block_editor_assets<\/code> \u94a9\u5b50)\uff0c\u68c0\u67e5\u662f\u5426\u5728\u7ba1\u7406\u540e\u53f0\u4e14\u5f53\u524d\u5168\u5c40 <code>$post<\/code> \u5bf9\u8c61\u7684\u7c7b\u578b\u4e3a <code>bsv5<\/code>\u3002<\/li>\n\n\n\n<li>\u5bf9\u4e8e\u524d\u7aef (<code>wp_enqueue_scripts<\/code> \u94a9\u5b50)\uff0c\u4f7f\u7528 <code>is_singular( 'bsv5' )<\/code> \u6765\u68c0\u67e5\u5f53\u524d\u662f\u5426\u6b63\u5728\u663e\u793a\u4e00\u7bc7\u5355\u72ec\u7684 <code>bsv5<\/code> \u7c7b\u578b\u6587\u7ae0\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul><h2 class=\"wp-block-heading\">\u6ce8\u610f\u4e8b\u9879<\/h2><ol class=\"wp-block-list\">\n<li><strong>\u8def\u5f84\u6b63\u786e\u6027<\/strong>: \u8bf7\u786e\u4fdd <code>bootstrap-diy.css<\/code> \u6587\u4ef6\u786e\u5b9e\u4f4d\u4e8e\u60a8\u7f51\u7ad9\u7684\u6839\u76ee\u5f55\u4e0b\u7684 <code>\/skint\/css\/<\/code> \u6587\u4ef6\u5939\u4e2d\u3002<code>get_home_path()<\/code> \u83b7\u53d6\u7684\u662f\u670d\u52a1\u5668\u4e0a WordPress \u5b89\u88c5\u7684\u7edd\u5bf9\u8def\u5f84\uff08\u4f8b\u5982 <code>\/home\/user\/public_html\/<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>\u7f13\u5b58\u95ee\u9898<\/strong>: \u4fee\u6539\u4ee3\u7801\u548c CSS \u6587\u4ef6\u540e\uff0c\u7531\u4e8e\u6d4f\u89c8\u5668\u3001\u63d2\u4ef6\u6216\u670d\u52a1\u5668\u7f13\u5b58\uff0c\u60a8\u53ef\u80fd\u65e0\u6cd5\u7acb\u5373\u770b\u5230\u53d8\u5316\u3002\u8bf7\u5c1d\u8bd5\u6e05\u9664\u6240\u6709\u76f8\u5173\u7684\u7f13\u5b58\u3002<\/li>\n\n\n\n<li><strong>\u6267\u884c\u987a\u5e8f\u548c\u4f9d\u8d56<\/strong>: \u6b64\u4ee3\u7801\u5c06\u60a8\u7684\u81ea\u5b9a\u4e49 Bootstrap \u6837\u5f0f\u8868\u4f5c\u4e3a\u72ec\u7acb\u7684\u6837\u5f0f\u8868\u52a0\u5165\u3002\u5982\u679c\u5b83\u9700\u8981\u8986\u76d6\u5176\u4ed6 Bootstrap \u6837\u5f0f\u7684\u89c4\u5219\uff0c\u8bf7\u786e\u4fdd\u5176\u9009\u62e9\u5668\u7684\u7279\u5f02\u6027\u8db3\u591f\u9ad8\uff0c\u6216\u8005\u8003\u8651\u4f7f\u7528 <code>!important<\/code>\uff08\u4e0d\u63a8\u8350\u5927\u91cf\u4f7f\u7528\uff09\u3002<\/li>\n\n\n\n<li><strong>\u4e3b\u9898\u517c\u5bb9\u6027<\/strong>: \u6b64\u4ee3\u7801\u5047\u8bbe\u60a8\u7684\u4e3b\u9898\u652f\u6301\u5e76\u6b63\u786e\u4f7f\u7528\u4e86\u6807\u51c6\u7684 WordPress \u6837\u5f0f\u8868\u6392\u961f\u7cfb\u7edf\u3002\u7edd\u5927\u591a\u6570\u73b0\u4ee3\u4e3b\u9898\u90fd\u662f\u5982\u6b64\u3002<\/li>\n\n\n\n<li><strong>\u5b50\u4e3b\u9898\u5efa\u8bae<\/strong>: \u5f3a\u70c8\u5efa\u8bae\u5728<strong>\u5b50\u4e3b\u9898<\/strong>\u7684 <code>functions.php<\/code> \u6587\u4ef6\u4e2d\u8fdb\u884c\u6b64\u7c7b\u4fee\u6539\uff0c\u4ee5\u9632\u6b62\u4e3b\u9898\u66f4\u65b0\u65f6\u60a8\u6dfb\u52a0\u7684\u4ee3\u7801\u88ab\u8986\u76d6\u3002<\/li>\n\n\n\n<li><strong>\u63d2\u4ef6\u51b2\u7a81<\/strong>: \u5982\u679c\u60a8\u4f7f\u7528\u4e86\u67d0\u4e9b\u4f18\u5316\u3001\u7f13\u5b58\u6216\u8d44\u6e90\u7ba1\u7406\u63d2\u4ef6\uff0c\u5b83\u4eec\u53ef\u80fd\u4f1a\u5e72\u6270\u6837\u5f0f\u8868\u7684\u52a0\u8f7d\u3002\u5982\u679c\u9047\u5230\u95ee\u9898\uff0c\u8bf7\u5c1d\u8bd5\u6682\u65f6\u505c\u7528\u76f8\u5173\u63d2\u4ef6\u4ee5\u6392\u67e5\u3002<\/li>\n<\/ol><h2 class=\"wp-block-heading\">\u66ff\u4ee3\u65b9\u6848<\/h2><p>\u9664\u4e86\u76f4\u63a5\u4fee\u6539\u4ee3\u7801\uff0c\u60a8\u4e5f\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u7c7b\u4f3c <strong>WP Add Custom CSS<\/strong> \u8fd9\u6837\u7684\u63d2\u4ef6\u3002\u8fd9\u7c7b\u63d2\u4ef6\u901a\u5e38\u5141\u8bb8\u60a8\u9488\u5bf9\u4e0d\u540c\u7684\u6587\u7ae0\u7c7b\u578b\u6216\u5355\u4e2a\u6587\u7ae0\u9875\u9762\u6dfb\u52a0\u81ea\u5b9a\u4e49 CSS \u89c4\u5219\u6216\u6837\u5f0f\u8868\u3002\u5982\u679c\u60a8\u4e0d\u4e60\u60ef\u7f16\u7801\uff0c\u8fd9\u53ef\u80fd\u662f\u4e00\u4e2a\u66f4\u7528\u6237\u53cb\u597d\u7684\u9009\u62e9\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u5c06\u901a\u8fc7\u4fee\u6539\u4e3b\u9898\u7684 functions.php \u6587\u4ef6\u6765\u5b9e\u73b0\u529f\u80fd\uff0c\u8fd9\u662f\u4e00\u79cd\u5e38\u89c1\u4e14\u76f8\u5bf9\u9ad8\u6548\u7684\u65b9\u6cd5\u3002 \u5b9e\u73b0\u65b9\u6848\u6982\u8ff0 \u901a\u8fc7\u4fee\u6539\u4e3b\u9898\u7684 functions.php \u6587\u4ef6\uff08\u6216\u4f7f\u7528\u81ea\u5b9a\u4e49\u529f\u80fd\u63d2\u4ef6\uff09\uff0c\u60a8\u53ef\u4ee5\u6761\u4ef6\u5316\u5730\u4e3a &#8220;bsv5&#8221; \u6587\u7ae0\u7c7b\u578b\u5f15\u5165\u81ea\u5b9a\u4e49\u7684 Bootstrap \u6837\u5f0f\u8868\u3002\u5b9e\u73b0\u6b64\u529f\u80fd\u4e3b\u8981\u6d89\u53ca\u4ee5\u4e0b\u4e24\u4e2a\u6b65\u9aa4\uff1a..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":true},"tags":[3290,3291],"bjjc2nav":[16],"tuisongtax":[],"class_list":["post-4755","bjjc","type-bjjc","status-publish","hentry","tag-wbjqtjysbd","tag-wwzqttjysb","bjjc2nav-functionpz"],"acf":{"qian_art_seotitle":"WordPress\u5411\u6307\u5b9a\u6587\u7ae0\u7c7b\u578b\u5355\u72ec\u6dfb\u52a0CSS\u6837\u5f0f\u8868\u5230\u7f51\u7ad9\u524d\u7aef\u53ca\u540e\u53f0","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":"WordPress\u5411\u6307\u5b9a\u6587\u7ae0\u7c7b\u578b\u5355\u72ec\u6dfb\u52a0CSS\u6837\u5f0f\u8868\u5230\u7f51\u7ad9\u524d\u7aef\u53ca\u540e\u53f0"},"qian_art_seokws":"\u4e3aWordPress\u7f16\u8f91\u5668\u6dfb\u52a0CSS\u6837\u5f0f\u8868\u7684\u65b9\u6cd5,\u4e3aWordPress\u7f51\u7ad9\u524d\u53f0\u6dfb\u52a0CSS\u6837\u5f0f\u8868\u7684\u65b9\u6cd5","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":"\u4e3aWordPress\u7f16\u8f91\u5668\u6dfb\u52a0CSS\u6837\u5f0f\u8868\u7684\u65b9\u6cd5,\u4e3aWordPress\u7f51\u7ad9\u524d\u53f0\u6dfb\u52a0CSS\u6837\u5f0f\u8868\u7684\u65b9\u6cd5"},"qian_art_stzhong":"\u5f15\u5165\u6837\u5f0f\u8868 \u6307\u5b9a\u6587\u7ae0\u7c7b\u578b\u7684\u524d\u540e\u53f0","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":"\u5f15\u5165\u6837\u5f0f\u8868 \u6307\u5b9a\u6587\u7ae0\u7c7b\u578b\u7684\u524d\u540e\u53f0"}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc\/4755","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/types\/bjjc"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/media?parent=4755"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=4755"},{"taxonomy":"bjjc2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc2nav?post=4755"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=4755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}