/*
* 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 );
Month: September 2018
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' );
Password Protect Folder with Apache .htaccess file
Create new file named “.htaccess” in the folder with this Content
AuthName "Password Protected!"
AuthType Basic
AuthUserFile /home/cpanel_user_name/public_html/folder_name/.htpasswd
require valid-user
*Change cpanel_user_name & folder_name
Create new file named “.htpasswd” in the same folder with this Content (Username:Password)
asiq:12345
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 );
Add Extra CSS Class to Widget
/*
* Add Extra CSS Class to Widget
*/
function add_extra_class_to_widget( $params ) {
// get widget vars
$widget_name = $params[ 0 ][ 'widget_name' ];
$widget_id = $params[ 0 ][ 'widget_id' ];
// bail early if this widget is not a Text widget
if ( $widget_name != 'Text' ) {
return $params;
}
// add Class to before_widget
$class = 'my-class';
// Get class name from ACF Fields
// $class = get_field( 'class', 'widget_' . $widget_id );
if ( $class ) {
$classe_to_add = 'class="' . $class . ' ';
$params[ 0 ][ 'before_widget' ] = str_replace( 'class="', $classe_to_add, $params[ 0 ][ 'before_widget' ] );
}
return $params;
}
add_filter( 'dynamic_sidebar_params', 'add_extra_class_to_widget' );
Remove Text “Category:”, “Tag:”, “Author:”, “Archives:” and “Other Taxonomy Name:” From Archive Title
/*
* Remove Text "Category:", "Tag:", "Author:", "Archives:" and "Other Taxonomy Name:" From Archive Title
*/
function das_archive_title_modification( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = '<span class="vcard">' . get_the_author() . '</span>';
} elseif ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
} elseif ( is_tax() ) {
$title = single_term_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'das_archive_title_modification' );