/*
* Remove Website Field for Comment form
*/
function ar_comment_website_remove( $fields ) {
if ( isset( $fields['url'] ) ) {
unset( $fields['url'] );
}
return $fields;
}
add_filter( 'comment_form_default_fields', 'ar_comment_website_remove' );
WP
Show Custom Message After Posting Comment
/*
* Show Custom Message After post Comment.
*/
function ar_set_comment_cookies( $comment, $user ) {
setcookie( 'ta_comment_wait_approval', '1', 0, '/' );
}
add_action( 'set_comment_cookies', 'ar_set_comment_cookies', 10, 2 );
function ar_comment_sent_message() {
if ( isset( $_COOKIE['ta_comment_wait_approval'] ) && $_COOKIE['ta_comment_wait_approval'] === '1' ) {
setcookie( 'ta_comment_wait_approval', '0', 0, '/' );
function ar_show_comment_mesg() {
echo "<p id='wait_approval'><strong>Your comment has been sent successfully & Waiting for Approval.</strong></p>";
}
add_action( 'comment_form_before', 'ar_show_comment_mesg' );
}
}
add_action( 'init', 'ar_comment_sent_message' );
function ar_comment_post_redirect( $location, $comment ) {
$location = get_permalink( $comment->comment_post_ID ) . '#wait_approval';
return $location;
}
add_filter( 'comment_post_redirect', 'ar_comment_post_redirect', 10, 2 );
Add Login/Logout Link to Menu
function gl_loginout_menu_link( $items, $args ) {
if ($args->theme_location == 'primary') {
if (is_user_logged_in()) {
$items .= '<li class="right"><a href="'. wp_logout_url() .'">'. __("Log Out") .'</a></li>';
} else {
$items .= '<li class="right"><a href="'. wp_login_url(get_permalink()) .'">'. __("Log In") .'</a></li>';
}
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'gl_loginout_menu_link', 10, 2 );
Add CSS Class to Last Menu Item Anchor Tag
/*
* Add CSS Class to Last Menu Item Anchor Tag
*/
function add_specific_menu_atts( $atts, $item, $args ) {
if ( $args->menu->count == $item->menu_order && $args->theme_location == 'primary' ) {
$atts[ 'class' ] = 'btn-def';
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'add_specific_menu_atts', 10, 3 );
Disable Redux Framework Developer Mode “dev_mode”
/*
* Disable Redux Developer Mode dev_mode
*/
if ( !function_exists( 'redux_disable_dev_mode_plugin' ) ) {
function redux_disable_dev_mode_plugin( $redux ) {
if ( $redux->args[ 'opt_name' ] != 'redux_demo' ) {
$redux->args[ 'dev_mode' ] = false;
$redux->args[ 'forced_dev_mode_off' ] = false;
}
}
add_action( 'redux/construct', 'redux_disable_dev_mode_plugin' );
}
function gl_removeDemoModeLink() {
if ( class_exists( 'ReduxFrameworkPlugin' ) ) {
remove_filter( 'plugin_row_meta', array( ReduxFrameworkPlugin::get_instance(), 'plugin_metalinks' ), null, 2 );
}
if ( class_exists( 'ReduxFrameworkPlugin' ) ) {
remove_action( 'admin_notices', array( ReduxFrameworkPlugin::get_instance(), 'admin_notices' ) );
}
}
add_action( 'init', 'gl_removeDemoModeLink' );
Add “odd” “even” Class Name to “post_class”
/*
* Add "odd" "even" Class Name to "post_class"
*/
function odd_even_post_class( $classes ) {
global $oddeven_class;
$oddeven_class = ( $oddeven_class == 'odd' ) ? 'even' : 'odd';
$classes[] = $oddeven_class;
return $classes;
}
add_filter( 'post_class', 'odd_even_post_class' );
Change Upload Directory for Specific Files Types
Available Plugin GL Upload Dir
/*
* Change Upload Directory for Specific Files Type
* Only works in WordPress 3.3+
*/
function wpse47415_pre_upload( $file ) {
add_filter( 'upload_dir', 'wpse47415_custom_upload_dir' );
return $file;
}
function wpse47415_post_upload( $fileinfo ) {
remove_filter( 'upload_dir', 'wpse47415_custom_upload_dir' );
return $fileinfo;
}
function wpse47415_custom_upload_dir( $path ) {
$extension = substr( strrchr( $_POST[ 'name' ], '.' ), 1 );
if ( empty( $path[ 'error' ] ) ) {
switch ( $extension ) {
case 'pdf':
$customdir = '/pdf';
break;
case 'doc':
$customdir = '/doc';
break;
case 'zip':
$customdir = '/zip';
break;
}
} else {
return $path;
}
$path[ 'path' ] = str_replace( $path[ 'subdir' ], '', $path[ 'path' ] ); //remove default subdir (year/month)
$path[ 'url' ] = str_replace( $path[ 'subdir' ], '', $path[ 'url' ] );
$path[ 'subdir' ] = $customdir;
$path[ 'path' ] .= $customdir;
$path[ 'url' ] .= $customdir;
return $path;
}
add_filter( 'wp_handle_upload_prefilter', 'wpse47415_pre_upload' );
add_filter( 'wp_handle_upload', 'wpse47415_post_upload' );
Limit Category to 1 Category in Edit Screen.
/*
* Limit Category to 1 Category in Edit Screen.
*/
function limit_cat_to_one() {
if ( is_admin() ) {
?>
<script>
jQuery( document ).ready( function ( $ ) {
$( "#category-all input:checkbox" ).change( function () {
var max = 1;
var count = $( "#category-all input:checked" ).length;
if ( count > max ) {
$( this ).prop( "checked", "" );
alert( "You can choose " + max + " Categor" + (
max == 1 ? "y" : "ies"
) );
}
} );
} );
</script>
<?php
}
}
add_action( 'admin_head', 'limit_cat_to_one' );
Remove WordPress Dashboard Widget
To remove WordPress dashboard widgets from your site add these codes to your theme ‘functions.php’ file.
/*
* Remove WordPress Dashboard Widget
*/
function remove_dashboard_widgets() {
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' ); //Quick Press widget
remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' ); //Recent Drafts
remove_meta_box( 'dashboard_primary', 'dashboard', 'side' ); //WordPress.com Blog
remove_meta_box( 'dashboard_secondary', 'dashboard', 'side' ); //Other WordPress News
remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' ); //Incoming Links
remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' ); //Plugins
remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' ); //Right Now
remove_meta_box( 'rg_forms_dashboard', 'dashboard', 'normal' ); //Gravity Forms
remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' ); //Recent Comments
remove_meta_box( 'icl_dashboard_widget', 'dashboard', 'normal' ); //Multi Language Plugin
remove_meta_box( 'dashboard_activity', 'dashboard', 'normal' ); //Activity
remove_action( 'welcome_panel', 'wp_welcome_panel' );
}
add_action( 'wp_dashboard_setup', 'remove_dashboard_widgets' );
Only Show Current User’s Media Attachments
/*
* Only Show Current User's Media Attachments
*/
function show_current_user_attachments( $query = array() ) {
$user_id = get_current_user_id();
if ( $user_id ) {
$query[ 'author' ] = $user_id;
}
return $query;
}
add_filter( 'ajax_query_attachments_args', 'show_current_user_attachments', 10, 1 );