This entry is part 3 of 9 in the Plugin Thoughts Series
- Plugin Thoughts Episode 1: Making Your Plugins More Extensible
- Plugin Thoughts Episode Two – Use Filters for Plugin Text
- Plugin Thoughts Episode 3 – Don’t Forget About Core Functions
- Plugin Thoughts Episode 4 – Learn How Core Does It
- Plugin Thoughts Episode 5 – Take Responsibility for Your Products
- Plugin Thoughts Episode 6 – Contribute to the WordPress Codex
- Plugin Thoughts Episode 7 – Remember Core CSS
- Plugin Thoughts Episode 8 – Create Clean Code
- Plugin Thoughts Episode 9 – Write Better Code; Release Better Plugins
When developing for WordPress, both in themes and plugins, do not forget that many, many core functions exist and that it is not always necessary (or wise) to write your own custom methods. Most core functions have actions and filters included, so when you write your own function to replace the one in core, these filters and actions are often excluded, which results in other developers not being able to use the filters and actions when also using your plugin or theme.
This episode is a direct result of my experience while working with a theme (mentioned in the video) that has a custom function for displaying featured post thumbnails. I was attempting to modify the HTML of the featured thumbnail, though the core post_thumbnail_html filter, but since the theme used its own custom function, which did not include this filter, my filter function was useless.
Nicely done. I normally don’t sit though all of these video. This one was interesting to see the solution was simple and really it was made that way by looking at the core. WWCD?
c.
Thanks. Keeping WWCD (What Would Core DO) in mind during development of both themes and plugins will definitely result in fewer headaches in the end, for everyone involved.
Very educatieve video, something to keep in mind, Thanks for sharing!
After watching your video, it took me back to when I was creating the function and believe it or not, I did actually have a reason for doing that (which is now kind of irrelevant). I am aware of get_the_post_thumbnail obvously but chose not to use it. And trust me, it would have much easier to use that function, but then I was going to have also create an additional function that filtered WordPress’s thumbnail markup in some hacky way to accomplish what I needed. Let me explain.
When you use get_the_post_thumbnail the HTML WordPress returns has the width/height of the image hardcoded in there. And with that, it screwed with the responsive design of the theme. If you notice, all images in the theme will compress down when you make your site smaller. This is possible because of this in my CSS:
img {
max-width:100%;
}
But this doesn’t work when you have a width/height attached to the image’s markup. However in the last month I’ve learned the simple little thing (that I probably should have known already) that I can override a width/height on the HTML markup by doing this:
img {
max-width:100%;
width:auto;
height:auto;
}
lol.. so no, I’m not anti-WordPress core, but yes, I will go ahead and make the change you’re suggesting, which is probably for the better. I probably wouldn’t have done it if it weren’t for your video, so thanks!
That makes perfect sense, and, believe me, I know you’re not anti-core 😉 AS you know I’m a huge fan of your themes.
I’ve just looked through all of the core functions for outputting images, and, sadly, there is not a filter that allows you to remove the width=”” and height=”” attributes. But another way that it could be done (instead of relying on CSS, which should work just as well), would be to modify the HTML returned by get_the_post_thumbnail() with the “post_thumbnail_html” filter. You could pretty easily strip out the height and width tags with that filter. I’m not sure if there are any negative side-effects of doing this, however.
Yea, I looked into all that when I was setting it up, and I settled on that being the option that made the most sense.
But this is a good time that you’re bringing this up. I’m currently looking to add any changes in a push to release 2.1 of the framework. So far a lot of stuff has changed for 2.1. There’s a whole new API system in place for you to make changes to sliders, layout builder, theme options, etc from your child theme with some simple functions.
This will be released with the new Jump Start project I’m not sure if you know about or not. Basically it’s going to be a simple version of the theme framework with a website dedicated to having tutorials on making child themes for it… hopefully eventually to take a run at Genesis in the coming years.
So, ya if you have any more suggestions like this, feel free to send em over!
Version 2.1 should be sweet!
I’ve heard you mention Jump Start, and it sounds great!
Some very good points here Pippin – but for developers new to WP and frankly to development for that matter – what’s the best way to ensure your 1) not reinventing the wheel and 2) not omitting/breaking core functionality?
Granted experience probably helps here – and exploring the core is good – but I just have trouble with the scope because WP is so huge.
The first thing I would do whenever you attempting to build / use some functionality or other, is to do some google searches to see if you can find existing methods for doing what you want. Let’s look at a simple example: you are building a function that sends a user an email, and in order to get their email address (let’s say you only have their user name) you have to user their user login name. You might do a google search for “Find WordPress user data from login name”. This result will lead you to the
function, which will do everything you need.
It’s really about properly researching the task at hand.
or of course I could always listen to part4 . . . doh!
Hi Pippin
Did you know that the video is now missing on this page?
Fixed!