wp-mix.com - WordPress oEmbed Tricks | WP-Mix
tutorials snippets code WordPress PHP JavaScript CSS HTML htaccess HTTP
Goto Site
https://wp-mix.com/wordpress-oembed-tricks/
Site Description
Ahh yeah, here are some sweet little code snippets to customize the default WordPress oEmbed functionality. Techniques include modifying default oEmbed...
Example Site Content
WordPress oEmbed Tricks | WP-Mix WP-Mix A fresh mix of code snippets and tutorials WordPress PHP JavaScript CSS HTML .htaccess HTTP Misc. WordPress oEmbed Tricks Author: Jeff Starr Category: WordPress Updated: August 18, 2017 Ahh yeah, here are some sweet little code snippets to customize the default WordPress oEmbed functionality. Techniques include modifying default oEmbed size, markup, as well as enabling oEmbed for Post Excerpts and Custom Fields. Customize oEmbed video size This snippet hooks into embed_defaults and sets the video size to 600×450. Add to functions.php or via plugin. // Customize oEmbed video size function shapeSpace_oembed_size() { return array('width' => 600, 'height' => 450); } add_filter('embed_defaults', 'shapeSpace_oembed_size'); You can set the width and height values to whatever is required. You can also set the video width using the $content_width global variable: function shapeSpace_content_width() { $GLOBALS['content_width'] = 600; // px } add_action('after_setup_theme', 'shapeSpace_content_width', 0); Or more simply: if (!isset($content_width)) $content_width = 600; // px Adding either of those snippets to functions.php would set the default content width to 600px, which would be used as the width for oEmbed videos, among other things. Customize oEmbed markup Here we are customizing the default oEmbed markup by wrapping it with a <div> classed with .oembed. Add to functions.php or via plugin. // Customize oEmbed markup function shapeSpace_oembed_html($html, $url, $attr, $post_id) { return '<div class="oembed">'. $html .'</div>'; } add_filter('embed_oembed_html', 'shapeSpace_oembed_html', 99, 4); You can change the markup to whatever is required, and/or customize the $html variable as desired. Enable oEmbed on Post Excerpts By default WordPress does not filter Post Excerpts with oEmbed. To enable it, you can add the following snippet to your theme’s functions file, or add via simple custom plugin. // Enable oEmbed on Post Excerpts add_filter('the_excerpt', array($GLOBALS['wp_embed'], 'autoembed'), 9); Nothing else to do here, just plug-&-play and done. Enable oEmbed on Custom Fields By default WordPress does not filter Custom Fields with oEmbed. To enable it, you can add the following snippet to your theme’s functions file or add via plugin: // Enable oEmbed on Custom Fields add_filter('get_post_metadata', array($GLOBALS['wp_embed'], 'autoembed'), 9); You may notice a pattern with these last two snippets, and as you may suspect the same basic technique can be applied to other areas of WordPress to enable oEmbed functionality. Good times. Learn more ‹ WordPress Fix Image Upload Errors PHP Stringify Formatted Text › WordPress Resources Subscribe to WP-Mix Your Email Your Name Project Demos Background Slideshow Responsive Image Gallery Responsive Image Slider Responsive Video Slider Simple Ajax Chat Demo Video Background Popular Posts Redirect HTTP to HTTPS PHP Get Absolute Path, Document Root, Base URL Disable caching with .htaccess Replace all instances of a string in WordPress Display category name in WordPress Disable caching with HTML Create .htaccess files on OS X and Windows View all most popular › Recent Posts SMS Text API ServicesFix "Function Not Found" Error in WordPress Must-Use PluginsWhitelist File Names via Apache/.htaccess Random Posts Center div Download large files via SSH Reset password via SQL RSS Feed Grab the RSS Feed › 1576 readersFeed Statistics About the Author Jeff Starr is a professional developer, designer, author, and publisher with over 15 years of experience. He writes books and tutorials, develops plugins, and runs his own business. About the Site WP-Mix is where I share code snippets, tricks, and tips. WP-Mix was launched in October 2012, and now features 414 posts. You can check out the latest post published on Aug 29, 2024. Learn more › Contact A few ways to connect: Jeff Starr on Twitter Jeff Starr on Facebook WP-Mix on Facebook Contact WP-Mix © 2012–2024 Monzilla Media ★ shapeSpace ★ Sitemap ★ Feed ★ Privacy ★ Made in the USA
Websites with similar content
-
thisiswhyimbroke.xyz
This is why im broke
-
pricemon.net
Price Monitor
-
qrcode-ai.com
Free QR Code AI Art Generator (2024) • Scanner, Link In Bio, Smart Link, Analytics, Workspace, Monkey, Tiger
-
shows.acast.com
ઈ-કોમર્સ સ્ટોર કોને કહેવાય અને WordPress નો ઉપયોગ કરીને કેવી રીતે બનાવી શકાય? - WPVaat - આપની સફર આપનો અનુભવ | Acast
-
getrector.com
We help you Reduce Costs and Erase Technical Debt | Rector - Automated Way to Instantly Upgrade and Refactor any PHP code
-
excelmaster.ai
AI Excel Bot | AI formula and VBA generator (better accuracy than ChatGPT) | ExcelMaster.ai
-
www.iheart.com
What in the Heck Are the Engineers Behind Genesis Doing about FSE with Mike McAlister - Press This WordPress Community Podcast | iHeart
-
www.smashingconf.com
SmashingConf Online Workshops — Friendly, practical workshops for designers and web developers — Online Workshops
-
www.mamp.info
MAMP & MAMP PRO - your local web development solution for PHP and WordPress development
-
wenews.cc
Wenews - Micro News - Daily News pickup
-
netgeninus.com
NetGeninus - Helps you making money, making wealth, creating an strategy