I’m wondering how I’d be able to set a custom field within my WordPress posts. I want to have a field available to add an image via the Post dashboard – that has a max width & max height set, I want the image to always float to the left within the posts (Text wrapping around via the right).
Can anyone recommend a plugin for this, or the PHP snippet that I could include to do so (I could add to single.php or functions.php, right?)
Thanks as always!
You should use the post thumbnail feature. Add support for this feature with this line in your functions.php file:
You can also set a new thumbnail size that will be cropped on new added photos to use this in your theme. Add this code to set a new thumbnail size (also in the functions.php file):
The code above crops the picture to fit exact into 500×300 pixel. to let the width and heigh to be fluid (with a max width of 500 and a max height of 300) set the true property to
false
.Finally add the thumbnail to the theme at the location you want. With this code:
That’s it 🙂 you enabled and customized a post thumbnail pictured! Hope this works for you 🙂
Edit
Adding a couple suggestions/best practices:
First, be sure to put the
functions.php
code inside a callback, hooked in appropriately; e.g.:Second, wrap the template call in a conditional, and output the fully-formed HTML for the image:
(I would also recommend using a unique slug for the custom image size, such as
theme-slug-large-feature', where
theme-slugis the *slug* of your Theme name. Note that I also used
theme_slugas a unique prefix for the
functions.php` callback function.)