Add action hook conditionally – only when home.php in use

Use is_home instead, as is_page_template will not work for home.php as its technically not a page template in the traditional sense. add_action(‘template_redirect’, ‘are_we_home_yet’, 10); function are_we_home_yet(){ if ( is_home() ) { //your logic here } } Revised: add_action(‘template_redirect’, ‘are_we_home_yet’, 10); function are_we_home_yet(){ global $template; $template_file = basename((__FILE__).$template); if ( is_home() && $template_file=”home.php” ) { //do … Read more

Extending auth_cookie_expiration based on user role

Untested, but the following should only change the expiration time for admins who select ‘remember me’. function wpse108399_change_cookie_logout( $expiration, $user_id, $remember ){ if( $remember && user_can( $user_id, ‘manage_options’ ) ){ $expiration = 60;// yes, I know this is 1 minute } return $expiration; } add_filter( ‘auth_cookie_expiration’,’wpse108399_change_cookie_logout’, 10, 3 );

Refresh page after form action

Searching around and not being able to implement the action through init hook I’ve found this workaround which for sure isn’t the best but does the job nicely. echo “<script type=”text/javascript”> window.location=document.location.href; </script>”; at the end of $_POST instructions. If somebody has a better solution, welcome to share.

Create a global variable for use in all templates

You’ll also have to fill the variable, e.g. function userinfo_global() { global $users_info; $users_info = wp_get_current_user(); } add_action( ‘init’, ‘userinfo_global’ ); And you should then be able to use $users_info everywhere in global context. Keep in mind that some template pars (header.php, footer.php, those used via get_template_part) are not in global scope by default, so … Read more

How to publish a post with empty title and empty content?

If the post content, title and excerpt are empty WordPress will prevent the insertion of the post. You can trick WordPress by first filtering the input array so empty values are set to something else, and then later resetting these values back to empty strings. This will bypass the standard check. add_filter(‘pre_post_title’, ‘wpse28021_mask_empty’); add_filter(‘pre_post_content’, ‘wpse28021_mask_empty’); … Read more