-
-
Save zuhra031/90d10e0527c61078e6a3803311da8aaa to your computer and use it in GitHub Desktop.
Custom Functions
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 | |
function ww_remove_version() { | |
return ''; | |
} | |
add_filter('the_generator', 'ww_remove_version'); | |
// unregister all default WP Widgets | |
function unregister_default_wp_widgets() { | |
unregister_widget('WP_Widget_Pages'); | |
unregister_widget('WP_Widget_Calendar'); | |
unregister_widget('WP_Widget_Archives'); | |
unregister_widget('WP_Widget_Links'); | |
unregister_widget('WP_Widget_Meta'); | |
unregister_widget('WP_Widget_Search'); | |
//unregister_widget('WP_Widget_Text'); | |
unregister_widget('WP_Widget_Categories'); | |
unregister_widget('WP_Widget_Recent_Posts'); | |
unregister_widget('WP_Widget_Recent_Comments'); | |
unregister_widget('WP_Widget_RSS'); | |
unregister_widget('WP_Widget_Tag_Cloud'); | |
//unregister_widget('WP_Nav_Menu_Widget'); | |
} | |
add_action('widgets_init', 'unregister_default_wp_widgets', 1); | |
/**REBRAND WP LOGIN**/ | |
function my_custom_login() { | |
echo '<link rel="stylesheet" type="text/css" href="' . get_bloginfo('template_directory') . '/path/to/custom_admin.css" />'; | |
} | |
add_action('login_head', 'my_custom_login'); | |
function new_wp_login_url() { | |
echo bloginfo('url'); | |
} | |
function new_wp_login_title() { | |
echo 'Powered by ' . get_option('blogname'); | |
} | |
add_filter('login_headerurl', 'new_wp_login_url'); | |
add_filter('login_headertitle', 'new_wp_login_title'); | |
/** END REBRAND WP LOGIN **/ | |
/**REPLACE WP LOGO**/ | |
function custom_admin_css() { | |
echo '<link rel="stylesheet" id="custom_admin" type="text/css" href="' . get_bloginfo('template_directory') . '/custom/custom_admin.css" />'; | |
} | |
add_action('admin_head','custom_admin_css'); | |
/**END REPLACE WP LOGO**/ | |
/**REPLACE FOOTER TEXT**/ | |
function filter_footer_admin() { ?> | |
Coerced by <a href="#">Secret Stache Media</a> | Built with <a href="http://wordpress.org">WordPress</a> and <a href="http://diythemes.com">Thesis</a> | |
<?php } | |
add_filter('admin_footer_text', 'filter_footer_admin'); | |
/**END REPLACE FOOTER TEXT**/ | |
/**REPLACE HOWDY**/ | |
// Customize: | |
$nohowdy = "Welcome Back"; | |
// Hook in | |
if (is_admin()) { | |
add_action('init', 'ozh_nohowdy_h'); | |
add_action('admin_footer', 'ozh_nohowdy_f'); | |
} | |
// Load jQuery | |
function ozh_nohowdy_h() { | |
wp_enqueue_script('jquery'); | |
} | |
// Modify | |
function ozh_nohowdy_f() { | |
global $nohowdy; | |
echo <<<JS | |
<script type="text/javascript"> | |
//<![CDATA[ | |
var nohowdy = "$nohowdy"; | |
jQuery('#user_info p') | |
.html( | |
jQuery('#user_info p') | |
.html() | |
.replace(/Howdy/,nohowdy) | |
); | |
//]]> | |
JS; | |
} | |
/**END REPLACE HOWDY**/ | |
/** REMOVE DASHBOARD WIDGETS **/ | |
function remove_dashboard_widgets() { | |
global $wp_meta_boxes; | |
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); | |
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); | |
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); | |
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); | |
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); | |
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']); | |
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); | |
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); | |
remove_action( 'wp_version_check', 'wp_version_check' ); | |
remove_action( 'admin_init', '_maybe_update_core' ); | |
add_filter( 'pre_transient_update_core', create_function( '$a', "return null;" ) ); | |
} | |
add_action('wp_dashboard_setup', 'remove_dashboard_widgets' ); | |
/** END REMOVE DASHBOARD WIDGETS **/ | |
/** INSERT CUSTOM DASHBOARD WIDGETS **/ | |
function tutorial_dashboard() { | |
?> | |
<h4>Adding Images</h4> | |
<p>From the Post or Page Edit Screen look for the Icons to the right of "Upload/Insert." Click on the first Icon and follow the instructions on screen</p> | |
<h4>Adding Gallery Images</h4> | |
<p><a href="#">Adding Gallery Video Tutorial</a> | |
<h4>Cheat Sheats</h4> | |
<p><a href="#">Download</a> a Hard Copy of the WordPress Cheat Sheat</p> | |
<?php } | |
function tutorial_dashboard_setup() { | |
wp_add_dashboard_widget( 'tutorial_dashboard', __( 'Tutorial Dashboard Title' ), 'tutorial_dashboard' ); | |
} | |
add_action('wp_dashboard_setup', 'tutorial_dashboard_setup'); | |
/** END INSERT CUSTOM DASHBOARD WIDGETS **/ | |
// QR CODE | |
<img src="http://api.qrserver.com/v1/create-qr-code/?size=100x100&data=<?php the_permalink(); ?>" alt="QR: | |
<?php the_title(); ?>"/> | |
<?php | |
//Remove links manager admin menu | |
add_action( 'admin_menu', 'remove_links_menu' ); | |
function remove_links_menu() { | |
remove_menu_page('link-manager.php'); | |
} | |
//Add this code snippet to your single.php or within the loop of your theme. This will display a text field and when clicked becomes selected for easy copy and paste. | |
<?php if (function_exists('wp_get_shortlink')) { ?> | |
<div><span class="post-shortlink">Shortlink: | |
<input type='text' value='<?php echo wp_get_shortlink(get_the_ID()); ?>' onclick='this.focus(); this.select();' /> | |
</span></div> | |
<?php } ?> | |
//Removes the version string (?ver=) from scripts and stylesheets. | |
function rssv_scripts() { | |
global $wp_scripts; | |
if ( !is_a( $wp_scripts, 'WP_Scripts' ) ) | |
return; | |
foreach ( $wp_scripts->registered as $handle => $script ) | |
$wp_scripts->registered[$handle]->ver = null; | |
} | |
function rssv_styles() { | |
global $wp_styles; | |
if ( !is_a( $wp_styles, 'WP_Styles' ) ) | |
return; | |
foreach ( $wp_styles->registered as $handle => $style ) | |
$wp_styles->registered[$handle]->ver = null; | |
} | |
add_action( 'wp_print_scripts', 'rssv_scripts', 100 ); | |
add_action( 'wp_print_footer_scripts', 'rssv_scripts', 100 ); | |
add_action( 'admin_print_styles', 'rssv_styles', 100 ); | |
add_action( 'wp_print_styles', 'rssv_styles', 100 ); | |
//eof | |
// add custom post content | |
function add_post_content($content) { | |
if(!is_feed() && !is_home()) { | |
$content .= '<p>This article is copyright © '.date('Y').' '.bloginfo('name').'</p>'; | |
} | |
return $content; | |
} | |
add_filter('the_content', 'add_post_content'); | |
// add custom feed content | |
function add_feed_content($content) { | |
if(is_feed()) { | |
$content .= '<p>This article is copyright © '.date('Y').' '.bloginfo('name').'</p>'; | |
} | |
return $content; | |
} | |
add_filter('the_excerpt_rss', 'add_feed_content'); | |
add_filter('the_content', 'add_feed_content'); | |
/* add custom content to feeds and posts | |
function add_custom_content($content) { | |
if(!is_home()) { | |
$content .= '<p>This article is copyright © '.date('Y').' '.bloginfo('name').'</p>'; | |
} | |
return $content; | |
} | |
add_filter('the_excerpt_rss', 'add_custom_content'); | |
add_filter('the_content', 'add_custom_content'); */ | |
// remove version info from head and feeds | |
function complete_version_removal() { | |
return ''; | |
} | |
add_filter('the_generator', 'complete_version_removal'); | |
// customize admin footer text | |
function custom_admin_footer() { | |
echo '<a href="http://monzilla.biz/">Website Design by Monzilla Media</a>'; | |
} | |
add_filter('admin_footer_text', 'custom_admin_footer'); | |
// enable html markup in user profiles | |
remove_filter('pre_user_description', 'wp_filter_kses'); | |
// delay feed update | |
function publish_later_on_feed($where) { | |
global $wpdb; | |
if (is_feed()) { | |
// timestamp in WP-format | |
$now = gmdate('Y-m-d H:i:s'); | |
// value for wait; + device | |
$wait = '5'; // integer | |
// http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff | |
$device = 'MINUTE'; // MINUTE, HOUR, DAY, WEEK, MONTH, YEAR | |
// add SQL-sytax to default $where | |
$where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait "; | |
} | |
return $where; | |
} | |
add_filter('posts_where', 'publish_later_on_feed'); | |
// admin link for all settings | |
function all_settings_link() { | |
add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php'); | |
} | |
add_action('admin_menu', 'all_settings_link'); | |
// 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'); | |
add_filter ('comment_reply_link', 'xwp_dofollow'); | |
add_filter ('comment_text', 'xwp_dofollow'); | |
// count words in posts | |
function word_count() { | |
global $post; | |
echo str_word_count($post->post_content); | |
} | |
// spam & delete links for all versions of wordpress | |
function delete_comment_link($id) { | |
if (current_user_can('edit_post')) { | |
echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&c='.$id.'">del</a> '; | |
echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&dt=spam&c='.$id.'">spam</a>'; | |
} | |
} | |
/* disable all feeds | |
function fb_disable_feed() { | |
wp_die(__('<h1>Feed not available, please visit our <a href="'.get_bloginfo('url').'">Home Page</a>!</h1>')); | |
} | |
add_action('do_feed', 'fb_disable_feed', 1); | |
add_action('do_feed_rdf', 'fb_disable_feed', 1); | |
add_action('do_feed_rss', 'fb_disable_feed', 1); | |
add_action('do_feed_rss2', 'fb_disable_feed', 1); | |
add_action('do_feed_atom', 'fb_disable_feed', 1); */ | |
// customize default gravatars | |
function custom_gravatars($avatar_defaults) { | |
// change the default gravatar | |
$customGravatar1 = get_bloginfo('template_directory').'/images/gravatar-01.png'; | |
$avatar_defaults[$customGravatar1] = 'Default'; | |
// add a custom user gravatar | |
$customGravatar2 = get_bloginfo('template_directory').'/images/gravatar-02.png'; | |
$avatar_defaults[$customGravatar2] = 'Custom Gravatar'; | |
// add another custom gravatar | |
$customGravatar3 = get_bloginfo('template_directory').'/images/gravatar-03.png'; | |
$avatar_defaults[$customGravatar3] = 'Custom gravatar'; | |
return $avatar_defaults; | |
} | |
add_filter('avatar_defaults', 'custom_gravatars'); | |
// disable auto formatting in posts | |
function my_formatter($content) { | |
$new_content = ''; | |
$pattern_full = '{(\[raw\].*?\[/raw\])}is'; | |
$pattern_contents = '{\[raw\](.*?)\[/raw\]}is'; | |
$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE); | |
foreach ($pieces as $piece) { | |
if (preg_match($pattern_contents, $piece, $matches)) { | |
$new_content .= $matches[1]; | |
} else { | |
$new_content .= wptexturize(wpautop($piece)); | |
} | |
} | |
return $new_content; | |
} | |
remove_filter('the_content', 'wpautop'); | |
remove_filter('the_content', 'wptexturize'); | |
add_filter('the_content', 'my_formatter', 99); | |
// escape html entities in comments | |
function encode_code_in_comment($source) { | |
$encoded = preg_replace_callback('/<code>(.*?)<\/code>/ims', | |
create_function('$matches', '$matches[1] = preg_replace(array("/^[\r|\n]+/i", "/[\r|\n]+$/i"), "", $matches[1]); | |
return "<code>" . htmlentities($matches[1]) . "</"."code>";'), $source); | |
if ($encoded) | |
return $encoded; | |
else | |
return $source; | |
} | |
add_filter('pre_comment_content', 'encode_code_in_comment'); | |
// custom comments callback function | |
function custom_comments_callback($comment, $args, $depth) { | |
$GLOBALS['comment'] = $comment; ?> | |
<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>"> | |
<div class="comment-wrap"> | |
<?php echo get_avatar(get_comment_author_email(), $size = '50', $default = bloginfo('stylesheet_directory').'/images/gravatar.png'); ?> | |
<div class="comment-intro"> | |
<?php printf(__('%s'), get_comment_author_link()); ?> – <a class="comment-permalink" href="<?php echo htmlspecialchars(get_comment_link($comment->comment_ID)); ?>"><?php comment_date('F j, Y'); ?> @ <?php comment_time(); ?></a><?php edit_comment_link('Edit', ' – ', ''); ?> | |
</div> | |
<?php if ($comment->comment_approved == '0') : ?> | |
<p class="comment-moderation"><?php _e('Your comment is awaiting moderation.'); ?></p> | |
<?php endif; ?> | |
<div class="comment-text"><?php comment_text(); ?></div> | |
<div class="reply" id="comment-reply-<?php comment_ID(); ?>"> | |
<?php comment_reply_link(array_merge($args, array('reply_text'=>'Reply', 'login_text'=>'Log in to Reply', 'add_below'=>'comment-reply', 'depth'=>$depth, 'max_depth'=>$args['max_depth']))); ?> | |
</div> | |
</div> | |
<?php } // WP adds the closing </li> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment