워드프레스 자식테마(Child theme) 만들기
WordPress
Author
inrokhah
Date
2019-05-23 13:38
Views
1013
워드프레스 자식테마(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 |
20 |
렌트카 가격비교
author
|
2021.07.05
|
Votes 0
|
Views 711
|
author | 2021.07.05 | 0 | 711 |
19 |
한우선물세트
author
|
2021.03.07
|
Votes 0
|
Views 1640
|
author | 2021.03.07 | 0 | 1640 |
18 |
KBoard 댓글 4.6 업데이트 후 댓글 작성시 "권한이 없습니다" 오류 발생 (6)
author
|
2020.07.10
|
Votes 0
|
Views 1209
|
author | 2020.07.10 | 0 | 1209 |
17 |
작성자를 무조건 아이디로 나오게 하려면... (2)
author
|
2019.05.31
|
Votes 0
|
Views 3442
|
author | 2019.05.31 | 0 | 3442 |
16 |
게시판에 글 작성 질문이요 (1)
author
|
2019.05.31
|
Votes 0
|
Views 1415
|
author | 2019.05.31 | 0 | 1415 |
15 |
글작성시 본문 색, 댓글 색, 첨부파일 이름 색을 변경하고 싶습니다. (2)
author
|
2019.05.31
|
Votes 0
|
Views 2008
|
author | 2019.05.31 | 0 | 2008 |
14 |
KBoard 기존에 생성된 게시글 작성자 변경문의 (1)
Editorial Team
|
2019.05.31
|
Votes 0
|
Views 1767
|
Editorial Team | 2019.05.31 | 0 | 1767 |
13 |
KBoard 게시판 버튼 색상 변경 방법
inrokhah
|
2019.05.26
|
Votes 0
|
Views 3786
|
inrokhah | 2019.05.26 | 0 | 3786 |
12 |
KBoard 게시판에 새로운 필드 추가
inrokhah
|
2019.05.26
|
Votes 0
|
Views 2691
|
inrokhah | 2019.05.26 | 0 | 2691 |
11 |
게시판 검색을 카테고리 별로 분류
inrokhah
|
2019.05.25
|
Votes 0
|
Views 1443
|
inrokhah | 2019.05.25 | 0 | 1443 |