Small homepage/website design shop in Kurume City, Fukuoka Prefecture, Japan.

猫壱屋 サイト ホームページ 作成 制作

MEMOMEMO

Useful code to write in functions.php (Part 1)

2023-11-10 22:47

/* Enable article eye-catching image feature*/
add_theme_support( 'post-thumbnails' );

/* Register and enable custom menu feature*/
register_nav_menu( 'menu-position-identifier', 'menu-description' );

/* Enable custom header feature*/
add_theme_support( ' custom-header' );

/* Enable custom background feature*/
add_theme_support( 'custom-background' );

/*Enable automatic output of feed links*/
add_theme_support( 'automatic-feed-links' );

/* Register widget*/
        'name'         => 'widget name',
      'id'               => 'widget id',
        'description'   => 'widget Description. ',
        'class'       => 'widget class',
        'before_widget 'before_widget' => '<div class=\"widget\">',
      'after_widget' => '</div>',
    & nbsp; 'before_title' => '<h2>',
      'after_title' => '</h2>',
    ));

// Add custom logo functionality//
function add_custom_logo_support() {
  add_theme_support( 'custom-logo', array(< br>  ) );
}
}
add_action( 'after_setup_theme', 'add_custom_logo_support' );

// Allow uploading WebP, AVIF, SVG Enable
function allow_custom_mime_types($mimes) {
  $mimes['webp'] = 'image/webp';
  $mimes['avif'] = ' image/avif';
  $mimes['svg'] = 'image/svg+xml';
  return $mimes;
}
add_filter('upload_mimes', 'allow_ custom_mime_types');

// Change upload size
function custom_upload_size_limit($limit) {
  return 64 * 1024 * 1024; // change to 64 megabytes
}
add_filter('upload_size_limit', 'custom_upload_size_limit');

//Icatch marker in list
function custom_columns( $columns ) {
  $columns = array_merge( $columns, array( 'featured_image' => 'eye-catching'));
  return $columns;
}

add_filter('manage_posts_columns', 'custom_columns');
function custom_columns_data( $column) {< br>  switch ( $column ) {
  case 'featured_image':
      the_post_thumbnail( 'thumbnail' );
      break;
  }
}
add_action( 'manage_posts_custom_columns', 'custom_columns_data', 10, 2 );
add_image_size(' custom-thumbnail', 125, 9999);
set_post_thumbnail_size(125, 0, array('custom-thumbnail'));

// Checkbox for post tags to allow selection by
function change_post_tag_to_checkbox() {
  $args = get_taxonomy('post_tag');
  $args -> hierarchical = true;//for Gutenberg
  $args -> meta_box_cb = 'post_categories_meta_box';//for Classic editor
  register_ taxonomy( 'post_tag', 'post', $args);
}
add_action( 'init', 'change_post_tag_to_checkbox', 1 );

<< Back to list