워드프레스 자식테마(Child theme) 만들기
WordPress
Author
inrokhah
Date
2019-05-23 13:38
Views
1368
워드프레스 자식테마(Child theme) 만들기
우선 워드프레스의 테마디렉토리 밑에 차일드테마 디렉토리를 생성한다.보통 워드프레스 테마는 WP설치위치/wp-content/themes 에 위치한다.
1 2 3 4 5 6 7 8 |
# cd ~/public_html/wp/wp-content/themes # ls ./ index.php twentynineteen/ twentysixteen/ ../ twentyfifteen/ twentyseventeen/ # mkdir twentyseventeen-child (이름은 아무거나 상관없다.) # ls ./ index.php twentynineteen/ twentyseventeen-child/ ../ twentyfifteen/ twentyseventeen/ twentysixteen/ |
차일드 테마에는 아래와 같이 4개의 파일이 있을 수 있다.
- style.css (필수)
- functions.php (옵션)
- Template files (옵션)
- Other files (옵션)
style.css 는 반드시 필요하며. 아래와 같은 해더정보가 필요. (위의 링크 https://codex.wordpress.org/ko:Child_Themes 에 있던 샘플.)
1 2 3 4 5 6 7 8 9 |
/* Theme Name: Twenty Eleven Child Theme URI: http: //example.com/ Description: Child theme for the Twenty Eleven theme Author: Your name here Author URI: http: //example.com/about/ Template: twentyeleven Version: 0.1.0 */ |
위의 style.css 헤더에서 꼭 필요한 부분은 2가지이다.
- Theme Name : child 테마의 이름
- Template : Parent테마의 디렉토리 ( 대소문자 구분)
1 2 3 4 5 6 |
/* Theme Name: Twenty Seventeen Child Template: twentyseventeen */ @import url("../twentyseventeen/style.css"); |
위와 같이 기본 형태를 꾸며놓고.. 필요한 경우 style을 추가로 지정
functions.php는 부모 테마의 functions.php를 덮어쓰지 않고, 추가로 함께 로드된다. 따라서 필요한 내용만 추가
메인페이지에 특정 카테고리 글을 제외하고 불러오는 것과, <head></head>테그에 특정 스크립트(구글 광고..)를 넣는 내용을 추가
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# cat ~/public_html/wp/wp-content/themes/twentyseventeen-child/functions.php <?php /** * 메인페이지에 특정카테고리 제외 */ function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '-4' ); } } add_action( 'pre_get_posts', 'exclude_category' ); /** * Head Tag 에 구글 애드샌스 추가 */ function child_theme_head_script() { ?> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-xxxxxxxxxxxxxxxxxx", enable_page_level_ads: true }); </script> <?php } add_action( 'wp_head', 'child_theme_head_script' ); # |
Total Reply 0
Total 20
Number | Title | Author | Date | Votes | Views |
10 |
게시판 하단에 Powered by KBoard 삭제 방법
inrokhah
|
2019.05.25
|
Votes 0
|
Views 2242
|
inrokhah | 2019.05.25 | 0 | 2242 |
9 |
KBoard를 검색엔진에 등록
inrokhah
|
2019.05.25
|
Votes 0
|
Views 2007
|
inrokhah | 2019.05.25 | 0 | 2007 |
8 |
Contact Form 문의하기 양식 적용하기
inrokhah
|
2019.05.24
|
Votes 0
|
Views 1203
|
inrokhah | 2019.05.24 | 0 | 1203 |
7 |
구글 애드센스 자동광고 설정하고 사용해보기 (1)
inrokhah
|
2019.05.23
|
Votes 0
|
Views 1365
|
inrokhah | 2019.05.23 | 0 | 1365 |
6 |
구글 애드센스 자동광고 설정 (1)
inrokhah
|
2019.05.23
|
Votes 0
|
Views 1063
|
inrokhah | 2019.05.23 | 0 | 1063 |
5 |
워드프레스 자식테마(Child theme) 만들기
inrokhah
|
2019.05.23
|
Votes 0
|
Views 1368
|
inrokhah | 2019.05.23 | 0 | 1368 |
4 |
워드프레스 첫 화면에 특정카테고리 안나오게 하기 (1)
inrokhah
|
2019.05.23
|
Votes 0
|
Views 969
|
inrokhah | 2019.05.23 | 0 | 969 |
3 |
워드프레스 업그레이드 후 500 Internal Server Error 발생할 때
inrokhah
|
2019.05.23
|
Votes 0
|
Views 838
|
inrokhah | 2019.05.23 | 0 | 838 |
2 |
KBoard 새로운 입력 필드 추가 방법
inrokhah
|
2019.05.22
|
Votes 0
|
Views 1608
|
inrokhah | 2019.05.22 | 0 | 1608 |
1 |
KBoard(케이보드) 플러그인 업데이트 방법 (1)
inrokhah
|
2019.05.22
|
Votes 0
|
Views 4947
|
inrokhah | 2019.05.22 | 0 | 4947 |