如何使用$ content_width在WordPress 3.5中设置oEmbed最大宽度

Today, we saw the release of WordPress 3.5 which came with tons of amazing features. As we upgraded one site after another, we noticed an issue on one of the sites we manage. The embedded video size were changed, and the embedded videos were a lot smaller. We went in the settings to find that the option to specify oEmbed max width and height were removed. In an attempt to simplify the admin panel, the core team got rid of the oEmbed max width and height settings screen. In this article, we will show you how to set oEmbed max width in WordPress 3.5 with $content_width.

今天,我们看到了WordPress 3.5的发布,其中包含了许多惊人的功能 。 当我们一个接一个地升级站点时,我们注意到我们管理的一个站点存在问题。 嵌入式视频的大小已更改,并且嵌入式视频要小得多。 我们进入设置,发现指定oEmbed最大宽度和高度的选项已删除。 为了简化管理面板,核心团队摆脱了oEmbed最大宽度和高度设置屏幕。 在本文中,我们将向您展示如何使用$ content_width在WordPress 3.5中设置oEmbed最大宽度。

发生了什么变化? 为什么? (What changed? and Why?)

In the past, in your Settings » Media screen there was an option to set the oEmbed max width and height.

过去,在“设置”»“媒体”屏幕中,有一个选项可以设置oEmbed的最大宽度和高度。

Media Settings oEmbed Width

Well, this option is no longer there in WordPress 3.5. The decision was made to make things simpler. There is no harm in auto-enabling oEmbeds in WordPress. If it is not enabled by default, beginners often get confused. The core devs also decided to get rid of the oEmbed max width and height fields in favor of using theme’s content width and make the height 1.5 times the content width. If your theme doesn’t have the content width defined, then your oEmbed sizes will be a lot smaller. This is exactly what happened to one of the sites we manage. The theme that was being used did not have $content_width specified.

好吧,WordPress 3.5中不再提供该选项。 决定使事情变得更简单。 在WordPress中自动启用oEmbeds没有任何危害。 如果默认情况下未启用它,则初学者通常会感到困惑。 核心开发人员还决定摆脱oEmbed的max width和height字段,转而使用主题的内容宽度,并使高度为内容宽度的1.5倍。 如果您的主题没有定义内容宽度,那么您的oEmbed大小会小很多。 这正是我们管理的网站之一发生的情况。 所使用的主题未指定$ content_width。

如何修复WordPress 3.5中的oEmbed Width问题 (How to Fix the oEmbed Width Issue in WordPress 3.5)

Open your theme’s functions.php file, and add the following code:

打开主题的functions.php文件,并添加以下代码:


if ( ! isset( $content_width ) ) $content_width = 600;

Remember to change the number 600 appropriately for your theme. It is the maximum width in pixels for your content area.

切记为主题适当更改数字600。 它是内容区域的最大宽度(以像素为单位)。

Once you do this, WordPress will automatically use that for the maximum width of your oEmbed elements (youtube videos, slideshare, etc).

完成此操作后,WordPress将自动将其用于oEmbed元素(YouTube视频,幻灯片共享等)的最大宽度。

翻译自: https://www.wpbeginner.com/wp-themes/how-to-set-oembed-max-width-in-wordpress-3-5-with-content_width/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,根据提供的引用内容,没有找到关于WordPress禁止下载的信息。但是,可以根据引用提到的防盗链设置来限制其他网站对你的WordPress网站上的图片、视频等资源的下载。具体方法如下: 1. 登录你的WordPress管理后台,进入“外观”-“编辑器”。 2. 找到主题目录下的functions.php文件,将以下代码复制粘贴到文件末尾并保存: ``` function wpbeginner_remove_version() { return ''; } add_filter('the_generator', 'wpbeginner_remove_version'); function wpbeginner_remove_wp_seo() { return ''; } add_filter('wpseo_generator', 'wpbeginner_remove_wp_seo'); function wpbeginner_remove_x_pingback($headers) { unset($headers['X-Pingback']); return $headers; } add_filter('wp_headers', 'wpbeginner_remove_x_pingback'); function wpbeginner_disable_embeds_code_init() { remove_action('rest_api_init', 'wp_oembed_register_route'); add_filter('embed_oembed_discover', '__return_false'); remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10); remove_action('wp_head', 'wp_oembed_add_discovery_links'); remove_action('wp_head', 'wp_oembed_add_host_js'); add_filter('tiny_mce_plugins', 'disable_embeds_tiny_mce_plugin'); add_filter('rewrite_rules_array', 'disable_embeds_rewrites'); } add_action('init', 'wpbeginner_disable_embeds_code_init', 9999); function disable_embeds_tiny_mce_plugin($plugins) { return array_diff($plugins, array('wpembed')); } function disable_embeds_rewrites($rules) { foreach($rules as $rule => $rewrite) { if(false !== strpos($rewrite, 'embed=true')) { unset($rules[$rule]); } } return $rules; } function wpbeginner_remove_comments_rss( $for_comments ) { return; } add_filter('post_comments_feed_link', 'wpbeginner_remove_comments_rss'); function wpbeginner_remove_comments_rss_links() { remove_action('wp_head', 'feed_links_extra', 3); remove_action('wp_head', 'feed_links', 2); } add_action('init', 'wpbeginner_remove_comments_rss_links'); function wpbeginner_remove_recent_comments_style() { global $wp_widget_factory; remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style')); } add_action('widgets_init', 'wpbeginner_remove_recent_comments_style'); function wpbeginner_remove_gallery_css($css) { return preg_replace("#<style type='text/css'>(.*?)</style>#s", '', $css); } add_filter('gallery_style', 'wpbeginner_remove_gallery_css'); function wpbeginner_remove_post_type_support() { remove_post_type_support('post', 'trackbacks'); remove_post_type_support('post', 'comments'); } add_action('init', 'wpbeginner_remove_post_type_support'); function wpbeginner_remove_dashboard_widgets() { global $wp_meta_boxes; unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); } add_action('wp_dashboard_setup', 'wpbeginner_remove_dashboard_widgets'); function wpbeginner_remove_admin_bar_links() { global $wp_admin_bar; $wp_admin_bar->remove_menu('wp-logo'); $wp_admin_bar->remove_menu('about'); $wp_admin_bar->remove_menu('wporg'); $wp_admin_bar->remove_menu('documentation'); $wp_admin_bar->remove_menu('support-forums'); $wp_admin_bar->remove_menu('feedback'); $wp_admin_bar->remove_menu('comments'); $wp_admin_bar->remove_menu('new-content'); $wp_admin_bar->remove_menu('w3tc'); } add_action('wp_before_admin_bar_render', 'wpbeginner_remove_admin_bar_links'); function wpbeginner_remove_admin_bar_css() { wp_enqueue_style('admin-bar', false); } add_action('wp_enqueue_scripts', 'wpbeginner_remove_admin_bar_css', 999); function wpbeginner_remove_dashboard_meta() { remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal'); remove_meta_box('dashboard_plugins', 'dashboard', 'normal'); remove_meta_box('dashboard_primary', 'dashboard', 'side'); remove_meta_box('dashboard_secondary', 'dashboard', 'normal'); remove_meta_box('dashboard_quick_press', 'dashboard', 'side'); remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side'); } add_action('admin_init', 'wpbeginner_remove_dashboard_meta'); function wpbeginner_remove_footer_admin() { echo ''; } add_filter('admin_footer_text', 'wpbeginner_remove_footer_admin'); function wpbeginner_remove_update_nag() { remove_action('admin_notices', 'update_nag', 3); } add_action('admin_menu', 'wpbeginner_remove_update_nag'); function wpbeginner_remove_dashboard_widgets_init() { global $wp_meta_boxes; unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); } add_action('wp_dashboard_setup', 'wpbeginner_remove_dashboard_widgets_init'); function wpbeginner_remove_dashboard_meta_init() { remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal'); remove_meta_box('dashboard_plugins', 'dashboard', 'normal'); remove_meta_box('dashboard_primary', 'dashboard', 'side'); remove_meta_box('dashboard_secondary', 'dashboard', 'normal'); remove_meta_box('dashboard_quick_press', 'dashboard', 'side'); remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side'); } add_action('admin_init', 'wpbeginner_remove_dashboard_meta_init'); function wpbeginner_remove_footer_admin_init() { echo ''; } add_filter('admin_footer_text', 'wpbeginner_remove_footer_admin_init'); function wpbeginner_remove_update_nag_init() { remove_action('admin_notices', 'update_nag', 3); } add_action('admin_menu', 'wpbeginner_remove_update_nag_init'); function wpbeginner_remove_admin_bar_links_init() { global $wp_admin_bar; $wp_admin_bar->remove_menu('wp-logo'); $wp_admin_bar->remove_menu('about'); $wp_admin_bar->remove_menu('wporg'); $wp_admin_bar->remove_menu('documentation'); $wp_admin_bar->remove_menu('support-forums'); $wp_admin_bar->remove_menu('feedback'); $wp_admin_bar->remove_menu('comments'); $wp_admin_bar->remove_menu('new-content'); $wp_admin_bar->remove_menu('w3tc'); } add_action('wp_before_admin_bar_render', 'wpbeginner_remove_admin_bar_links_init'); function wpbeginner_remove_admin_bar_css_init() { wp_enqueue_style('admin-bar', false); } add_action('wp_enqueue_scripts', 'wpbeginner_remove_admin_bar_css_init', 999); function wpbeginner_remove_comments_rss_init( $for_comments ) { return; } add_filter('post_comments_feed_link', 'wpbeginner_remove_comments_rss_init'); function wpbeginner_remove_comments_rss_links_init() { remove_action('wp_head', 'feed_links_extra', 3); remove_action('wp_head', 'feed_links', 2); } add_action('init', 'wpbeginner_remove_comments_rss_links_init'); function wpbeginner_remove_recent_comments_style_init() { global $wp_widget_factory; remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style')); } add_action('widgets_init', 'wpbeginner_remove_recent_comments_style_init'); function wpbeginner_remove_gallery_css_init($css) { return preg_replace("#<style type='text/css'>(.*?)</style>#s", '', $css); } add_filter('gallery_style', 'wpbeginner_remove_gallery_css_init'); function wpbeginner_remove_post_type_support_init() { remove_post_type_support('post', 'trackbacks'); remove_post_type_support('post', 'comments'); } add_action('init', 'wpbeginner_remove_post_type_support_init'); function wpbeginner_remove_dashboard_widgets_init() { global $wp_meta_boxes; unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); } add_action('wp_dashboard_setup', 'wpbeginner_remove_dashboard_widgets_init'); function wpbeginner_remove_dashboard_meta_init() { remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal'); remove_meta_box('dashboard_plugins', 'dashboard', 'normal'); remove_meta_box('dashboard_primary', 'dashboard', 'side'); remove_meta_box('dashboard_secondary', 'dashboard', 'normal'); remove_meta_box('dashboard_quick_press', 'dashboard', 'side'); remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side'); } add_action('admin_init', 'wpbeginner_remove_dashboard_meta_init'); function wpbeginner_remove_footer_admin_init() { echo ''; } add_filter('admin_footer_text', 'wpbeginner_remove_footer_admin_init'); function wpbeginner_remove_update_nag_init() { remove_action('admin_notices', 'update_nag', 3); } add_action('admin_menu', 'wpbeginner_remove_update_nag_init'); function wpbeginner_remove_admin_bar_links_init() { global $wp_admin_bar; $wp_admin_bar->remove_menu('wp-logo'); $wp_admin_bar->remove_menu('about'); $wp_admin_bar->remove_menu('wporg'); $wp_admin_bar->remove_menu('documentation'); $wp_admin_bar->remove_menu('support-forums'); $wp_admin_bar->remove_menu('feedback'); $wp_admin_bar->remove_menu('comments'); $wp_admin_bar->remove_menu('new-content'); $wp_admin_bar->remove_menu('w3tc'); } add_action('wp_before_admin_bar_render', 'wpbeginner_remove_admin_bar_links_init'); function wpbeginner_remove_admin_bar_css_init() { wp_enqueue_style('admin-bar', false); } add_action('wp_enqueue_scripts', 'wpbeginner_remove_admin_bar_css_init', 999); function wpbeginner_remove_comments_rss_init( $for_comments ) { return; } add_filter('post_comments_feed_link', 'wpbeginner_remove_comments_rss_init'); function wpbeginner_remove_comments_rss_links_init() { remove_action('wp_head', 'feed_links_extra', 3); remove_action('wp_head', 'feed_links', 2); } add_action('init', 'wpbeginner_remove_comments_rss_links_init'); function wpbeginner_remove_recent_comments_style_init() { global $wp_widget_factory; remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style')); } add_action('widgets_init', 'wpbeginner_remove_recent_comments_style_init'); function wpbeginner_remove_gallery_css_init($css) { return preg_replace("#<style type='text/css'>(.*?)</style>#s", '', $css); } add_filter('gallery_style', 'wpbeginner_remove_gallery_css_init'); function wpbeginner_remove_post_type_support_init() { remove_post_type_support('

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值