Code

Items deleted using the file manager are preserved in the hidden .Trash directory and will occasionally need deleting to recover disc space. Running this command from the command line occasionally can save a lot of disc space on your server: find /home/*/.trash/* -exec rm -rf {} \; You might need to adjust the path to…

Placing this in functions.php will enable automatic updates of the WordPress core, plugins and themes. /* configure automatic updates */ add_filter( ‘auto_update_core’, ‘__return_true’ ); add_filter( ‘auto_update_plugin’, ‘__return_true’ ); add_filter( ‘auto_update_theme’, ‘__return_true’ ); Changing __return_true to __return_false disables said updates. These can be further refined to limit the level of updates and include only certain plugins.…

Default date format in the Display Posts Shortcode plugin is hard coded in the plugin but it can be changed using a filter. By default the date format is (8/29/15) which is useless for countries other than the USA. The following function can be placed in the THEME/functions.php file to change the format so that…

First check for the existence of the image then display it in the content area: In the template us this: // check if the post has a Post Thumbnail assigned to it. if ( has_post_thumbnail() ) { the_post_thumbnail(); } This defaults to the Thumbnail size under Settings. Size can be set by adding sizing parameters…

The basic format for the add_filter function is: add_filter(‘pre_option_’.$option, ‘override_function_name’); Where $option is the name of the Option as found in the wp_options table of the database. This example uses a filter to update the admin_email set in Options to that of the current user, so ‘admin_email’ becomes ‘pre_option_admin_email’. add_filter(‘pre_option_admin_email’, ‘override_option_admin_email’); function override_option_admin_email() { global…

This function returns the user role by name rather than by capabilities which is useful for determining whether the current user is a Wholesale customer for instance. It can also return the name of the user role given the user ID as a parameter. /** * Checks if a particular user has a role. *…

This is useful for non WordPress pages on a WordPress installation. Add this to the top of the page: <?php include(‘wp-load.php’); if(!current_user_can(‘editor’)) { wp_redirect( wp_login_url() ); } ?> To restrict access to admin only change “editor” to “administrator”. wp-load.php loads the WordPress functions so yo can use the current_user_can() function

Creates a link to show the previous page which works in Chrome as well as other browsers. Place the function in the : Then create a link to call the function and load the previous page: Previous Page Without the “return false” in the function the back button doesn’t work in Chrome. Recently I have…