wordpress snippets last updated   : October 6, 2014
we now have 641 snippets

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

Display external files in posts using shortcode

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will allow you to include the content of an external file within your page using shortcode.

read more

Prevent direct file access to functions.php

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will prevent direct file access to the functions.php file via the URL “http://wpsnipp.com/wp-content/themes/themename/functions.php” Great snippet from Pete over at swisswp.

read more

List all unattached files in media library

wordpress snippet

Adding the first snippet to the functions.php of your wordpress theme then add the second snippet into your wordpress template. Once added this snippet will display thumbnails of unattached image files and links to other file types.

read more