Programmatically Set First Image as Featured

Regarding the code you posted, I would say some things: you can avoid using 6 different actions because one is enough: ‘save_post’ is triggered everytime a post is created or updated you can drop globalize $post: ‘save_post’ will pass the post id, you can use it, in addition, preparing the function to receive an argument … Read more

Remove Comments Metabox but still allow comments

Don’t remove this via CSS. The _POST part is also active and WP save the data! Use the hooks to remove meta boxes; code by scratch. function fb_remove_comments_meta_boxes() { remove_meta_box( ‘commentstatusdiv’, ‘post’, ‘normal’ ); remove_meta_box( ‘commentstatusdiv’, ‘page’, ‘normal’ ); // remove trackbacks remove_meta_box( ‘trackbacksdiv’, ‘post’, ‘normal’ ); remove_meta_box( ‘trackbacksdiv’, ‘page’, ‘normal’ ); } add_action( ‘admin_init’, … Read more

How to add first name & last name to default registration form?

Add this code in functions.php add_action( ‘register_form’, ‘myplugin_register_form’ ); function myplugin_register_form() { $first_name = ( ! empty( $_POST[‘first_name’] ) ) ? trim( $_POST[‘first_name’] ) : ”; $last_name = ( ! empty( $_POST[‘last_name’] ) ) ? trim( $_POST[‘last_name’] ) : ”; ?> <p> <label for=”first_name”><?php _e( ‘First Name’, ‘mydomain’ ) ?><br /> <input type=”text” name=”first_name” id=”first_name” … Read more

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 . ‘&amp;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 . ‘&amp;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; }