WP_Widget_Text::inject_video_max_width_style() WordPress Method

The WP_Widget_Text::inject_video_max_width_style() method is used to inject custom styles into the header of a WordPress site to ensure that videos embedded in widgets are sized correctly. This is particularly useful for sites that use a responsive design, as it can help ensure that videos maintain their correct aspect ratio when the site is viewed on different devices.

WP_Widget_Text::inject_video_max_width_style( array $matches ) #

Inject max-width and remove height for videos too constrained to fit inside sidebars on frontend.


Description

Top ↑

See also


Top ↑

Parameters

$matches

(array)(Required)Pattern matches from preg_replace_callback.


Top ↑

Return

(string) HTML Output.


Top ↑

Source

File: wp-includes/widgets/class-wp-widget-text.php

	public function inject_video_max_width_style( $matches ) {
		$html = $matches[0];
		$html = preg_replace( '/\sheight="\d+"/', '', $html );
		$html = preg_replace( '/\swidth="\d+"/', '', $html );
		$html = preg_replace( '/(?<=width:)\s*\d+px(?=;?)/', '100%', $html );
		return $html;
	}

Top ↑

Changelog

Changelog
VersionDescription
4.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.