Created
January 23, 2018 19:48
-
-
Save SkaTeMasTer/91298ed7c59c21ea233743be6c123cb7 to your computer and use it in GitHub Desktop.
Wordpress hacks...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Redirect to Post If Search Results Return One Post | |
add_action('template_redirect', 'redirect_single_post'); | |
function redirect_single_post() { | |
if (is_search()) { | |
global $wp_query; | |
if ($wp_query->post_count == 1 && $wp_query->max_num_pages == 1) { | |
wp_redirect( get_permalink( $wp_query->posts['0']->ID ) ); | |
exit; | |
} | |
} | |
} | |
// Exclude Pages from WordPress Search Results | |
function filter_search($query) { | |
if ($query->is_search) { | |
$query->set('post_type', 'post'); | |
} | |
return $query; | |
} | |
add_filter('pre_get_posts', 'filter_search'); | |
// Remove the URL Field From Your Comment Form | |
function remove_comment_fields($fields) { | |
unset($fields['url']); | |
return $fields; | |
} | |
add_filter('comment_form_default_fields','remove_comment_fields'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment