Optimize Search Results

// 1. Exclude pages from search results function exclude_pages_from_search($query) { if (!is_admin() && $query->is_search && $query->is_main_query()) { $query->set(‘post_type’, ‘post’); } return $query; } add_action(‘pre_get_posts’, ‘exclude_pages_from_search’); // 2. Search only titles and excerpts (exclude post content) function search_title_excerpt_only($search, $wp_query) { global…Continue reading

Plain Upcoming Events List Shortcode

/** * Bare, theme-friendly list of upcoming events. * * The Events List block bakes in an title and calendar icons and is hard * to restyle. This snippet adds a shortcode that outputs a plain, one-line-per * event list…Continue reading

Restrict Dashboard Access

function disable_dashboard_access() { $file = basename( $_SERVER[‘PHP_SELF’] ); if ( is_user_logged_in() && is_admin() && ! current_user_can( ‘edit_posts’ ) && $file != ‘admin-ajax.php’ ) { wp_redirect( home_url() ); exit; } } add_action( ‘init’, ‘disable_dashboard_access’ );Continue reading

Remove Optional Script

remove_action( ‘wp_footer’, ‘wpcomsh_footer_rum_js’ ); // remove frontend // remove_action( ‘admin_footer’, ‘wpcomsh_footer_rum_js’ ); // remove backendContinue reading