Snippets repository for WordPress developpers

Browse
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
// into functions.php
<?php
function sp_enable_svg_upload( $mimes ) {
  //For security reasons only admin can uplaod svg files
  if ( !current_user_can( 'administrator' ) ) {
    return $mimes;
  }
  $mimes['svg']  = 'image/svg+xml';
  $mimes['svgz'] = 'image/svg+xml';
  return $mimes;
}
add_filter('upload_mimes', 'sp_enable_svg_upload');
?>

Or use Daryll Doyle Safe SVG plugin.

// functions.php
add_image_size( 'sp_cover', 1980, 1200, true );
add_filter( 'image_size_names_choose', 'sp_custom_image_sizes' );
function sp_custom_image_sizes( $sizes ) {
  return array_merge( $sizes, array(
    'sp_cover' => __( 'Rosa cover' ),
  ) );
}
Tags:

Categories

Tags