wordpress snippets last updated   : April 14, 2014
we now have 630 snippets
category attachment

Upload user-submitted files from the frontend

wordpress snippet

There are many use cases for allowing users to upload files from the frontend, but the trick is making sure the file is uploaded and saved in the WordPress media library correctly. You can easily use standard PHP functions to handle the upload and then store the file wherever you like, but then you won’t be able to take advantage of the attachment system that WordPress uses. An image that is uploaded correctly, for example, will have all the various sizes available as well as the meta data, such as title, description and caption. You will also be able to edit all of this from the media library in your WordPress dashboard.

read more

Require a featured image before you can publish post

wordpress snippet
require-featured-image-can-publish-post

    If you would like to require that all posts have a featured image before they can be published add this snippet to the functions.php of your wordpress theme. When you try and publish a post without a featured image you get an admin message “You must select Featured Image. Your Post is saved but it can not be published.” Great way to ensure all your posts have a featured image before they are publish.

    read more

    Attach PDF files to post with custom metabox file selection

    wordpress snippet

    Adding this snippet to the functions.php of your wordpress theme will create a new metabox within your post editing screen with a select menu listing all PDF files. Adding the second snippet in your wordpress template in the location you wish to display the files URL.

    read more

    Display attachment thumbnail with image metadata

    wordpress snippet

    Adding this snippet within the loop of your index.php template file will display a list of all post attachments with the following metadata (Credit, Camera, Focal Length, Aperture, ISO, Shutter Speed, Time Stamp, Copyright).

    read more

    Remove unneeded images / thumbnail sizes

    wordpress snippet

    Adding some or all of these lines of code to the functions.php of your wordpress theme will effectively remove some of the default images sizes that may be unneeded. Make sure to include both the _w _h for width and height,

    read more

    Media library admin columns with attachment id

    wordpress snippet

    Adding this snippet to the functions.php of your wordpress theme will add a new column within the media library admin columns with the attachment id.

    read more
    jqsnipp.com | we just launched jquery snippets website