Snippets repository for WordPress developpers

Browse

// Core updates
add_filter( 'auto_core_update_send_email', 'wpb_stop_auto_update_emails', 10, 4 );
 
function wpb_stop_update_emails( $send, $type, $core_update, $result ) {
if ( ! empty( $type ) && $type == 'success' ) {
return false;
}
return true;
}

// Plugins updates
add_filter( 'auto_plugin_update_send_email', '__return_false' );

//Themes updates
add_filter( 'auto_theme_update_send_email', '__return_false' );
function wpc_fix_svg_size_attributes($out, $id) {
	$image_url = wp_get_attachment_url($id);
	$file_ext = pathinfo($image_url, PATHINFO_EXTENSION);
	if (is_admin() || 'svg' !== $file_ext) {
		return false;
	}
	return array($image_url, null, null, false);
}
add_filter('image_downsize', 'wpc_fix_svg_size_attributes', 10, 2);
Tags:
Source
/**
 * Reusable Blocks accessible in backend
 * @link https://www.billerickson.net/reusable-blocks-accessible-in-wordpress-admin-area
 *
 */
function be_reusable_blocks_admin_menu() {
    add_menu_page( 'Reusable Blocks', 'Reusable Blocks', 'edit_posts', 'edit.php?post_type=wp_block', '', 'dashicons-editor-table', 22 );
}
add_action( 'admin_menu', 'be_reusable_blocks_admin_menu' );
Tags:
Source
// into any page or template
$orig_post = $post;
global $post;
$categories = get_the_category($post->ID);
if ($categories) {
  $category_ids = array();
  foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
  $args=array(
    'category__in' => $category_ids,
    'post__not_in' => array($post->ID),
    'posts_per_page'=> 2, // Number of related posts that will be shown.
    'ignore_sticky_posts'=>1
  );

  $my_query = new wp_query( $args );
  if( $my_query->have_posts() ) { ?>
    <h4>Related posts</h4>
    <?php
    while( $my_query->have_posts() ) {
      $my_query->the_post();
      get_template_part( '/partials/article-card' );
    } ?>
    <?php	
  }
}
$post = $orig_post;
wp_reset_postdata();
Source
<?php
$tags = get_tags();
if ( $tags ) :
   foreach ( $tags as $tag ) : ?>
    <li><a href="<?php echo esc_url( get_tag_link( $tag->term_id ) ); ?>" title="<?php echo esc_attr( $tag->name ); ?>"><?php echo esc_html( $tag->name ); ?></a></li>
   <?php endforeach; ?>
<?php endif; ?>
Tags:
// functions.php
// Will only leave Image, Paragraph, Heading and List blocks 
function misha_allowed_block_types( $allowed_blocks, $post ) {
  $allowed_blocks = array(
    'core/image',
    'core/paragraph',
    'core/heading',
    'core/list'
  );
  // Only for Page post type
  if( $post->post_type === 'page' ) {
    $allowed_blocks[] = 'core/shortcode';
  }
  return $allowed_blocks;
}
add_filter( 'allowed_block_types', 'misha_allowed_block_types', 10, 2 );

Tags:
Source

Categories

Tags