Modifying Size Of Embedded Videos
Simply paste the following snippet on your functions.php file and you will be able to modify the size of embedded videos as per your requirements.
1 2 3 4 5 6 7 8 9 10 11 |
function mycustom_embed_defaults($embed_size){ $embed_size['width'] = 586; // Adjust values to your needs $embed_size['height'] = 500; return $embed_size; } add_filter('embed_defaults', 'mycustom_embed_defaults'); |
Snippet Source/Credit: Shailan
How To Automatically Delete Trash On Daily Basis
When you delete a post or a page or a comment, it goes in a Trash instead of being removed permanently. Using the following snippet will ease you job of deletion and will tell WordPress to automatically delete the trash itself. Simply copy and paste the following lines of code in your wp-config,php file and you are done.
1 |
define('EMPTY_TRASH_DAYS', 1); |
Note: Make sure that you do replace 1 by X to empty spam comments automatically every X days.
How To Remove WordPress Version Number
WordPress, by default, publicly display its version number in both its RSS and Atom feeds. Well, while using the snippet, you will be able to remove it. Simply paste the following snippet in your functions.php file and you will be able to remove WordPress version number.
1 2 3 4 5 6 7 |
add_filter('the_generator', 'digwp_complete_version_removal'); function digwp_complete_version_removal() { return ''; } |
Snippet Source/Credit: Jeff Starr
How To Execute Shortcodes Inside Custom Fields
WordPress, by default, don’t allow shortcodes to be executed inside custom fields. While, if in case, you want to do it so, then this can be done by using the following snippet below. Simply paste the snippet to the page where you wish to display the results of the shortcode. While doing this, make sure you do change your_custom_field_here to the name of your selected custom field.
1 |
<?php echo apply_filters('the_content', get_post_meta($post->ID, 'your_custom_field_here', true)); ?> |
Snippet Source/Credit: Snipplr
Securing Your WordPress Blog Uploads Directory
Although WordPress is a very secure system one actually thinks of BUT since there is always a room open for more improvement, using the following snippet will let you secure your WordPress blog uploads directory.
To do so, first of all, create a file named .htaccess and paste the following code in it. Once you created it, upload the same into your wp-content/uploads directory. Remember at line 5 in the snippet below; make sure to add/update all the extensions you want to make it work for you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<Files ~ ".*..*"> Order Allow,Deny Deny from all </Files> <FilesMatch ".(jpg|jpeg|jpe|gif|png|tif|tiff)$"> Order Deny,Allow Allow from all </FilesMatch> |
Snippet Source/Credit: Jeff Starr
How To Easily Get Post Content By ID
Using the following snippet will let you easily get post content by ID. All you have to do is to simply use the get_post_field() function to get the post content and you are done.
1 |
echo get_post_field('post_content', $post_id); |
How To Embed A Page Into Another Page In Your WordPress Blog
Using the following snippet, you will be able to embed a page into another page in your WordPress blog.
1 2 3 4 5 6 7 |
<?php $recent = new WP_Query("page_id=**ID**"); while($recent->have_posts()) : $recent->the_post();?> <h3><?php the_title(); ?></h3> <?php the_content(); ?> <?php endwhile; ?> |
Snippet Source/Credit: CSS Tricks