Skip to content

Instantly share code, notes, and snippets.

@ovizii
ovizii / functions.php
Created August 15, 2013 10:24
Remove author URL from comment form
add_filter('comment_form_default_fields', 'unset_url_field');
function unset_url_field($fields){
if(isset($fields['url']))
unset($fields['url']);
return $fields;
}
@ovizii
ovizii / functions.php
Created August 15, 2013 10:36
Check post age
function is_old_post($days = 5) {
$days = (int) $days;
$offset = $days*60*60*24;
if ( get_post_time() < date('U') - $offset )
return true;
return false;
}
//To be included in the loop
if ( is_old_post(10) ) {
@ovizii
ovizii / single.php
Created August 15, 2013 10:38
Ceate edit post link
<?php edit_post_link(__('Edit This')); ?>
@ovizii
ovizii / footer.php
Last active January 7, 2018 22:49
Copyright year updated automatically
@ovizii
ovizii / anywhere.php
Created August 15, 2013 10:39
Display avatars of all logged-in users
<?php
global $current_user;
get_currentuserinfo();
echo get_avatar( $current_user->ID, 64 );
?>
@ovizii
ovizii / search.php
Created August 15, 2013 10:41
Highlight search terms on results page
//To highlight the term that was searched in search results, open up search.php and replace the_title(); with echo $title;. Above this line add the following code.
<?php
$title = get_the_title();
$keys= explode(" ",$s);
$title = preg_replace('/('.implode('|', $keys) .')/iu',
'<strong class="search-excerpt">�</strong>',
$title);
?>
@ovizii
ovizii / functions.php
Created August 15, 2013 10:42
Remove noffollow from specific comment fields
// remove nofollow from comments
function xwp_dofollow($str) {
$str = preg_replace(
'~<a ([^>]*)s*(["|']{1}w*)s*nofollow([^>]*)>~U',
'<a ${1}${2}${3}>', $str);
return str_replace(array(' rel=""', " rel=''"), '', $str);
}
remove_filter('pre_comment_content', 'wp_rel_nofollow');
add_filter ('get_comment_author_link', 'xwp_dofollow');
add_filter ('post_comments_link', 'xwp_dofollow');
@ovizii
ovizii / functions.php
Created August 15, 2013 10:43
Insert custom content after each post
// add custom post content
function add_post_content($content) {
if(!is_feed() && !is_home()) {
$content .= '<p>This article is copyright &copy; '.date('Y').'&nbsp;'.bloginfo('name').'</p>';
}
return $content;
}
add_filter('the_content', 'add_post_content');
@ovizii
ovizii / functions.php
Created August 15, 2013 10:44
Insert custom content into feed
// add custom feed content
function add_feed_content($content) {
if(is_feed()) {
$content .= '<p>This article is copyright &copy; '.date('Y').'&nbsp;'.bloginfo('name').'</p>';
}
return $content;
}
add_filter('the_excerpt_rss', 'add_feed_content');
add_filter('the_content', 'add_feed_content');
@ovizii
ovizii / functions.php
Created August 15, 2013 10:44
Remove or disable the wordpress admin bar
remove_action('init', 'wp_admin_bar_init');
OR
show_admin_bar(false);