Run functions only in the admin area?

There is very little overhead to assigning couple of filters on hooks that simply won’t fire on front end. In general it would be something like this: add_action(‘init’, ‘admin_only’); function admin_only() { if( !is_admin() ) return; // filter assignemnts and such go here } Also create_function() is not recommended for performance and some other reasons. … Read more

How to paginate the get_users function?

First get the total number of users: $total_users = count_users(); //var_dump($total_users); //for debugging purpose $total_users = $total_users[‘total_users’]; and the current page: $paged = get_query_var(‘paged’); Set a variable that will decide how many users to display per page: $number = 20; // ie. 20 users page page Then, in your $args array add the offset if … Read more

Logout redirect to current page – function

Using this code in the functions.php does the trick: function wpse_44020_logout_redirect( $logouturl, $redir ) { return $logouturl . ‘&redirect_to=’ . get_permalink(); } add_filter( ‘logout_url’, ‘wpse_44020_logout_redirect’, 10, 2 ); Note – The above code works only on non-admin pages. To make this work on any page you should replace: return $logouturl . ‘&redirect_to=’ . get_permalink(); With: … Read more

Disable visual editor on one specific page

In your code, calling the action admin_init makes is_admin() unnecessary. And, if not mistaken, is_page() is meant to be used in the front-end… But the solution is the following (based on this Answer): add_filter( ‘user_can_richedit’, ‘wpse_58501_page_can_richedit’ ); function wpse_58501_page_can_richedit( $can ) { global $post; if ( 28 == $post->ID ) return false; return $can; }

disable WP automatically inserted line breaks after an image

If this is how it looks: <img class=”alignleft size-medium wp-image-8530″ alt=”…” src=”#” width=”413″ height=”275″ /> <img class=”alignleft size-medium wp-image-8529″ alt=”…” src=”#” width=”413″ height=”275″ /> Then you have to put them together like this: <img class=”alignleft size-medium wp-image-8530″ alt=”…” src=”#” width=”413″ height=”275″ /><img class=”alignleft size-medium wp-image-8529″ alt=”…” src=”#” width=”413″ height=”275″ /> Because if you do this … Read more

How to get the image EXIF date/time and use it for the WP post date/time

PHP has a function for this purpose: exif_read_data I used this image for testing. Try this code for your purpose: add_action( ‘add_attachment’, ‘create_post_from_image’ ); function create_post_from_image( $id ) { if ( wp_attachment_is_image( $id ) ) { $image = get_post( $id ); // Get image height/width for auto inserting the image later @list( $width, $height ) … Read more

get_term_by not working when in functions.php

This is probably happening because the taxonomy you’re trying to query is registered yet. Eg. The WordPress environment is loaded when a theme’s functions.php file loads, but many plugins/themes/core functions don’t register taxonomies until later. Try hooking into init with a really high priority number and running the get_term_by function. Like so: <?php add_action( ‘init’, … Read more

Edit tag cloud widget number

Add the following to your theme’s function.php. Default values are shown below, except changing ‘number’ from 45 to 15. Only the changed values need to be included, so you can either leave the default values or remove/comment out those lines. For WordPress Tag Cloud widget: function custom_tag_cloud_widget() { $args = array( ‘smallest’ => 8, ‘largest’ … Read more