Snippets

Trim posts with status future like post status publish

// Trim posts with status future like post status publish function custom_archive_query($query) { if ( $query->is_archive() ) { $query->set(‘post_status’, array(‘future’, ‘publish’)); } return $query; } add_filter(‘pre_get_posts’, ‘custom_archive_query’); Source: 10+ Useful WordPress Code Snippets

Trim AJAX Calendar Future POSTS to be valid

// Trim AJAX Calendar Future POSTS to be valid add_filter(‘get_calendar’, ‘customize_calendar_output’); function customize_calendar_output($calendar_output) { $calendar_output = str_replace(‘<table id=”wp-calendar” summary=”‘ . esc_attr__(‘Calendar’) . ‘”>’, ‘<table id=”wp-calendar”>’, $calendar_output); return $calendar_output; } Source: 10+ Useful WordPress Code Snippets

Add new dashboard widget

// Add new dashboard widget function new_dash_widget_function() { ?> <p>Some text or Html.</p> <?php } function add_dashboard_widgets() { wp_add_dashboard_widget(‘new_dash_widget’, ‘Your_Widget_name’, ‘new_dash_widget_function’); } add_action(‘wp_dashboard_setup’, ‘add_dashboard_widgets’); Source: 10+ Useful WordPress Code Snippets

Remove Posts menu for Editor, Author, and Contributor

// Remove Posts menu for Editor, Author, and Contributor if (! current_user_can(‘manage_options’)) { add_action(‘admin_menu’, ‘notadmin_remove_menus’, 999); function notadmin_remove_menus() { remove_menu_page(‘edit.php’); // Posts remove_menu_page(‘tools.php’); // Tools remove_submenu_page(‘edit.php?post_type=custom_post_type’, ‘post-new.php?post_type=custom_post_type’); // Custom Post Type } } Source: 10+ Useful WordPress Code Snippets

Remove Items from admin bar for authors

// Remove Items from admin bar for authors function remove_admin_bar_links() { if (current_user_can(‘author’)){ global $wp_admin_bar; $wp_admin_bar->remove_menu(‘new-content’); // Remove Add New $wp_admin_bar->remove_menu(‘comments’); // Remove Comments $wp_admin_bar->remove_menu(‘wpseo-menu’); // Remove Yoast SEO links menu $wp_admin_bar->remove_menu(‘documentation’); // Remove the WordPress documentation link $wp_admin_bar->remove_menu(‘support-forums’); // Remove the support forums link $wp_admin_bar->remove_menu(‘feedback’); // Remove the feedback link } } add_action(‘wp_before_admin_bar_render’, ‘remove_admin_bar_links’); …

Remove Items from admin bar for authors Read More »

Remove Edit Title, Add new, Permalink, View Post buttons from Custom Post Type Edit Screens

// Remove Edit Title, Add new, Permalink, View Post buttons from Custom Post Type Edit Screens function posttype_admin_css() { if (current_user_can(‘author’)){ global $post_type; if($post_type == ‘custom_post_type’) { echo ‘<style type=”text/css”>#titlediv,.add-new-h2,#edit-slug-box,#view-post-btn,.updated p a{display: none;}</style>’; } } } add_action(‘admin_head’, ‘posttype_admin_css’); Source: 10+ Useful WordPress Code Snippets

Remove editor only for author based on Custom Post Types

// Remove editor only for author based on Custom Post Types function remove_editor() { if (current_user_can(‘author’)){ remove_post_type_support(‘custom_post_type’,’editor’); } } add_action(‘admin_init’,’remove_editor’); Source: 10+ Useful WordPress Code Snippets

Remove Dynamic Widget Metabox from Custom Post Type Edit Screens

// Remove Dynamic Widget Metabox from Custom Post Type Edit Screens function remove_dynwid_box() { if ($current_user->user_level < 10){ remove_meta_box(‘dynwid’,’custom_post_type’,’side’); } } add_action(‘do_meta_boxes’, ‘remove_dynwid_box’); Source: 10+ Useful WordPress Code Snippets

Remove Featured Image Metabox from Custom Post Type Edit Screens

// Remove Featured Image Metabox from Custom Post Type Edit Screens function remove_image_box() { if ($current_user->user_level < 10){ remove_meta_box(‘postimagediv’,’custom_post_type’,’side’); } } add_action(‘do_meta_boxes’, ‘remove_image_box’); Source: 10+ Useful WordPress Code Snippets

Scroll to Top