Skip to content

Instantly share code, notes, and snippets.

@shizhua
Created September 11, 2015 08:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shizhua/f2c656496c5d1252cadf to your computer and use it in GitHub Desktop.
Save shizhua/f2c656496c5d1252cadf to your computer and use it in GitHub Desktop.
Useful WordPress Snippets
<?php
/****
* Automatic Linking to Twitter Usernames within a post
****/
function content_twitter_mention($content) {
return preg_replace('/([^a-zA-Z0-9-_&amp;])@([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