How to Set oEmbed Max Width in WordPress: 4 Simple Methods

by Quartez Watson

Do you need to set a maximum width for oEmbeds in WordPress?

WordPress automatically embeds third-party content like YouTube videos and Tweets. However, at times these embeds can become too wide and disrupt your website’s design. In this article, we will guide you on how to set the maximum width for oEmbeds in WordPress, providing you with more control over your site layout.

Why Adjust the Maximum OEmbed Width in WordPress?

WordPress supports oEmbed, allowing automatic embedding of content from third-party websites. For instance, you can effortlessly embed YouTube videos, SlideShare presentations, tweets, and various other types of content. Since this content is not hosted on your server, it does not slow down your website. It’s crucial to utilize technologies such as oEmbed and refrain from uploading videos directly to WordPress.

Method 1: Utilizing the Embed Shortcode (Ideal for YouTube Videos)

You can establish a maximum width using a shortcode. This technique is convenient, especially when you wish to specify the maximum width for a limited number of posts. Additionally, we have observed that this approach is effective for incorporating videos into WordPress blog posts. However, it’s important to note that the embed shortcode, along with its width and height parameters, may not function for all oEmbed providers. For instance, it cannot be utilized to set the height and width of a Giphy embed in WordPress. In such cases, you may want to try one of the alternative methods outlined below. Instead of directly inserting the URL into the post editor, you’ll need to create a shortcode block. Subsequently, you can include width and height parameters within the embed code. Simply adjust the width and height values to align with your specific requirements and replace the URL with the content you intend to embed. Once you are satisfied with the page, simply click on either ‘Update’ or ‘Publish.’ The embedded content will now seamlessly adapt to the available space.

Method 2: Leveraging the Built-in WordPress Embed Blocks (Simple)

The WordPress block editor is equipped with various embed blocks tailored to different oEmbed services. Certain blocks offer the flexibility to modify the embed’s alignment and designate the content as ‘Wide width’ or ‘Full width.’ Opting for full width will cause both the embed block and the embedded content to span the entire screen width. On the other hand, selecting wide width will expand the embed block to full width while keeping the content size unchanged. The outcome may vary based on your WordPress theme. Nevertheless, given its expediency and simplicity, it’s worthwhile to explore whether this approach suits your WordPress website. Merely click on the ‘Align’ button in the compact toolbar above the block, and then choose either ‘Wide width’ or ‘Full width.’ If this resolves the maximum width concern for the embed, feel free to proceed and publish the page. If you find the appearance unsatisfactory, consider trying an alternative approach.

Method 3: Utilizing Custom PHP (Setting a Maximum Width for All Embeds)

At times, you may wish to establish a maximum width for all embedded content. The most straightforward approach is to incorporate custom code into your WordPress website. However, a challenge with this method arises when the embedded content already has a defined ‘width’ attribute. In such cases, the maximum width attribute may not take effect. For those unfamiliar with editing their site’s code, we suggest referring to our comprehensive guide on seamlessly adding custom code snippets in WordPress. While some guides propose manual theme file edits, this practice can introduce common WordPress errors and potentially disrupt your website’s functionality. Therefore, we recommend employing WPCode, a tool that simplifies the integration of code snippets in WordPress without necessitating direct theme file modifications. This allows for theme updates or changes without compromising your custom code functionalities. To begin, you’ll need to install and activate the WPCode plugin, which is available for free. For detailed instructions, please refer to our step-by-step guide on installing a WordPress plugin. On the subsequent screen, provide a title for the code snippet. This serves as a reference and can be customized as per your preference. Ensure to adjust the height and width attributes to align with your requirements. Lastly, slide the ‘Inactive’ toggle to ‘Active.’ Then, click either the ‘Save Snippet’ or ‘Update’ button to activate the code snippet.

Method 4: Utilizing CSS (Setting a Maximum Width for Specific Embed Types)

WordPress inherently assigns CSS classes to various sections of your website. In the case of embed blocks, WordPress includes multiple CSS classes that can be leveraged to establish a maximum width for embeds in your WordPress blog. This approach is advantageous if you aim to set a maximum size for a particular embed type, like embedded Tweets. Moreover, it allows for a standardized maximum size for all embedded content, irrespective of type. To determine the requisite CSS classes for targeting, embed content in a post or page and preview it in your browser. Subsequently, hover over the embedded content and right-click. From the ensuing menu, opt for the ‘Inspect’ tool. This action unveils a new panel displaying all the CSS classes added by WordPress to the embedded content. These classes can be utilized to define a maximum width for this embed type. To pinpoint a specific oEmbed provider, you will typically employ .wp-block-embed-providername. Hence, search for this class within the panel. For Pinterest embeds, you can specifically set a maximum width using the .wp-block-embed-pinterest class. It’s important to note that depending on the content you wish to target, you might need to substitute .wp-block-embed-pinterest with an alternative CSS class.

Related Posts

Leave a Comment