{"id":1947,"date":"2025-06-10T18:10:28","date_gmt":"2025-06-10T10:10:28","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/wpdt\/1947.html"},"modified":"2025-06-10T18:10:28","modified_gmt":"2025-06-10T10:10:28","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8wordpress%e4%b8%ad%e5%8a%a8%e6%80%81%e6%94%b9%e5%8f%98oembed%e7%9a%84%e5%ae%bd%e5%ba%a6%e5%92%8c%e9%ab%98%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/post\/1947.html","title":{"rendered":"\u5982\u4f55\u5728WordPress\u4e2d\u52a8\u6001\u6539\u53d8oEmbed\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"Bug&#32534;&#35793;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<p class=\"my-0\">Bug&#32534;&#35793;&#29422;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312;WordPress&#20013;&#65292;&#20320;&#21487;&#20197;&#36890;&#36807;&#20462;&#25913;&#25554;&#20214;&#25110;&#33258;&#23450;&#20041;&#20195;&#30721;&#26469;&#21160;&#24577;&#35843;&#25972;oEmbed&#30340;&#23485;&#24230;&#21644;&#39640;&#24230;&#12290;&#20197;&#19979;&#26159;&#20855;&#20307;&#27493;&#39588;&#65306;<\/p>\n<ol>\n<li>\n<p>&#25214;&#21040;&#20320;&#30340;oEmbed&#25554;&#20214;&#65306;&#36890;&#24120;&#24773;&#20917;&#19979;&#65292;oEmbed&#25554;&#20214;&#20250;&#23433;&#35013;&#22312;<code>\/wp-content\/plugins\/oembed<\/code>&#30446;&#24405;&#19979;&#12290;<\/p>\n<\/li>\n<li>\n<p>&#20462;&#25913;oEmbed&#30456;&#20851;&#25991;&#20214;&#65306;<\/p>\n<ul>\n<li>&#22312;oEmbed&#25554;&#20214;&#30340;&#20027;&#25991;&#20214;&#65288;&#36890;&#24120;&#26159;<code>oembed.php<\/code>&#65289;&#20013;&#25214;&#21040;&#19982;&#23485;&#24230;&#21644;&#39640;&#24230;&#30456;&#20851;&#30340;&#37197;&#32622;&#12290;<\/li>\n<li>&#20363;&#22914;&#65292;&#22312;&#20197;&#19979;&#20195;&#30721;&#29255;&#27573;&#20013;&#65292;&#20320;&#21487;&#20197;&#30475;&#21040;&#35774;&#32622;&#23485;&#24230;&#20026;600px&#65292;&#39640;&#24230;&#20026;350px&#65306;<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<pre><code class=\"language-php\">&lt;?php echo wp_oembed_get($url, array('width' =&gt; '600', 'height' =&gt; '350')); ?&gt;<\/code><\/pre>\n<ol start=\"3\">\n<li>&#33258;&#23450;&#20041;&#20195;&#30721;&#23454;&#29616;&#65306;\n<ul>\n<li>&#22914;&#26524;&#20320;&#24819;&#35201;&#26356;&#28789;&#27963;&#22320;&#25511;&#21046;&#23485;&#24230;&#21644;&#39640;&#24230;&#65292;&#21487;&#20197;&#32534;&#20889;&#33258;&#23450;&#20041;&#20989;&#25968;&#26469;&#33719;&#21462;oEmbed&#25968;&#25454;&#24182;&#26681;&#25454;&#38656;&#35201;&#35843;&#25972;&#23485;&#24230;&#21644;&#39640;&#24230;&#12290;<\/li>\n<li>&#31034;&#20363;&#20195;&#30721;&#22914;&#19979;&#65306;<\/li>\n<\/ul><\/li>\n<\/ol>\n<pre><code class=\"language-php\">function custom_oembed_width_height($url) {\n    $oembed_data = wp_oembed_get($url);\n    if ($oembed_data &amp;&amp; isset($oembed_data['width']) &amp;&amp; isset($oembed_data['height'])) {\n        return sprintf('&lt;img src=\"%s\" width=\"%d\" height=\"%d\"&gt;', esc_url($oembed_data['url']), (int)$oembed_data['width'], (int)$oembed_data['height']);\n    } else {\n        return '&lt;p&gt;Error loading oEmbed data.&lt;\/p&gt;';\n    }\n}\nadd_filter('the_content', 'custom_oembed_width_height');<\/code><\/pre>\n<ol start=\"4\">\n<li>&#20351;&#29992;&#33258;&#23450;&#20041;&#20989;&#25968;&#65306;\n<ul>\n<li>&#23558;&#19978;&#36848;&#20195;&#30721;&#28155;&#21152;&#21040;&#20320;&#30340;&#20027;&#39064;&#30340;functions.php&#25991;&#20214;&#20013;&#12290;<\/li>\n<li>&#29616;&#22312;&#65292;&#24403;&#20320;&#20351;&#29992;<code>&lt;figure&gt;<\/code>&#26631;&#31614;&#26102;&#65292;oEmbed&#23558;&#33258;&#21160;&#35843;&#25972;&#20854;&#23485;&#24230;&#21644;&#39640;&#24230;&#20197;&#21305;&#37197;&#25351;&#23450;&#30340;&#23610;&#23544;&#12290;<\/li>\n<\/ul><\/li>\n<\/ol>\n<p>&#35831;&#27880;&#24847;&#65292;&#36825;&#21482;&#26159;&#19968;&#20010;&#22522;&#26412;&#31034;&#20363;&#12290;&#23454;&#38469;&#24212;&#29992;&#20013;&#21487;&#33021;&#38656;&#35201;&#26681;&#25454;&#20855;&#20307;&#38656;&#27714;&#36827;&#34892;&#26356;&#22810;&#30340;&#23450;&#21046;&#21270;&#22788;&#29702;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#40657;&#26495;&#21069;&#30340;Bug&#35821;&#27861;&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<p class=\"my-0\">&#40657;&#26495;&#21069;&#30340;Bug&#35821;&#27861;&#35762;&#24072;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312;WordPress&#20013;&#65292;&#20351;&#29992;oEmbed&#25554;&#20214;&#26469;&#23454;&#29616;&#21160;&#24577;&#35843;&#25972;&#23485;&#24230;&#21644;&#39640;&#24230;&#30340;&#21151;&#33021;&#26159;&#38750;&#24120;&#31616;&#21333;&#30340;&#12290;&#20197;&#19979;&#26159;&#22914;&#20309;&#36890;&#36807;&#35774;&#32622;&#23884;&#20837;&#20195;&#30721;&#30340;&#26041;&#24335;&#26469;&#23454;&#29616;&#36825;&#19968;&#30446;&#26631;&#65306;<\/p>\n<h3>&#27493;&#39588;1&#65306;&#28155;&#21152;oEmbed&#20195;&#30721;<\/h3>\n<p>&#39318;&#20808;&#65292;&#22312;&#20320;&#30340;&#20027;&#39064;&#25110;&#27169;&#26495;&#25991;&#20214;&#20013;&#25554;&#20837;oEmbed&#20195;&#30721;&#12290;&#36825;&#36890;&#24120;&#28041;&#21450;&#21040;&#19968;&#20010;<code>&lt;iframe&gt;<\/code>&#26631;&#31614;&#65292;&#22914;&#19979;&#25152;&#31034;&#65306;<\/p>\n<pre><code class=\"language-html\">&lt;!-- &#20301;&#20110;&#39029;&#38754;&#20013;&#30340;&#20219;&#20309;&#20301;&#32622; --&gt;\n&lt;iframe src=\"https:\/\/example.com\/embed\" width=\"500\" height=\"300\"&gt;&lt;\/iframe&gt;<\/code><\/pre>\n<h3>&#27493;&#39588;2&#65306;&#32534;&#36753;&#23884;&#20837;&#20195;&#30721;<\/h3>\n<p>&#25509;&#19979;&#26469;&#65292;&#20320;&#38656;&#35201;&#22312;oEmbed&#25554;&#20214;&#20013;&#20462;&#25913;&#23884;&#20837;&#20195;&#30721;&#20197;&#36866;&#24212;&#38656;&#35201;&#21160;&#24577;&#35843;&#25972;&#22823;&#23567;&#30340;&#38656;&#27714;&#12290;&#35201;&#36798;&#21040;&#27492;&#30446;&#30340;&#65292;&#21487;&#20197;&#32771;&#34385;&#20351;&#29992;&#33258;&#23450;&#20041;HTML&#33050;&#26412;&#26469;&#22788;&#29702;&#23884;&#20837;&#30340;&#22270;&#29255;&#12290;<\/p>\n<h3>&#27493;&#39588;3&#65306;&#32534;&#20889;&#33258;&#23450;&#20041;HTML&#33050;&#26412;<\/h3>\n<h4>&#31034;&#20363;&#20195;&#30721;1: &#20351;&#29992;JavaScript<\/h4>\n<pre><code class=\"language-javascript\">\/\/ &#33719;&#21462;&#21040;oEmbed iframe&#20803;&#32032;\nconst oembedIframe = document.querySelector('iframe#oembed');\n\n\/\/ &#35774;&#32622;&#23485;&#24230;&#21644;&#39640;&#24230;&#23646;&#24615;\noembedIframe.style.width = '500px';\noembedIframe.style.height = '300px';\n\n\/\/ &#28155;&#21152;&#20107;&#20214;&#30417;&#21548;&#22120;&#20197;&#33258;&#21160;&#26356;&#26032;&#23485;&#24230;&#21644;&#39640;&#24230;\noembedIframe.addEventListener('load', function() {\n    const oembedElement = this;\n    const width = window.getComputedStyle(oembedElement).width;\n    const height = window.getComputedStyle(oembedElement).height;\n\n    if (width &amp;&amp; height) {\n        \/\/ &#23558;&#23485;&#24230;&#21644;&#39640;&#24230;&#36716;&#25442;&#20026;&#20687;&#32032;\n        const pixelWidth = parseInt(width.replace(\"px\", \"\"));\n        const pixelHeight = parseInt(height.replace(\"px\", \"\"));\n\n        \/\/ &#35843;&#25972;iframe&#20803;&#32032;&#30340;&#23485;&#24230;&#21644;&#39640;&#24230;\n        oembedIframe.style.width = `${pixelWidth}px`;\n        oembedIframe.style.height = `${pixelHeight}px`;\n    }\n});<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;&#25105;&#20204;&#39318;&#20808;&#33719;&#21462;&#21040;oEmbed iframe&#20803;&#32032;&#65292;&#28982;&#21518;&#35774;&#32622;&#20854;&#23485;&#24230;&#21644;&#39640;&#24230;&#23646;&#24615;&#12290;&#25509;&#30528;&#65292;&#25105;&#20204;&#28155;&#21152;&#20102;&#19968;&#20010;&#20107;&#20214;&#30417;&#21548;&#22120;&#65292;&#27599;&#24403;iframe&#21152;&#36733;&#23436;&#25104;&#21518;&#65292;&#23601;&#35843;&#29992;&#19968;&#20010;&#20989;&#25968;&#26469;&#26816;&#26597;&#24403;&#21069;&#23485;&#24230;&#21644;&#39640;&#24230;&#26159;&#21542;&#21487;&#29992;&#65292;&#24182;&#26681;&#25454;&#36825;&#20123;&#20540;&#35843;&#25972;iframe&#30340;&#23610;&#23544;&#12290;<\/p>\n<h4>&#31034;&#20363;&#20195;&#30721;2: &#20351;&#29992;jQuery<\/h4>\n<pre><code class=\"language-javascript\">$(document).ready(function(){\n    let oembedIframe = $('iframe#oembed');\n\n    oembedIframe.css({\n        'width': '500',\n        'height': '300'\n    });\n\n    oembedIframe.on('load', function(){\n        var width = $(this).css('width');\n        var height = $(this).css('height');\n\n        if (width &amp;&amp; height){\n            width = parseInt(width, 10);\n            height = parseInt(height, 10);\n\n            $(this).css({\n                'width': `${width}px`,\n                'height': `${height}px`\n            });\n        }\n    });\n});<\/code><\/pre>\n<p>&#36825;&#20010;&#20363;&#23376;&#19982;&#19978;&#36848;JavaScript&#29256;&#26412;&#31867;&#20284;&#65292;&#21482;&#26159;&#37319;&#29992;&#20102;jQuery&#30340;&#26041;&#24335;&#12290;&#21516;&#26679;&#22320;&#65292;&#25105;&#20204;&#20808;&#33719;&#21462;&#21040;oEmbed iframe&#20803;&#32032;&#65292;&#28982;&#21518;&#35774;&#32622;&#20854;&#23485;&#24230;&#21644;&#39640;&#24230;&#23646;&#24615;&#12290;&#28982;&#21518;&#65292;&#25105;&#20204;&#22312;iframe&#19978;&#28155;&#21152;&#20102;&ldquo;on&rdquo;&#20107;&#20214;&#30417;&#21548;&#22120;&#65292;&#24403;iframe&#21152;&#36733;&#23436;&#25104;&#21518;&#65292;&#20877;&#27425;&#35843;&#29992;&#19968;&#20010;&#20989;&#25968;&#26469;&#26816;&#26597;&#23485;&#24230;&#21644;&#39640;&#24230;&#26159;&#21542;&#21487;&#29992;&#65292;&#24182;&#26681;&#25454;&#36825;&#20123;&#20540;&#35843;&#25972;iframe&#30340;&#23610;&#23544;&#12290;<\/p>\n<h3>&#27880;&#24847;&#20107;&#39033;<\/h3>\n<ul>\n<li>&#30830;&#20445;&#22312;&#25554;&#20837;oEmbed&#20195;&#30721;&#20043;&#21069;&#27491;&#30830;&#23433;&#35013;&#24182;&#21551;&#29992;oEmbed&#25554;&#20214;&#12290;<\/li>\n<li>&#22312;&#23454;&#38469;&#24212;&#29992;&#20013;&#65292;&#30830;&#20445;&#20351;&#29992;&#23433;&#20840;&#30340;HTTPS&#36830;&#25509;&#65292;&#24182;&#27880;&#24847;&#36991;&#20813;&#21253;&#21547;&#25935;&#24863;&#20449;&#24687;&#30340;&#38142;&#25509;&#12290;<\/li>\n<\/ul>\n<p>&#36890;&#36807;&#20197;&#19978;&#27493;&#39588;&#65292;&#20320;&#21487;&#20197;&#36731;&#26494;&#22320;&#22312;WordPress&#20013;&#21160;&#24577;&#35843;&#25972;oEmbed&#30340;&#23485;&#24230;&#21644;&#39640;&#24230;&#12290;&#36825;&#26679;&#20570;&#30340;&#30446;&#30340;&#26159;&#20026;&#20102;&#26356;&#22909;&#22320;&#36866;&#24212;&#19981;&#21516;&#23631;&#24149;&#23610;&#23544;&#21644;&#35774;&#22791;&#38656;&#27714;&#65292;&#25552;&#20379;&#26356;&#22909;&#30340;&#29992;&#25143;&#20307;&#39564;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#22312;WordPress&#20013;&#65292;&#20320;&#21487;&#20197;&#36890;&#36807;&#20462;&#25913;&#25554;&#20214;&#25110;&#33258;&#23450;&#038;#2..<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[52,53],"tuisongtax":[],"class_list":["post-1947","post","type-post","status-publish","format-standard","hentry","category-wpdt","tag-ztjc","tag-ztmbpzjc"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/1947","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/comments?post=1947"}],"version-history":[{"count":0,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/1947\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/media?parent=1947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/categories?post=1947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=1947"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=1947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}