Created
September 11, 2015 08:41
-
-
Save shizhua/f2c656496c5d1252cadf to your computer and use it in GitHub Desktop.
Useful WordPress Snippets
This file contains 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
<?php | |
/**** | |
* Automatic Linking to Twitter Usernames within a post | |
****/ | |
function content_twitter_mention($content) { | |
return preg_replace('/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/', "$1@$2", $content); | |
} | |
add_filter('the_content', 'content_twitter_mention'); | |
add_filter('comment_text', 'content_twitter_mention'); | |
/**** | |
* Redirect New Registered Users to a Specific Page | |
****/ | |
function wps_registration_redirect(){ | |
return home_url( '/finished/' ); | |
} | |
add_filter( 'registration_redirect', 'wps_registration_redirect' ); | |
/**** | |
* Show a Post Date and Modified Date | |
****/ | |
$u_time = get_the_time('U'); | |
$u_modified_time = get_the_modified_time('U'); | |
if ($u_modified_time != $u_time) { | |
echo "Last modified on "; | |
the_modified_time('F jS, Y'); | |
echo ". "; | |
} | |
/**** | |
* Remove the Comment URL Field | |
****/ | |
function remove_comment_fields($fields) { | |
unset($fields['url']); | |
return $fields; | |
} | |
add_filter('comment_form_default_fields','remove_comment_fields'); | |
/**** | |
* Show X Results on the Search Results Page | |
****/ | |
function limit_posts_per_search_page() { | |
if ( is_search() ) | |
set_query_var('posts_per_archive_page', 20); | |
} | |
add_filter('pre_get_posts', 'limit_posts_per_search_page'); | |
/**** | |
* | |
****/ | |
/**** | |
* | |
****/ | |
/**** | |
* | |
****/ | |
/**** | |
* | |
****/ | |
/**** | |
* | |
****/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment