10 Sep

Useful WordPress Code Snippets vol.1

Wordpress functions.php code

Here’s our first collection of WordPress Code Snippets which deserve a place in every WP developer’s toolbox. These are snippets of code that I myself find useful and use frequently.

Alot of the functionality from these code snippets can be done via plugins, but in the interest in keeping it simple and your installed plugin count down, it’s often better to simply paste these into your theme.  Unless stated otherwise, these snippets belong in your theme’s functions.php file.

1. Limit Max Width of Youtube Embeds

When faced with the issue of seeing Youtube videos I had embedded into a WP site were displaying with a width wider than that of the content area, I was surprised to see the maximum width for videos wasn’t in the core settings.

Drop the below snippet into your theme to overcome this problem, and define your desired maximum video width on the 2nd line ($maxw).
Read article