후쿠오카현 구루메시에 위치한 작은 홈페이지・웹사이트 제작소

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

MEMOMEMO

functions.php에 작성해두면 유용한 코드 (그 1)

2023-11-10 22:47

/* 글의 아이캐치 이미지 기능 활성화*/
add_theme_support( 'pos t-thumbnails' ); /* 글 의 아이캐치 이미지 기능 활성화*/ add_theme_support( 'post-thumbnails' );

/* 커스텀 메뉴 기능 등록 및 활성화*/
register_nav_menu( '메뉴 위치 식별자', '메뉴 설명문'); /* 커스텀 메뉴 기능 등록 및 활성화

/* 커스텀 헤더 기능 활성화*/
add_theme_support( 'custom-header' ); /* 커스텀 헤더 기능 활성화*/ add_theme_support( 'custom-header' );

/* 커스텀 배경 기능 활성화 */
add_theme_support( 'custom-background' ); /* 피드 링크의 자동 출력 기능 활성화

/* 피드 링크 자동 출력 활성화 */
add_theme_support( 'automatic-feed-links' ); add_theme_support( 'automatic-feed-links' );

/* 위젯 등록*/
register_sidebar(array(
'name' => '위젯의 이름',
'id' => '위젯의 ID',
'description' => '위젯의 설명'. ,
'class' => '위젯의 클래스',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '</div>', 'before_title' => '</div>', 'title' => '<h2>', 'description' => '위젯의 설명. '<h2>',
'after_title' => '</h2>',
));

// 커스텀 로고 기능 추가 //
function add_custom_logo_support() {
add_theme_support( 'custom-logo', array(
) );
}
add_action( 'after_setup_theme', 'add_ custom_logo_support' );

// WebP, AVIF, SVG를 업로드할 수 있도록 허용
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');

// 업로드 크기 변경
function custom_upload_size_limit($limit) {
return 64 * 1024 * 1024; // 64MB로 변경
}
add_filter('upload_size_limit', 'custom_upload_size_limit', 'custom_upload_size_limit'); // 업로드 크기 변경 upload_size_limit'); // 목록에서 아이캐치 표식을 추가합니다.

// 목록에 아이캐치 표시
function custom_columns( $columns ) {
$columns = array_merge( $columns, array( 'featured_image' => '아이캐치')));
return $columns;
}
add_filter('manage_posts_columns' , 'custom_columns');
function custom_columns_data( $column) {
switch ( $column ) {
case 'featured_image':
the_ post_thumbnail( 'thumbnail' );
break;
}
}
add_action( 'manage_posts_custom_column' , 'custom_columns_data', 10, 2 );
add_image_size( 'custom- thumbnail', 125, 9999);
set_post_thumbnail_size(125, 0, array('custom-thumbnail')); set_post_thumbnail_size(125, 0, array('custom-thumbnail'));

// 게시물의 태그를 체크박스로 선택할 수 있도록 하기
function change_post_tag_to_checkbox() {
$args = get_taxonomy('post_tag');
$args -> hierarchical = true;// 구텐베르크용
$args -> meta_box_cb = 'post_categories_meta_box';//클래식 에디터용
register_taxonomy( 'post_tag', 'post', $args);
}
add_action( ' init', 'change_post_tag_to_checkbox', 1 );

<< 목록으로 돌아가기