Skip to content

Instantly share code, notes, and snippets.

@rad73
rad73 / WooCommerce: Shortcode for displaying on sale products
Created October 14, 2018 21:12
WooCommerce: Shortcode for displaying on sale products
function loc_woo_sale_products( $atts ) {
global $woocommerce_loop;
extract(shortcode_atts(array(
'per_page' => '12',
'columns' => '4',
'orderby' => 'date',
'order' => 'desc'
), $atts));
@rad73
rad73 / WordPress: Author Box after Content
Created October 14, 2018 21:11
WordPress: Author Box after Content
function my_author_info_box( $content ) {
global $post;
if ( is_single() && isset( $post->post_author ) ) {
$display_name = get_the_author_meta( 'display_name', $post->post_author );
if ( empty( $display_name ) )
$display_name = get_the_author_meta( 'nickname', $post->post_author );
$user_description = get_the_author_meta( 'user_description', $post->post_author );
$user_website = get_the_author_meta('url', $post->post_author);
@rad73
rad73 / WordPress: add featured image support for theme
Created October 14, 2018 21:11
WordPress: add featured image support for theme
@rad73
rad73 / WordPress Dashboard: Remove all Widgets
Created October 14, 2018 21:10
WordPress Dashboard: Remove all Widgets
function bdev_remove_dashboard_widgets() {
global $wp_meta_boxes;
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press'] );
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments'] );
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
@rad73
rad73 / WordPress: Remove emojis
Created October 14, 2018 21:10
WordPress: Remove emojis
function my_disable_emojicons() {
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
add_filter( 'emoji_svg_url', '__return_false' );
@rad73
rad73 / WordPress: Remove Comment Functionality
Created October 14, 2018 21:10
WordPress: Remove Comment Functionality
// Remove from admin menu
add_action( 'admin_menu', 'my_remove_admin_menus' );
function my_remove_admin_menus() {
remove_menu_page( 'edit-comments.php' );
}
// Remove from post and pages
add_action( 'init', 'remove_my_comment_support', 100 );
function remove_comment_support() {
remove_post_type_support( 'post', 'comments' );
@rad73
rad73 / WordPress Search: Remove pages
Created October 14, 2018 21:10
WordPress Search: Remove pages
function exclude_pages_from_my_wp_search() {
global $wp_post_types;
$wp_post_types['page']->exclude_from_search = true;
}
add_action( 'init', 'exclude_pages_from_my_wp_search' );
@rad73
rad73 / WordPress: Create Custom Post Type
Created October 14, 2018 21:10
WordPress: Create Custom Post Type
function create_new_custom_post() {
register_post_type( 'custom-post', // name for custom post type
array(
'labels' => array(
'name' => __( 'Custom Post' ),
),
'public' => true,
'hierarchical' => true,
'has_archive' => true,
'supports' => array(
@rad73
rad73 / WordPress: Post Listing with Thumbnail Support
Created October 14, 2018 21:09
WordPress: Post Listing with Thumbnail Support
add_image_size( 'admin-list-thumb', 80, 80, false );
function loc_add_thumbnail_columns( $columns ) {
if ( !is_array( $columns ) )
$columns = array();
$new = array();
foreach( $columns as $key => $title ) {
if ( $key == 'title' )
$new['featured_thumb'] = __( 'Image');
@rad73
rad73 / TinyMCE: Always show advanced toolbar
Created October 14, 2018 21:09
TinyMCE: Always show advanced toolbar
function show_tinymce_adv_toolbar( $in ) {
$in['wordpress_adv_hidden'] = false;
return $in;
}
add_filter( 'tiny_mce_before_init', 'show_tinymce_adv_toolbar' );