Ver3.0 ๐ ์๋ํ๋ ์ค ๋คํฌ ๋ชจ๋ ๊ตฌํํ๊ธฐ

๐ ์๋ํ๋ ์ค ๋คํฌ ๋ชจ๋ ๊ตฌํํ๊ธฐ
์ฌ์ฉ์ ๊ฒฝํ์ ํ ๋จ๊ณ ์ ๊ทธ๋ ์ด๋ํ๋ ๋คํฌ ๋ชจ๋ ์๋ฒฝ ๊ฐ์ด๋
์์ฆ ์น์ฌ์ดํธ๋ ์ฑ์ ๋ณด๋ฉด ๋คํฌ ๋ชจ๋๊ฐ ๊ฑฐ์ ํ์ ๊ธฐ๋ฅ์ฒ๋ผ ์๋ฆฌ ์ก์์ง? ๐
๋ฐค์ ์ค๋งํธํฐ ๋ณด๋ค๊ฐ ๋์ด ๋ถ์
์ ํ๋ฉด ๋ฐ๊ธฐ๋ฅผ ์ต์๋ก ๋ฎ์ถฐ๋ณธ ๊ฒฝํ, ๋ค๋ค ์์ ๊ฑฐ์ผ.
๋คํฌ ๋ชจ๋๋ ๋จ์ํ '๊ฒ์ ๋ฐฐ๊ฒฝ'์ด ์๋๋ผ, ์ฌ์ฉ์์ ๋ ๊ฑด๊ฐ๊ณผ ๋ฐฐํฐ๋ฆฌ ์๋ช
, ๊ทธ๋ฆฌ๊ณ ์ ์ฒด์ ์ธ ์ฌ์ฉ ๊ฒฝํ์ ๊ฐ์ ํ๋ ๊ฐ๋ ฅํ ๋๊ตฌ์ผ.
์๋ํ๋ ์ค๋ก ์น์ฌ์ดํธ๋ฅผ ์ด์ํ๊ณ ์๋ค๋ฉด, ๋คํฌ ๋ชจ๋ ๊ตฌํ์ ์๊ฐ๋ณด๋ค ์ด๋ ต์ง ์์.
์ด ๊ธ์์๋ ์ด๋ณด์๋ ๋ฐ๋ผ ํ ์ ์๋ ์ค์ ๋ฐฉ๋ฒ๋ถํฐ, ๊ฐ๋ฐ์๋ฅผ ์ํ ๊ณ ๊ธ ์ปค์คํฐ๋ง์ด์ง๊น์ง ๋ชจ๋ ๋ค๋ค๋ณผ๊ฒ! ๐ช
๐ฏ ๋คํฌ ๋ชจ๋, ์ ํ์ํ ๊น?
๋คํฌ ๋ชจ๋๋ฅผ ๊ตฌํํ๊ธฐ ์ ์, ์ ์ด๊ฒ ์ค์ํ์ง๋ถํฐ ์์๋ณด์.
๋จ์ํ '๋ฉ์์ด ๋ณด์ฌ์'๊ฐ ์๋๋ผ, ์ค์ง์ ์ธ ์ด์ ๋ค์ด ์์ด.
๐๏ธ ๋ ๊ฑด๊ฐ ๋ณดํธ
๋ฐ์ ํ๋ฉด์ ์ค๋ ๋ณด๋ฉด ๋์ ํผ๋ก๋๊ฐ ๊ธ๊ฒฉํ ์ฆ๊ฐํด.
ํนํ ์ด๋์ด ํ๊ฒฝ์์ ๋ฐ์ ํ๋ฉด์ ๋ณด๋ฉด ๋๊ณต์ด ์์ถํ๋ฉด์ ๋์ ๋ ํฐ ๋ถ๋ด์ ์ฃผ์ง.
๋คํฌ ๋ชจ๋๋ ํ๋ฉด์ ๋ฐ๊ธฐ๋ฅผ ๋ฎ์ถฐ์ ๋์ ํผ๋ก๋ฅผ ์ค์ฌ์ฃผ๊ณ , ๋ธ๋ฃจ๋ผ์ดํธ ๋
ธ์ถ๋ ๊ฐ์์์ผ์ค. ๐
๐ ๋ฐฐํฐ๋ฆฌ ์๋ช ์ฐ์ฅ
OLED๋ AMOLED ๋์คํ๋ ์ด๋ฅผ ์ฌ์ฉํ๋ ๊ธฐ๊ธฐ์์๋ ๋คํฌ ๋ชจ๋๊ฐ ๋ฐฐํฐ๋ฆฌ ์๋ช
์ ํฌ๊ฒ ๋๋ ค์ค.
์ด๋ฐ ๋์คํ๋ ์ด๋ ๊ฒ์์ ํฝ์
์ ํ์ํ ๋ ์ ๋ ฅ์ ๊ฑฐ์ ์๋นํ์ง ์๊ฑฐ๋ .
๊ตฌ๊ธ์ ํ
์คํธ ๊ฒฐ๊ณผ, ์ ํ๋ธ ์ฑ์์ ๋คํฌ ๋ชจ๋๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฐฐํฐ๋ฆฌ ์๋ชจ๊ฐ ์ฝ 43% ๊ฐ์ํ๋ค๊ณ ํด! ๐
๐จ ๋ฏธ์ ์ ํ์ ๋ค์์ฑ
์ฌ์ฉ์๋ง๋ค ์ ํธํ๋ ์ธํฐํ์ด์ค ์คํ์ผ์ด ๋ฌ๋ผ.
์ด๋ค ์ฌ๋์ ๋ฐ๊ณ ๊น๋ํ ๋ผ์ดํธ ๋ชจ๋๋ฅผ ์ข์ํ๊ณ , ์ด๋ค ์ฌ๋์ ์ธ๋ จ๋๊ณ ์ง์คํ๊ธฐ ์ข์ ๋คํฌ ๋ชจ๋๋ฅผ ์ ํธํ์ง.
์ ํ๊ถ์ ์ ๊ณตํ๋ ๊ฒ ์์ฒด๊ฐ ์ฌ์ฉ์ ๊ฒฝํ์ ํฅ์์ํค๋ ๊ฑฐ์ผ.
โฟ ์ ๊ทผ์ฑ ํฅ์
์๊ฐ ์ฅ์ ๋ ๊ด๊ณผ๋ฏผ์ฑ์ ๊ฐ์ง ์ฌ์ฉ์๋ค์๊ฒ ๋คํฌ ๋ชจ๋๋ ํ์์ ์ธ ๊ธฐ๋ฅ์ด์ผ.
๋ฐ์ ๋น์ ๋ฏผ๊ฐํ ์ฌ๋๋ค์ ๋คํฌ ๋ชจ๋๊ฐ ์์ผ๋ฉด ์น์ฌ์ดํธ๋ฅผ ์ ๋๋ก ์ด์ฉํ๊ธฐ ์ด๋ ค์ธ ์ ์์ด.
์น ์ ๊ทผ์ฑ์ ๋จ์ํ ์ ํ์ด ์๋๋ผ ๋ชจ๋ ์ฌ์ฉ์๋ฅผ ๋ฐฐ๋ คํ๋ ํ์ ์์์ผ. ๐
๐ ๏ธ ์๋ํ๋ ์ค ๋คํฌ ๋ชจ๋ ๊ตฌํ ๋ฐฉ๋ฒ
์, ์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก ์๋ํ๋ ์ค์์ ๋คํฌ ๋ชจ๋๋ฅผ ๊ตฌํํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด์!
ํฌ๊ฒ ์ธ ๊ฐ์ง ๋ฐฉ๋ฒ์ด ์์ด: ํ๋ฌ๊ทธ์ธ ์ฌ์ฉ, ํ
๋ง ๊ธฐ๋ฅ ํ์ฉ, ์ง์ ์ฝ๋ฉ.
๊ฐ๊ฐ์ ์ฅ๋จ์ ๊ณผ ๊ตฌ์ฒด์ ์ธ ๋ฐฉ๋ฒ์ ์ดํด๋ณผ๊ฒ. ๐
๐ฆ ๋ฐฉ๋ฒ 1: ํ๋ฌ๊ทธ์ธ ์ฌ์ฉํ๊ธฐ (์ด๋ณด์ ์ถ์ฒ)
๊ฐ์ฅ ์ฝ๊ณ ๋น ๋ฅธ ๋ฐฉ๋ฒ์ด์ผ. ์ฝ๋ฉ ์ง์์ด ์ ํ ์์ด๋ ๋ช ๋ถ ์์ ๋คํฌ ๋ชจ๋๋ฅผ ์ถ๊ฐํ ์ ์์ด.
์๋ํ๋ ์ค์ ๊ฐ๋ ฅํ ํ๋ฌ๊ทธ์ธ ์ํ๊ณ ๋๋ถ์ ๋ค์ํ ์ ํ์ง๊ฐ ์์ง.
๐ ์ถ์ฒ ํ๋ฌ๊ทธ์ธ TOP 3
โ ์ฃผ์ ๊ธฐ๋ฅ:
โข ์ํด๋ฆญ ๋คํฌ ๋ชจ๋ ํ์ฑํ
โข 32๊ฐ์ง ์ด์์ ์ฌ์ ์ ์๋ ๋คํฌ ๋ชจ๋ ์คํ์ผ
โข ํ๋ก ํธ์๋์ ๋ฐฑ์๋ ๋ชจ๋ ์ง์
โข ์๋ ๋คํฌ ๋ชจ๋ (์๊ฐ ๊ธฐ๋ฐ, OS ์ค์ ๊ธฐ๋ฐ)
โข ํน์ ํ์ด์ง/ํฌ์คํธ ์ ์ธ ๊ธฐ๋ฅ
โข WooCommerce, Elementor ๋ฑ ์ฃผ์ ํ๋ฌ๊ทธ์ธ ํธํ
๐ฐ ๊ฐ๊ฒฉ: ๋ฌด๋ฃ (ํ๋ฆฌ๋ฏธ์: $49/๋ )
โญ ํ์ : 4.8/5 (1,000๊ฐ ์ด์์ ๋ฆฌ๋ทฐ)
โ ์ฃผ์ ๊ธฐ๋ฅ:
โข ์ด๊ฒฝ๋ (50KB ๋ฏธ๋ง)
โข ํ์ด์ง ๋ก๋ฉ ์๋์ ๊ฑฐ์ ์ํฅ ์์
โข ๊ฐ๋จํ ํ ๊ธ ์ค์์น
โข ์ฌ์ฉ์ ์ ํ ๊ธฐ์ต (์ฟ ํค ๊ธฐ๋ฐ)
โข ์ปค์คํ CSS ์ง์
๐ฐ ๊ฐ๊ฒฉ: ๋ฌด๋ฃ (ํ๋ฆฌ๋ฏธ์: $29/๋ )
โญ ํ์ : 4.7/5
โ ์ฃผ์ ๊ธฐ๋ฅ:
โข ์ต์ํ์ ์ค์
โข ๊น๋ํ ํ ๊ธ ๋ฒํผ
โข ์์น ์ปค์คํฐ๋ง์ด์ง ๊ฐ๋ฅ
โข ๋ชจ๋ฐ์ผ ์ต์ ํ
๐ฐ ๊ฐ๊ฒฉ: ์์ ๋ฌด๋ฃ
โญ ํ์ : 4.5/5
๐ง WP Dark Mode ์ค์น ๋ฐ ์ค์ ๊ฐ์ด๋
์๋ํ๋ ์ค ๊ด๋ฆฌ์ ํ์ด์ง์์ ํ๋ฌ๊ทธ์ธ > ์๋ก ์ถ๊ฐ๋ก ์ด๋ํด.
๊ฒ์์ฐฝ์ "WP Dark Mode"๋ฅผ ์ ๋ ฅํ๊ณ ์ค์น ํ ํ์ฑํ!
WP Dark Mode > Settings ๋ฉ๋ด๋ก ๋ค์ด๊ฐ๋ฉด ๋์๋ณด๋๊ฐ ๋์.
์ฌ๊ธฐ์ "Enable Frontend Darkmode"๋ฅผ ์ผ์ฃผ๋ฉด ๊ธฐ๋ณธ ๋คํฌ ๋ชจ๋๊ฐ ๋ฐ๋ก ์ ์ฉ๋ผ!
Customization ํญ์์ ๋คํฌ ๋ชจ๋ ์์์ ์กฐ์ ํ ์ ์์ด.
โข Background Color: ๋ฐฐ๊ฒฝ์ (์ถ์ฒ: #1a1a1a ~ #2d2d2d)
โข Text Color: ํ ์คํธ ์์ (์ถ์ฒ: #e0e0e0 ~ #ffffff)
โข Link Color: ๋งํฌ ์์ (์ถ์ฒ: #64b5f6 ~ #90caf9)
โข Selection Color: ํ ์คํธ ์ ํ ์์
Switch Settings์์ ๋คํฌ ๋ชจ๋ ํ ๊ธ ๋ฒํผ์ ์์น๋ฅผ ์ ํด์ค.
โข Floating Switch: ํ๋ฉด ๊ตฌ์์ ๋ ์๋ ๋ฒํผ
โข Menu Switch: ๋ฉ๋ด์ ํตํฉ
โข Custom Position: ์ํ๋ ์์น์ ์์ฝ๋๋ก ๋ฐฐ์น
Advanced ํญ์์ ์ธ๋ฐํ ์กฐ์ ์ด ๊ฐ๋ฅํด.
โข Time Based: ํน์ ์๊ฐ๋์ ์๋์ผ๋ก ๋คํฌ ๋ชจ๋ ํ์ฑํ
โข OS Aware: ์ฌ์ฉ์์ ์ด์์ฒด์ ์ค์ ์ ๋ฐ๋ฆ
โข Excludes: ํน์ ํ์ด์ง๋ ์์๋ฅผ ๋คํฌ ๋ชจ๋์์ ์ ์ธ
โข Image Settings: ์ด๋ฏธ์ง ๋ฐ๊ธฐ ์๋ ์กฐ์
๐จ ๋ฐฉ๋ฒ 2: ํ ๋ง ๊ธฐ๋ฅ ํ์ฉํ๊ธฐ
์ต๊ทผ ์ถ์๋๋ ํ๋ฆฌ๋ฏธ์ ์๋ํ๋ ์ค ํ
๋ง๋ค์ ๋คํฌ ๋ชจ๋๋ฅผ ๊ธฐ๋ณธ ๊ธฐ๋ฅ์ผ๋ก ์ ๊ณตํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์.
๋ง์ฝ ๋ค๊ฐ ์ฌ์ฉํ๋ ํ
๋ง์ ๋คํฌ ๋ชจ๋ ๊ธฐ๋ฅ์ด ์๋ค๋ฉด, ํ๋ฌ๊ทธ์ธ ์์ด๋ ๊ตฌํํ ์ ์์ด!
๐ ํ ๋ง ๋คํฌ ๋ชจ๋ ์ง์ ํ์ธํ๊ธฐ
2. ํ ๋ง ๋ฌธ์(Documentation)๋ฅผ ํ์ธํด. ๋๋ถ๋ถ์ ํ๋ฆฌ๋ฏธ์ ํ ๋ง๋ ์์ธํ ๊ฐ์ด๋๋ฅผ ์ ๊ณตํด.
3. ํ ๋ง ๊ฐ๋ฐ์์๊ฒ ์ง์ ๋ฌธ์ํด๋ ๋ผ.
๐ ๋คํฌ ๋ชจ๋๋ฅผ ๊ธฐ๋ณธ ์ง์ํ๋ ์ธ๊ธฐ ํ ๋ง
์ธ๋ชจ > ์ฌ์ฉ์ ์ ์ํ๊ธฐ > Global > Colors์์ Dark Mode Palette๋ฅผ ์ค์ ํ ์ ์์ด.
โข GeneratePress Premium
๊ฐ๋ฐ์๋ค์ด ์ฌ๋ํ๋ ํ ๋ง. ๋คํฌ ๋ชจ๋ ์ปค์คํฐ๋ง์ด์ง ์์ ๋๊ฐ ๋์.
Elements ๊ธฐ๋ฅ์ ์ฌ์ฉํด์ ์กฐ๊ฑด๋ถ ๋คํฌ ๋ชจ๋ ์คํ์ผ๋ ์ ์ฉ ๊ฐ๋ฅํด.
โข Kadence Theme
์ต์ ํธ๋ ๋๋ฅผ ๋ฐ์ํ ํ ๋ง. ๋คํฌ ๋ชจ๋๊ฐ ๋งค์ฐ ์ธ๋ จ๋๊ฒ ๊ตฌํ๋์ด ์์ด.
์์ ํ๋ ํธ๋ฅผ ๋ผ์ดํธ/๋คํฌ ๋ชจ๋๋ณ๋ก ๋ฐ๋ก ์ค์ ํ ์ ์์ด.
โข OceanWP
๋ฌด๋ฃ ํ ๋ง์ง๋ง ๋คํฌ ๋ชจ๋ ํ์ฅ ๊ธฐ๋ฅ์ ์ ๊ณตํด.
Ocean Extra ํ๋ฌ๊ทธ์ธ๊ณผ ํจ๊ป ์ฌ์ฉํ๋ฉด ๋ ๋ง์ ์ต์ ์ ์ฌ์ฉํ ์ ์์ด.
๐ป ๋ฐฉ๋ฒ 3: ์ง์ ์ฝ๋ฉํ๊ธฐ (๊ฐ๋ฐ์์ฉ)
์์ ํ ์ปค์คํฐ๋ง์ด์ง์ ์ํ๋ค๋ฉด ์ง์ ์ฝ๋ฉํ๋ ๊ฒ ์ต๊ณ ์ผ.
CSS ๋ณ์์ JavaScript๋ฅผ ํ์ฉํ๋ฉด ์๊ฐ๋ณด๋ค ๊ฐ๋จํ๊ฒ ๊ตฌํํ ์ ์์ด.
์ด ๋ฐฉ๋ฒ์ ํ๋ฌ๊ทธ์ธ ์์กด์ฑ์ ์ค์ด๊ณ , ์ฌ์ดํธ ์ฑ๋ฅ์ ์ต์ ํํ ์ ์๋ค๋ ์ฅ์ ์ด ์์ง. ๐ฏ
๐ ๊ธฐ๋ณธ ๊ตฌ์กฐ ์ดํดํ๊ธฐ
๋คํฌ ๋ชจ๋ ๊ตฌํ์ ํต์ฌ์ ์ธ ๊ฐ์ง์ผ:
1. CSS ๋ณ์๋ก ์์ ์ฒด๊ณ ์ ์
2. JavaScript๋ก ๋ชจ๋ ์ ํ ๊ธฐ๋ฅ ๊ตฌํ
3. LocalStorage๋ก ์ฌ์ฉ์ ์ ํ ์ ์ฅ
๐จ Step 1: CSS ๋ณ์ ์ค์
๋จผ์ style.css ํ์ผ์ CSS ๋ณ์๋ฅผ ์ ์ํด์ค.
์ด๋ ๊ฒ ํ๋ฉด ๋์ค์ ์์์ ๋ณ๊ฒฝํ ๋ ํ ๊ณณ๋ง ์์ ํ๋ฉด ๋ผ์ ๊ด๋ฆฌ๊ฐ ํธํด.
/* ๋ผ์ดํธ ๋ชจ๋ (๊ธฐ๋ณธ) */
:root {
--bg-primary: #ffffff;
--bg-secondary: #f8f9fa;
--text-primary: #212529;
--text-secondary: #6c757d;
--border-color: #dee2e6;
--link-color: #0d6efd;
--link-hover: #0a58ca;
--shadow: rgba(0, 0, 0, 0.1);
}
/* ๋คํฌ ๋ชจ๋ */
[data-theme="dark"] {
--bg-primary: #1a1a1a;
--bg-secondary: #2d2d2d;
--text-primary: #e0e0e0;
--text-secondary: #a0a0a0;
--border-color: #404040;
--link-color: #64b5f6;
--link-hover: #90caf9;
--shadow: rgba(0, 0, 0, 0.5);
}
/* ๋ณ์ ์ ์ฉ */
body {
background-color: var(--bg-primary);
color: var(--text-primary);
transition: background-color 0.3s ease, color 0.3s ease;
}
.container {
background-color: var(--bg-secondary);
border: 1px solid var(--border-color);
box-shadow: 0 2px 8px var(--shadow);
}
a {
color: var(--link-color);
transition: color 0.2s ease;
}
a:hover {
color: var(--link-hover);
}
h1, h2, h3, h4, h5, h6 {
color: var(--text-primary);
}
p {
color: var(--text-secondary);
}
โก Step 2: JavaScript ํ ๊ธ ๊ธฐ๋ฅ
์ด์ ๋คํฌ ๋ชจ๋๋ฅผ ์ผ๊ณ ๋ ์ ์๋ JavaScript ์ฝ๋๋ฅผ ์์ฑํด๋ณด์.
functions.php ํ์ผ์ ์คํฌ๋ฆฝํธ๋ฅผ ์ถ๊ฐํ๊ฑฐ๋, ๋ณ๋์ JS ํ์ผ์ ๋ง๋ค์ด์ enqueue ํด์ค.
// ๋คํฌ ๋ชจ๋ ํ ๊ธ ์คํฌ๋ฆฝํธ
(function() {
// ์ ์ฅ๋ ํ
๋ง ๋ถ๋ฌ์ค๊ธฐ ๋๋ ์์คํ
์ค์ ํ์ธ
const getPreferredTheme = () => {
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
return savedTheme;
}
// ์์คํ
๋คํฌ ๋ชจ๋ ์ค์ ํ์ธ
return window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: 'light';
};
// ํ
๋ง ์ ์ฉ
const setTheme = (theme) => {
document.documentElement.setAttribute('data-theme', theme);
localStorage.setItem('theme', theme);
// ํ ๊ธ ๋ฒํผ ์์ด์ฝ ์
๋ฐ์ดํธ
const toggleBtn = document.getElementById('theme-toggle');
if (toggleBtn) {
toggleBtn.innerHTML = theme === 'dark'
? 'โ๏ธ'
: '๐';
toggleBtn.setAttribute('aria-label',
theme === 'dark'
? 'Switch to light mode'
: 'Switch to dark mode'
);
}
};
// ํ์ด์ง ๋ก๋ ์ ํ
๋ง ์ ์ฉ (๊น๋นก์ ๋ฐฉ์ง)
setTheme(getPreferredTheme());
// DOM ๋ก๋ ํ ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์ถ๊ฐ
document.addEventListener('DOMContentLoaded', () => {
const toggleBtn = document.getElementById('theme-toggle');
if (toggleBtn) {
toggleBtn.addEventListener('click', () => {
const currentTheme = document.documentElement.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
setTheme(newTheme);
});
}
});
// ์์คํ
ํ
๋ง ๋ณ๊ฒฝ ๊ฐ์ง
window.matchMedia('(prefers-color-scheme: dark)')
.addEventListener('change', (e) => {
if (!localStorage.getItem('theme')) {
setTheme(e.matches ? 'dark' : 'light');
}
});
})();
๐ Step 3: ํ ๊ธ ๋ฒํผ ์ถ๊ฐ
์ฌ์ฉ์๊ฐ ํด๋ฆญํ ์ ์๋ ํ ๊ธ ๋ฒํผ์ ๋ง๋ค์ด์ผ ํด.
header.php๋ ์ํ๋ ์์น์ ๋ฒํผ์ ์ถ๊ฐํด์ค.
<!-- HTML: ํ ๊ธ ๋ฒํผ -->
<button id="theme-toggle"
class="theme-toggle-btn"
aria-label="Toggle dark mode"
type="button">
๐
</button>
<!-- CSS: ๋ฒํผ ์คํ์ผ -->
<style>
.theme-toggle-btn {
position: fixed;
bottom: 20px;
right: 20px;
width: 50px;
height: 50px;
border-radius: 50%;
border: 2px solid var(--border-color);
background-color: var(--bg-secondary);
color: var(--text-primary);
font-size: 24px;
cursor: pointer;
box-shadow: 0 4px 12px var(--shadow);
transition: all 0.3s ease;
z-index: 1000;
display: flex;
align-items: center;
justify-content: center;
}
.theme-toggle-btn:hover {
transform: scale(1.1);
box-shadow: 0 6px 16px var(--shadow);
}
.theme-toggle-btn:active {
transform: scale(0.95);
}
/* ๋ชจ๋ฐ์ผ ์ต์ ํ */
@media (max-width: 768px) {
.theme-toggle-btn {
bottom: 15px;
right: 15px;
width: 45px;
height: 45px;
font-size: 20px;
}
}
</style>
๐ง Step 4: functions.php์ ์คํฌ๋ฆฝํธ ๋ฑ๋ก
์๋ํ๋ ์ค ๋ฐฉ์์ผ๋ก ์คํฌ๋ฆฝํธ๋ฅผ ์ ๋๋ก ๋ฑ๋กํด์ค์ผ ํด.
์ฐจ์ผ๋ ํ
๋ง์ functions.php์ ๋ค์ ์ฝ๋๋ฅผ ์ถ๊ฐํด.
function enqueue_dark_mode_script() {
// CSS ํ์ผ ๋ฑ๋ก
wp_enqueue_style(
'dark-mode-styles',
get_stylesheet_directory_uri() . '/dark-mode.css',
array(),
'1.0.0'
);
// JavaScript ํ์ผ ๋ฑ๋ก
wp_enqueue_script(
'dark-mode-toggle',
get_stylesheet_directory_uri() . '/dark-mode.js',
array(),
'1.0.0',
true
);
}
add_action('wp_enqueue_scripts', 'enqueue_dark_mode_script');
// ํ ๊ธ ๋ฒํผ์ footer์ ์๋ ์ถ๊ฐ
function add_dark_mode_toggle() {
echo '<button id="theme-toggle" class="theme-toggle-btn" aria-label="Toggle dark mode" type="button">๐</button>';
}
add_action('wp_footer', 'add_dark_mode_toggle');
๐จ ๋คํฌ ๋ชจ๋ ๋์์ธ ๋ฒ ์คํธ ํ๋ํฐ์ค
๋คํฌ ๋ชจ๋๋ฅผ ๊ตฌํํ๋ค๊ณ ๋์ด ์๋์ผ. ์ ๋๋ก ๋ ๋คํฌ ๋ชจ๋๋ ๋จ์ํ ์์ ๋ฐ์ ์ํค๋ ๊ฒ ์๋๋ผ,
์ฌ์ฉ์ ๊ฒฝํ์ ๊ณ ๋ คํ ์ธ์ฌํ ๋์์ธ์ด ํ์ํด. ๊ตฌ๊ธ, ์ ํ, ๋ง์ดํฌ๋ก์ํํธ ๊ฐ์ ๋๊ธฐ์
๋ค์ด
์๋
๊ฐ ์ฐ๊ตฌํ ๋คํฌ ๋ชจ๋ ๋์์ธ ์์น๋ค์ ์์๋ณด์! ๐ฏ
๐ ์์ ์ ํ์ ๊ณผํ
1. ์์ํ ๊ฒ์์์ ํผํ์
์ด์ :
์์ํ ๊ฒ์์(#000000)์ ๋์ ๋๋ฌด ๊ฐํ ๋๋น๋ฅผ ๋ง๋ค์ด์ ์คํ๋ ค ํผ๋ก๋๋ฅผ ๋์ฌ.
์ฝ๊ฐ ๋ฐ์ ์ด๋์ด ํ์์ ์ฌ์ฉํ๋ฉด ๋์ด ํจ์ฌ ํธ์ํด์ง๊ณ , ๊น์ด๊ฐ๋ ํํํ ์ ์์ด.
๊ตฌ๊ธ ๋จธํฐ๋ฆฌ์ผ ๋์์ธ์์๋ #121212๋ฅผ ๊ธฐ๋ณธ ๋คํฌ ๋ฐฐ๊ฒฝ์ผ๋ก ๊ถ์ฅํ๊ณ ์์ด.
2. ํ ์คํธ ์์ ์ต์ ํ
โข ํฐ ํ ์คํธ: ์ต์ 4.5:1 (WCAG AA ๊ธฐ์ค)
โข ๋ณด์กฐ ํ ์คํธ: ์ต์ 4.5:1
์ถ์ฒ ์์:
โข ์ฃผ ํ ์คํธ: #e0e0e0 ~ #f5f5f5
โข ๋ณด์กฐ ํ ์คํธ: #a0a0a0 ~ #b0b0b0
โข ๋นํ์ฑ ํ ์คํธ: #6c6c6c ~ #808080
๐ก ์์ํ ํฐ์(#ffffff)์ ๋คํฌ ๋ชจ๋์์ ๋๋ฌด ๋ฐ์์ ๋์ด ๋ถ์ค ์ ์์ด. ์ฝ๊ฐ ์ด๋์ด ํฐ์์ ์ฌ์ฉํ๋ ๊ฒ ์ข์!
3. ์์ ์ฑ๋ ์กฐ์
๋ผ์ดํธ ๋ชจ๋์์ ์ฌ์ฉํ๋ ๋ฐ๊ณ ์ ๋ช
ํ ์์์ ๋คํฌ ๋ชจ๋์์ ๊ทธ๋๋ก ์ฌ์ฉํ๋ฉด ๋๋ฌด ํ์ด ๋ณด์ฌ.
๋คํฌ ๋ชจ๋์์๋ ์ฑ๋๋ฅผ ๋ฎ์ถ๊ณ ๋ฐ๊ธฐ๋ฅผ ์กฐ์ ํด์ผ ํด.
| ์์ ์ฉ๋ | ๋ผ์ดํธ ๋ชจ๋ | ๋คํฌ ๋ชจ๋ | ์กฐ์ ๋ฐฉ๋ฒ |
|---|---|---|---|
| Primary ๋ฒํผ | #0d6efd | #64b5f6 | ๋ฐ๊ธฐ +30%, ์ฑ๋ -10% |
| Success ์์ | #198754 | #4caf50 | ๋ฐ๊ธฐ +40%, ์ฑ๋ -15% |
| Warning ์์ | #ffc107 | #ffb74d | ๋ฐ๊ธฐ -10%, ์ฑ๋ -20% |
| Danger ์์ | #dc3545 | #ef5350 | ๋ฐ๊ธฐ +20%, ์ฑ๋ -10% |
๐ ๋ ์ด์์๊ณผ ๊น์ด๊ฐ
Elevation (๊ณ ๋) ์์คํ
๋คํฌ ๋ชจ๋์์๋ ๊ทธ๋ฆผ์ ๋์ ๋ฐ๊ธฐ๋ก ๊น์ด๋ฅผ ํํํด.
์์๊ฐ ์๋ก ์ฌ๋ผ์ฌ์๋ก ๋ฐฐ๊ฒฝ์ ์กฐ๊ธ์ฉ ๋ฐ๊ฒ ๋ง๋๋ ๊ฑฐ์ผ.
Level 1 (์นด๋): #1e1e1e
Level 2 (์ฑ๋ฐ): #232323
Level 3 (๋ฉ๋ด): #252525
Level 4 (๋ชจ๋ฌ): #272727
๊ฐ ๋ ๋ฒจ๋ง๋ค ์ฝ 5% ์ ๋์ฉ ๋ฐ๊ธฐ๋ฅผ ๋์ฌ์ฃผ๋ฉด ์์ฐ์ค๋ฌ์ด ๊น์ด๊ฐ์ด ์๊ฒจ.
/* Elevation ์์คํ
CSS ์์ */
.surface-level-0 {
background-color: #121212;
}
.surface-level-1 {
background-color: #1e1e1e;
/* ์นด๋, ํจ๋ ๋ฑ */
}
.surface-level-2 {
background-color: #232323;
/* ํค๋, ๋ค๋น๊ฒ์ด์
๋ฐ */
}
.surface-level-3 {
background-color: #252525;
/* ๋๋กญ๋ค์ด ๋ฉ๋ด, ํ์
*/
}
.surface-level-4 {
background-color: #272727;
/* ๋ชจ๋ฌ, ๋ค์ด์ผ๋ก๊ทธ */
}
๐ผ๏ธ ์ด๋ฏธ์ง์ ๋ฏธ๋์ด ์ฒ๋ฆฌ
์ด๋ฏธ์ง ๋ฐ๊ธฐ ์๋ ์กฐ์
๋คํฌ ๋ชจ๋์์ ๋ฐ์ ์ด๋ฏธ์ง๋ ๋์ ๋ถ๋ด์ ์ค ์ ์์ด.
CSS ํํฐ๋ฅผ ์ฌ์ฉํด์ ์ด๋ฏธ์ง ๋ฐ๊ธฐ๋ฅผ ์๋์ผ๋ก ์กฐ์ ํด๋ณด์.
/* ๋คํฌ ๋ชจ๋์์ ์ด๋ฏธ์ง ๋ฐ๊ธฐ ์กฐ์ */
[data-theme="dark"] img {
filter: brightness(0.8) contrast(1.1);
transition: filter 0.3s ease;
}
/* ๋ก๊ณ ๋ ์์ด์ฝ์ ์ ์ธ */
[data-theme="dark"] .logo,
[data-theme="dark"] .icon {
filter: none;
}
/* ํธ๋ฒ ์ ์๋ ๋ฐ๊ธฐ๋ก */
[data-theme="dark"] img:hover {
filter: brightness(1) contrast(1);
}
/* ๋น๋์ค๋ ๋์ผํ๊ฒ */
[data-theme="dark"] video {
filter: brightness(0.85) contrast(1.05);
}
SVG ์์ด์ฝ ์์ ์ฒ๋ฆฌ
/* SVG ์์ด์ฝ ์์ ์๋ ๋ณ๊ฒฝ */
[data-theme="dark"] svg {
fill: var(--text-primary);
stroke: var(--text-primary);
}
/* ์ปฌ๋ฌ ์์ด์ฝ์ ์ ์ธ */
[data-theme="dark"] .color-icon {
fill: currentColor;
}
/* ํน์ ์์ด์ฝ๋ง ์์ ์ ์ง */
[data-theme="dark"] .brand-icon {
fill: none;
stroke: none;
}
โก ์ฑ๋ฅ ์ต์ ํ
1. ์ ํ ์ ๋๋ฉ์ด์ ์ต์ ํ
๋คํฌ ๋ชจ๋ ์ ํ ์ ๋ถ๋๋ฌ์ด ์ ๋๋ฉ์ด์
์ ์ข์ง๋ง, ๋๋ฌด ๋ง์ ์์์ transition์ ์ ์ฉํ๋ฉด
์ฑ๋ฅ ๋ฌธ์ ๊ฐ ์๊ธธ ์ ์์ด. ๊ผญ ํ์ํ ์์ฑ๋ง ์ ๋๋ฉ์ด์
์ฒ๋ฆฌํ์.
/* โ ๋์ ์: ๋ชจ๋ ์์ฑ ์ ๋๋ฉ์ด์
*/
* {
transition: all 0.3s ease;
}
/* โ
์ข์ ์: ํ์ํ ์์ฑ๋ง */
body {
transition: background-color 0.3s ease, color 0.3s ease;
}
.card {
transition: background-color 0.3s ease, border-color 0.3s ease;
}
a {
transition: color 0.2s ease;
}
2. ๊น๋นก์ ๋ฐฉ์ง (FOUC ๋ฐฉ์ง)
ํ์ด์ง ๋ก๋ ์ ๋ผ์ดํธ ๋ชจ๋๊ฐ ์ ๊น ๋ณด์๋ค๊ฐ ๋คํฌ ๋ชจ๋๋ก ๋ฐ๋๋ ๊น๋นก์์ ๋ฐฉ์งํด์ผ ํด.
์ด๊ฑธ FOUC(Flash of Unstyled Content)๋ผ๊ณ ํ๋๋ฐ, ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๊ฐ๋จํด.
<!-- head ํ๊ทธ ์์ ์ธ๋ผ์ธ ์คํฌ๋ฆฝํธ ์ถ๊ฐ -->
<script>
(function() {
const theme = localStorage.getItem('theme') ||
(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
document.documentElement.setAttribute('data-theme', theme);
})();
</script>
3. CSS ๋ณ์ ํด๋ฐฑ
์ค๋๋ ๋ธ๋ผ์ฐ์ ๋ CSS ๋ณ์๋ฅผ ์ง์ํ์ง ์์ ์ ์์ด.
ํด๋ฐฑ ๊ฐ์ ์ ๊ณตํด์ ํธํ์ฑ์ ๋์ด์.
/* ํด๋ฐฑ ๊ฐ ์ ๊ณต */
body {
background-color: #ffffff; /* ํด๋ฐฑ */
background-color: var(--bg-primary);
color: #212529; /* ํด๋ฐฑ */
color: var(--text-primary);
}
/* @supports๋ก ๊ธฐ๋ฅ ๊ฐ์ง */
@supports not (--css: variables) {
body {
background-color: #ffffff;
color: #212529;
}
[data-theme="dark"] body {
background-color: #1a1a1a;
color: #e0e0e0;
}
}
๐ง ๊ณ ๊ธ ๊ธฐ๋ฅ ๊ตฌํํ๊ธฐ
๊ธฐ๋ณธ์ ์ธ ๋คํฌ ๋ชจ๋ ๊ตฌํ์ ๋ง์ณค๋ค๋ฉด, ์ด์ ์ฌ์ฉ์ ๊ฒฝํ์ ํ ๋จ๊ณ ๋ ๋์ฌ์ค
๊ณ ๊ธ ๊ธฐ๋ฅ๋ค์ ์ถ๊ฐํด๋ณด์! ์ด๋ฐ ๊ธฐ๋ฅ๋ค์ด ์์ผ๋ฉด ๋ค ์ฌ์ดํธ๊ฐ ํจ์ฌ ํ๋กํ์
๋ํด ๋ณด์ผ ๊ฑฐ์ผ. ๐
๐ ์๊ฐ ๊ธฐ๋ฐ ์๋ ์ ํ
์ฌ์ฉ์์ ํ์ฌ ์๊ฐ์ ๋ฐ๋ผ ์๋์ผ๋ก ๋คํฌ ๋ชจ๋๋ฅผ ์ผ๊ณ ๋๋ ๊ธฐ๋ฅ์ด์ผ.
์๋ฅผ ๋ค์ด, ์คํ 8์๋ถํฐ ์ค์ 6์๊น์ง๋ ์๋์ผ๋ก ๋คํฌ ๋ชจ๋๋ฅผ ํ์ฑํํ๋ ๊ฑฐ์ง.
// ์๊ฐ ๊ธฐ๋ฐ ์๋ ๋คํฌ ๋ชจ๋
function autoThemeByTime() {
const hour = new Date().getHours();
const isDarkTime = hour >= 20 || hour < 6; // ์ ๋
8์ ~ ์๋ฒฝ 6์
// ์ฌ์ฉ์๊ฐ ์๋์ผ๋ก ์ค์ ํ์ง ์์์ ๋๋ง ์๋ ์ ํ
if (!localStorage.getItem('manualThemeSet')) {
const theme = isDarkTime ? 'dark' : 'light';
setTheme(theme);
}
}
// ํ์ด์ง ๋ก๋ ์ ์คํ
autoThemeByTime();
// 1์๊ฐ๋ง๋ค ์ฒดํฌ
setInterval(autoThemeByTime, 3600000);
// ํ ๊ธ ๋ฒํผ ํด๋ฆญ ์ ์๋ ์ค์ ํ๋๊ทธ
document.getElementById('theme-toggle').addEventListener('click', () => {
localStorage.setItem('manualThemeSet', 'true');
// 24์๊ฐ ํ ์๋ ๋ชจ๋๋ก ๋ณต๊ท
setTimeout(() => {
localStorage.removeItem('manualThemeSet');
}, 86400000);
});
๐ ์์น ๊ธฐ๋ฐ ์ผ๋ชฐ/์ผ์ถ ๊ฐ์ง
๋ ์ ๊ตํ๊ฒ ํ๋ ค๋ฉด, ์ฌ์ฉ์์ ์์น๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ค์ ์ผ๋ชฐ/์ผ์ถ ์๊ฐ์ ๋ง์ถฐ
๋คํฌ ๋ชจ๋๋ฅผ ์ ํํ ์๋ ์์ด. SunCalc ๊ฐ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ฉด ์ฝ๊ฒ ๊ตฌํ ๊ฐ๋ฅํด!
// Geolocation API๋ก ์์น ๊ฐ์ ธ์ค๊ธฐ
function getLocationAndSetTheme() {
if ('geolocation' in navigator) {
navigator.geolocation.getCurrentPosition(
(position) => {
const lat = position.coords.latitude;
const lon = position.coords.longitude;
// ์ผ๋ชฐ/์ผ์ถ ์๊ฐ ๊ณ์ฐ (๊ฐ๋จํ ๋ฒ์ )
const times = calculateSunTimes(lat, lon);
const now = new Date();
const isDark = now < times.sunrise || now > times.sunset;
setTheme(isDark ? 'dark' : 'light');
},
(error) => {
// ์์น ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์ผ๋ฉด ์๊ฐ ๊ธฐ๋ฐ์ผ๋ก ํด๋ฐฑ
autoThemeByTime();
}
);
}
}
// ๊ฐ๋จํ ์ผ์ถ/์ผ๋ชฐ ๊ณ์ฐ ํจ์
function calculateSunTimes(lat, lon) {
// ์ค์ ๋ก๋ SunCalc ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ ๊ถ์ฅ
// ์ฌ๊ธฐ์๋ ๊ฐ๋
๋ง ๋ณด์ฌ์ฃผ๋ ๊ฐ๋จํ ๋ฒ์
const date = new Date();
const sunrise = new Date(date);
sunrise.setHours(6, 0, 0); // ๊ฐ๋จํ 6์๋ก ์ค์
const sunset = new Date(date);
sunset.setHours(18, 0, 0); // ๊ฐ๋จํ 18์๋ก ์ค์
return { sunrise, sunset };
}
๐๏ธ ๋ฐ๊ธฐ ์กฐ์ ์ฌ๋ผ์ด๋
๋จ์ํ ๋ผ์ดํธ/๋คํฌ ๋ ๊ฐ์ง๋ง์ด ์๋๋ผ, ์ฌ์ฉ์๊ฐ ์ํ๋ ๋ฐ๊ธฐ๋ฅผ ์ง์ ์กฐ์ ํ ์ ์๊ฒ ํด๋ณด์.
์ด๊ฑด ์ ๋ง ๊ณ ๊ธ ๊ธฐ๋ฅ์ด์ผ! ๐
<!-- HTML: ๋ฐ๊ธฐ ์กฐ์ ์ฌ๋ผ์ด๋ -->
<div class="brightness-control">
<label for="brightness-slider">๋ฐ๊ธฐ ์กฐ์ </label>
<input type="range"
id="brightness-slider"
min="0"
max="100"
value="50">
<span id="brightness-value">50%</span>
</div>
<script>
// ๋ฐ๊ธฐ ์กฐ์ ๊ธฐ๋ฅ
const brightnessSlider = document.getElementById('brightness-slider');
const brightnessValue = document.getElementById('brightness-value');
brightnessSlider.addEventListener('input', (e) => {
const brightness = e.target.value;
brightnessValue.textContent = brightness + '%';
// CSS ๋ณ์๋ก ๋ฐ๊ธฐ ์กฐ์
const lightness = brightness / 100;
document.documentElement.style.setProperty('--brightness-factor', lightness);
// ๋ก์ปฌ ์คํ ๋ฆฌ์ง์ ์ ์ฅ
localStorage.setItem('brightness', brightness);
});
// ํ์ด์ง ๋ก๋ ์ ์ ์ฅ๋ ๋ฐ๊ธฐ ์ ์ฉ
const savedBrightness = localStorage.getItem('brightness') || 50;
brightnessSlider.value = savedBrightness;
brightnessValue.textContent = savedBrightness + '%';
document.documentElement.style.setProperty('--brightness-factor', savedBrightness / 100);
</script>
<style>
/* CSS์์ ๋ฐ๊ธฐ ํฉํฐ ํ์ฉ */
:root {
--brightness-factor: 1;
}
[data-theme="dark"] {
--bg-primary: hsl(0, 0%, calc(10% * var(--brightness-factor)));
--bg-secondary: hsl(0, 0%, calc(18% * var(--brightness-factor)));
--text-primary: hsl(0, 0%, calc(88% * var(--brightness-factor)));
}
</style>
๐จ ์ปค์คํ ํ ๋ง ํ๋ฆฌ์
๋ผ์ดํธ/๋คํฌ๋ง์ด ์๋๋ผ, ์ฌ๋ฌ ๊ฐ์ง ์์ ํ
๋ง๋ฅผ ์ ๊ณตํ ์๋ ์์ด.
์๋ฅผ ๋ค์ด, "๋คํฌ ๋ธ๋ฃจ", "๋คํฌ ํผํ", "์ธํผ์" ๊ฐ์ ์ต์
๋ค ๋ง์ด์ผ.
// ํ
๋ง ํ๋ฆฌ์
์ ์
const themePresets = {
light: {
'--bg-primary': '#ffffff',
'--bg-secondary': '#f8f9fa',
'--text-primary': '#212529',
'--accent-color': '#0d6efd'
},
dark: {
'--bg-primary': '#1a1a1a',
'--bg-secondary': '#2d2d2d',
'--text-primary': '#e0e0e0',
'--accent-color': '#64b5f6'
},
'dark-blue': {
'--bg-primary': '#0a1929',
'--bg-secondary': '#132f4c',
'--text-primary': '#b2bac2',
'--accent-color': '#3399ff'
},
'dark-purple': {
'--bg-primary': '#1a0a2e',
'--bg-secondary': '#2d1b4e',
'--text-primary': '#d4c5f9',
'--accent-color': '#a78bfa'
},
sepia: {
'--bg-primary': '#f4ecd8',
'--bg-secondary': '#e8dcc4',
'--text-primary': '#5c4a3a',
'--accent-color': '#8b6f47'
}
};
// ํ
๋ง ์ ์ฉ ํจ์
function applyThemePreset(presetName) {
const preset = themePresets[presetName];
if (!preset) return;
const root = document.documentElement;
Object.keys(preset).forEach(property => {
root.style.setProperty(property, preset[property]);
});
localStorage.setItem('themePreset', presetName);
}
// ํ
๋ง ์ ํ UI
function createThemeSelector() {
const selector = document.createElement('div');
selector.className = 'theme-selector';
selector.innerHTML = `
<button data-theme="light">โ๏ธ Light</button>
<button data-theme="dark">๐ Dark</button>
<button data-theme="dark-blue">๐ Ocean</button>
<button data-theme="dark-purple">๐ฎ Purple</button>
<button data-theme="sepia">๐ Sepia</button>
`;
selector.querySelectorAll('button').forEach(btn => {
btn.addEventListener('click', () => {
applyThemePreset(btn.dataset.theme);
});
});
return selector;
}
๐ฑ ๋ชจ๋ฐ์ผ ์ ์ค์ฒ ์ง์
๋ชจ๋ฐ์ผ์์๋ ์ค์์ดํ ์ ์ค์ฒ๋ก ๋คํฌ ๋ชจ๋๋ฅผ ์ ํํ ์ ์๊ฒ ํ๋ฉด ํธ๋ฆฌํด.
ํ๋ฉด ์๋จ์์ ์๋๋ก ์ค์์ดํํ๋ฉด ๋คํฌ ๋ชจ๋๊ฐ ํ ๊ธ๋๋ ์์ด์ง.
// ํฐ์น ์ด๋ฒคํธ๋ก ์ค์์ดํ ๊ฐ์ง
let touchStartY = 0;
let touchEndY = 0;
document.addEventListener('touchstart', (e) => {
touchStartY = e.changedTouches[0].screenY;
}, { passive: true });
document.addEventListener('touchend', (e) => {
touchEndY = e.changedTouches[0].screenY;
handleSwipe();
}, { passive: true });
function handleSwipe() {
const swipeDistance = touchEndY - touchStartY;
const minSwipeDistance = 100; // ์ต์ ์ค์์ดํ ๊ฑฐ๋ฆฌ
// ํ๋ฉด ์๋จ 20% ์์ญ์์๋ง ์๋
if (touchStartY < window.innerHeight * 0.2) {
if (swipeDistance > minSwipeDistance) {
// ์๋๋ก ์ค์์ดํ: ๋คํฌ ๋ชจ๋ ํ ๊ธ
toggleTheme();
// ํ
ํฑ ํผ๋๋ฐฑ (์ง์ํ๋ ๊ธฐ๊ธฐ์์)
if ('vibrate' in navigator) {
navigator.vibrate(50);
}
}
}
}
๐ ๋คํฌ ๋ชจ๋ ์ ํ ์๋ฆผ
๋คํฌ ๋ชจ๋๊ฐ ์ ํ๋ ๋ ์ฌ์ฉ์์๊ฒ ๋ถ๋๋ฌ์ด ์๋ฆผ์ ๋ณด์ฌ์ฃผ๋ฉด ์ข์.
ํ ์คํธ ๋ฉ์์ง๋ ๊ฐ๋จํ ์ ๋๋ฉ์ด์
์ผ๋ก ํผ๋๋ฐฑ์ ์ ๊ณตํ๋ ๊ฑฐ์ง.
// ํ ์คํธ ์๋ฆผ ํจ์
function showThemeToast(theme) {
const toast = document.createElement('div');
toast.className = 'theme-toast';
toast.innerHTML = `
<span class="toast-icon">${theme === 'dark' ? '๐' : 'โ๏ธ'}</span>
<span class="toast-text">${theme === 'dark' ? '๋คํฌ' : '๋ผ์ดํธ'} ๋ชจ๋ ํ์ฑํ</span>
`;
document.body.appendChild(toast);
// ์ ๋๋ฉ์ด์
setTimeout(() => toast.classList.add('show'), 10);
setTimeout(() => {
toast.classList.remove('show');
setTimeout(() => toast.remove(), 300);
}, 2000);
}
// CSS
<style>
.theme-toast {
position: fixed;
bottom: -100px;
left: 50%;
transform: translateX(-50%);
background: var(--bg-secondary);
color: var(--text-primary);
padding: 12px 24px;
border-radius: 24px;
box-shadow: 0 4px 12px var(--shadow);
display: flex;
align-items: center;
gap: 10px;
transition: bottom 0.3s ease;
z-index: 9999;
}
.theme-toast.show {
bottom: 30px;
}
.toast-icon {
font-size: 20px;
}
.toast-text {
font-size: 14px;
font-weight: 500;
}
</style>
๐พ ํด๋ผ์ฐ๋ ๋๊ธฐํ
์ฌ์ฉ์๊ฐ ์ฌ๋ฌ ๊ธฐ๊ธฐ๋ฅผ ์ฌ์ฉํ๋ค๋ฉด, ๋คํฌ ๋ชจ๋ ์ค์ ์ ๋๊ธฐํํด์ฃผ๋ฉด ์ข๊ฒ ์ง?
์๋ํ๋ ์ค ์ฌ์ฉ์ ๋ฉํ๋ฐ์ดํฐ๋ฅผ ํ์ฉํ๋ฉด ๋ก๊ทธ์ธํ ์ฌ์ฉ์์ ์ค์ ์ ์ ์ฅํ ์ ์์ด.
// PHP: ์ฌ์ฉ์ ํ
๋ง ์ค์ ์ ์ฅ
function save_user_theme_preference() {
check_ajax_referer('theme_nonce', 'nonce');
if (is_user_logged_in()) {
$user_id = get_current_user_id();
$theme = sanitize_text_field($_POST['theme']);
update_user_meta($user_id, 'preferred_theme', $theme);
wp_send_json_success();
} else {
wp_send_json_error('User not logged in');
}
}
add_action('wp_ajax_save_theme', 'save_user_theme_preference');
// JavaScript: ํ
๋ง ๋ณ๊ฒฝ ์ ์๋ฒ์ ์ ์ฅ
function setTheme(theme) {
document.documentElement.setAttribute('data-theme', theme);
localStorage.setItem('theme', theme);
// ๋ก๊ทธ์ธํ ์ฌ์ฉ์๋ผ๋ฉด ์๋ฒ์๋ ์ ์ฅ
if (typeof wpAjax !== 'undefined') {
fetch(wpAjax.ajaxurl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
action: 'save_theme',
theme: theme,
nonce: wpAjax.nonce
})
});
}
}
๐ ๋ฌธ์ ํด๊ฒฐ ๋ฐ ๋๋ฒ๊น
๋คํฌ ๋ชจ๋๋ฅผ ๊ตฌํํ๋ค ๋ณด๋ฉด ์์์น ๋ชปํ ๋ฌธ์ ๋ค์ด ์๊ธธ ์ ์์ด.
์์ฃผ ๋ฐ์ํ๋ ๋ฌธ์ ๋ค๊ณผ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์์๋ณด์! ๐
โ ์์ฃผ ๋ฐ์ํ๋ ๋ฌธ์ ๋ค
1. ํน์ ์์๊ฐ ๋คํฌ ๋ชจ๋์์ ์ ๋ณด์
๋คํฌ ๋ชจ๋๋ก ์ ํํ๋๋ฐ ์ผ๋ถ ํ ์คํธ๋ ์์ด์ฝ์ด ๊ฒ์์ ๋ฐฐ๊ฒฝ์ ๊ฒ์์์ผ๋ก ๋์์ ์ ๋ณด์ฌ.
์์ธ:
ํด๋น ์์์ ํ๋์ฝ๋ฉ๋ ์์ ๊ฐ์ด ์๊ฑฐ๋, CSS ์ฐ์ ์์ ๋ฌธ์ .
ํด๊ฒฐ ๋ฐฉ๋ฒ:
/* ๋ฌธ์ ๊ฐ ๋๋ ์์ ์ฐพ๊ธฐ */
[data-theme="dark"] * {
outline: 1px solid red; /* ์์๋ก ๋ชจ๋ ์์์ ํ
๋๋ฆฌ */
}
/* ํน์ ์์ ๊ฐ์ ์คํ์ผ ์ ์ฉ */
[data-theme="dark"] .problem-element {
color: var(--text-primary) !important;
background-color: var(--bg-primary) !important;
}
/* ๋๋ CSS ๋ณ์ ์ฌ์ฉํ๋๋ก ์์ */
.problem-element {
color: var(--text-primary);
background-color: var(--bg-primary);
}
2. ์ด๋ฏธ์ง๊ฐ ๋๋ฌด ๋ฐ์์ ๋์ด ๋ถ์ฌ
๋คํฌ ๋ชจ๋์์ ๋ฐ์ ์ด๋ฏธ์ง๋ค์ด ๋๋ฌด ํ์ด ๋ณด์ด๊ณ ๋์ด ๋ถ์ .
ํด๊ฒฐ ๋ฐฉ๋ฒ:
/* ๋ชจ๋ ์ด๋ฏธ์ง ๋ฐ๊ธฐ ์กฐ์ */
[data-theme="dark"] img:not(.no-filter) {
filter: brightness(0.8) contrast(1.1);
}
/* ํน์ ์ด๋ฏธ์ง๋ ์ ์ธ */
[data-theme="dark"] .logo,
[data-theme="dark"] .product-image {
filter: none;
}
/* ํธ๋ฒ ์ ์๋ ๋ฐ๊ธฐ */
[data-theme="dark"] img:hover {
filter: brightness(1) contrast(1);
transition: filter 0.3s ease;
}
3. ํ๋ฌ๊ทธ์ธ/ํ ๋ง ์ถฉ๋
๋คํฌ ๋ชจ๋ ํ๋ฌ๊ทธ์ธ์ ์ค์นํ๋๋ฐ ๋ค๋ฅธ ํ๋ฌ๊ทธ์ธ์ด๋ ํ ๋ง์ ์ถฉ๋ํด์ ๋ ์ด์์์ด ๊นจ์ ธ.
ํด๊ฒฐ ๋ฐฉ๋ฒ:
1. ํ๋ฌ๊ทธ์ธ์ ํ๋์ฉ ๋นํ์ฑํํ๋ฉด์ ์์ธ ์ฐพ๊ธฐ
2. ๋ธ๋ผ์ฐ์ ๊ฐ๋ฐ์ ๋๊ตฌ(F12)๋ก CSS ์ถฉ๋ ํ์ธ
3. ๋คํฌ ๋ชจ๋ ํ๋ฌ๊ทธ์ธ ์ค์ ์์ ํน์ ์์ ์ ์ธ
4. ์ปค์คํ CSS๋ก ๋ฌธ์ ์์ ์์
/* WP Dark Mode ํ๋ฌ๊ทธ์ธ์์ ํน์ ์์ ์ ์ธ */
.wp-dark-mode-ignore {
/* ์ด ํด๋์ค๋ฅผ ๊ฐ์ง ์์๋ ๋คํฌ ๋ชจ๋ ์ ์ฉ ์ ๋จ */
}
/* ๋๋ ํ๋ฌ๊ทธ์ธ ์ค์ ์์ CSS ์ ํ์๋ก ์ ์ธ */
/* Settings > Advanced > Excludes์ ์ถ๊ฐ */
.elementor-widget, .woocommerce-product
4. ํ์ด์ง ๋ก๋ ์ ๊น๋นก์ (FOUC)
ํ์ด์ง๋ฅผ ์๋ก๊ณ ์นจํ๋ฉด ์ ๊น ๋ผ์ดํธ ๋ชจ๋๊ฐ ๋ณด์๋ค๊ฐ ๋คํฌ ๋ชจ๋๋ก ๋ฐ๋๋ฉด์ ๊น๋นก์ฌ.
ํด๊ฒฐ ๋ฐฉ๋ฒ:
<!-- head ํ๊ทธ ์ต์๋จ์ ์ธ๋ผ์ธ ์คํฌ๋ฆฝํธ ์ถ๊ฐ -->
<head>
<script>
(function() {
const theme = localStorage.getItem('theme');
if (theme) {
document.documentElement.setAttribute('data-theme', theme);
}
})();
</script>
<!-- ๋๋จธ์ง head ๋ด์ฉ -->
</head>
<!-- ๋๋ CSS๋ก ์ด๊ธฐ ๋ก๋ฉ ์จ๊ธฐ๊ธฐ -->
<style>
html:not([data-theme]) {
visibility: hidden;
}
html[data-theme] {
visibility: visible;
}
</style>
5. ๋ชจ๋ฐ์ผ์์ ์ฑ๋ฅ ์ ํ
๋คํฌ ๋ชจ๋ ์ ํ ์ ๋ชจ๋ฐ์ผ์์ ๋ฒ๋ฒ ๊ฑฐ๋ฆฌ๊ฑฐ๋ ๋๋ ค์ ธ.
ํด๊ฒฐ ๋ฐฉ๋ฒ:
/* GPU ๊ฐ์ ํ์ฉ */
[data-theme] {
will-change: background-color, color;
transform: translateZ(0);
}
/* ๋ถํ์ํ transition ์ ๊ฑฐ */
@media (prefers-reduced-motion: reduce) {
* {
transition: none !important;
}
}
/* ๋ชจ๋ฐ์ผ์์ transition ๊ฐ์ํ */
@media (max-width: 768px) {
* {
transition-duration: 0.15s !important;
}
}
๐ ๋๋ฒ๊น ๋๊ตฌ ํ์ฉ
๋ธ๋ผ์ฐ์ ๊ฐ๋ฐ์ ๋๊ตฌ
2. Console ํญ: getComputedStyle(element)๋ก CSS ๋ณ์ ๊ฐ ํ์ธ
3. Network ํญ: CSS ํ์ผ ๋ก๋ฉ ์์์ ์๊ฐ ํ์ธ
4. Performance ํญ: ๋คํฌ ๋ชจ๋ ์ ํ ์ ์ฑ๋ฅ ์ธก์
5. Lighthouse: ์ ๊ทผ์ฑ ์ ์ ํ์ธ
// Console์์ ์ ์ฉํ ๋๋ฒ๊น
๋ช
๋ น์ด
// ํ์ฌ ํ
๋ง ํ์ธ
console.log(document.documentElement.getAttribute('data-theme'));
// CSS ๋ณ์ ๊ฐ ํ์ธ
const root = document.documentElement;
const bgColor = getComputedStyle(root).getPropertyValue('--bg-primary');
console.log('Background color:', bgColor);
// ๋ชจ๋ CSS ๋ณ์ ์ถ๋ ฅ
const allStyles = getComputedStyle(root);
const cssVars = Array.from(allStyles).filter(prop => prop.startsWith('--'));
cssVars.forEach(prop => {
console.log(prop, ':', allStyles.getPropertyValue(prop));
});
// ๋คํฌ ๋ชจ๋ ์ง์ ์ฌ๋ถ ํ์ธ
console.log('Prefers dark:', window.matchMedia('(prefers-color-scheme: dark)').matches);
๐งช ํ ์คํธ ์ฒดํฌ๋ฆฌ์คํธ
- โ๏ธ ๋ชจ๋ ํ์ด์ง์์ ํ ์คํธ๊ฐ ์ ๋ณด์ด๋๊ฐ?
- โ๏ธ ๋ฒํผ๊ณผ ๋งํฌ์ ํธ๋ฒ ์ํ๊ฐ ๋ช ํํ๊ฐ?
- โ๏ธ ํผ ์ ๋ ฅ ํ๋๊ฐ ์ ๋ณด์ด๊ณ ์ฌ์ฉ ๊ฐ๋ฅํ๊ฐ?
- โ๏ธ ์ด๋ฏธ์ง์ ์์ด์ฝ์ด ์ ์ ํ ๋ฐ๊ธฐ์ธ๊ฐ?
- โ๏ธ ๊ทธ๋ฆผ์์ ํ ๋๋ฆฌ๊ฐ ์ ๋ณด์ด๋๊ฐ?
- โ๏ธ ๋ชจ๋ฐ์ผ์์๋ ์ ์๋ํ๋๊ฐ?
- โ๏ธ ํ์ด์ง ๋ก๋ ์ ๊น๋นก์์ด ์๋๊ฐ?
- โ๏ธ ์ฌ์ฉ์ ์ ํ์ด ์ ์ฅ๋๊ณ ์ ์ง๋๋๊ฐ?
- โ๏ธ ์ ๊ทผ์ฑ ๊ธฐ์ค(WCAG)์ ์ถฉ์กฑํ๋๊ฐ?
- โ๏ธ ์ฃผ์ ๋ธ๋ผ์ฐ์ ์์ ๋ชจ๋ ์๋ํ๋๊ฐ?
- โ๏ธ ํ๋ฌ๊ทธ์ธ/ํ ๋ง์ ์ถฉ๋์ด ์๋๊ฐ?
- โ๏ธ ์ฑ๋ฅ ์ ํ๊ฐ ์๋๊ฐ?
โฟ ์ ๊ทผ์ฑ ๊ณ ๋ ค์ฌํญ
๋คํฌ ๋ชจ๋๋ ๋จ์ํ '๋ฉ์์ด ๋ณด์ด๋' ๊ธฐ๋ฅ์ด ์๋๋ผ, ์ ๊ทผ์ฑ์ ๋์ด๋ ์ค์ํ ๋๊ตฌ์ผ.
๋ชจ๋ ์ฌ์ฉ์๊ฐ ํธํ๊ฒ ์ฌ์ฉํ ์ ์๋๋ก ์ ๊ทผ์ฑ์ ๊ณ ๋ คํด์ผ ํด. ๐
๐ฏ WCAG ๊ฐ์ด๋๋ผ์ธ ์ค์
๋ช ์๋น(Contrast Ratio) ๊ธฐ์ค
- ์ผ๋ฐ ํ ์คํธ: 4.5:1
- ํฐ ํ ์คํธ (18pt ์ด์): 3:1
โข AAA ๋ฑ๊ธ (๊ถ์ฅ):
- ์ผ๋ฐ ํ ์คํธ: 7:1
- ํฐ ํ ์คํธ: 4.5:1
๐ก ๋คํฌ ๋ชจ๋์์๋ AAA ๋ฑ๊ธ์ ๋ชฉํ๋ก ํ๋ ๊ฒ ์ข์!
๋ช ์๋น ํ์ธ ๋๊ตฌ
- ๊ฐ์ฅ ๊ฐ๋จํ๊ณ ์ง๊ด์ ์ธ ์จ๋ผ์ธ ๋๊ตฌ
2. Colour Contrast Analyser (CCA)
- ๋ฐ์คํฌํฑ ์ฑ, ํ๋ฉด์ ์ด๋ค ์์์ด๋ ์ธก์ ๊ฐ๋ฅ
3. Chrome DevTools
- Elements ํญ์์ ์์ ์ ํ ์ ๋ช ์๋น ์๋ ํ์
4. Stark ํ๋ฌ๊ทธ์ธ (Figma, Sketch)
- ๋์์ธ ๋จ๊ณ์์ ๋ช ์๋น ํ์ธ
๐ค ํค๋ณด๋ ๋ค๋น๊ฒ์ด์
๋คํฌ ๋ชจ๋ ํ ๊ธ ๋ฒํผ์ ํค๋ณด๋๋ก๋ ์ ๊ทผ ๊ฐ๋ฅํด์ผ ํด.
๋ง์ฐ์ค๋ฅผ ์ฌ์ฉํ ์ ์๋ ์ฌ์ฉ์๋ค์ ์ํด์ ๋ง์ด์ผ.
<!-- ์ ๊ทผ ๊ฐ๋ฅํ ํ ๊ธ ๋ฒํผ -->
<button
id="theme-toggle"
class="theme-toggle-btn"
aria-label="๋คํฌ ๋ชจ๋ ์ ํ"
aria-pressed="false"
type="button"
tabindex="0">
<span aria-hidden="true">๐</span>
<span class="sr-only">๋คํฌ ๋ชจ๋๋ก ์ ํ</span>
</button>
<!-- ์คํฌ๋ฆฐ ๋ฆฌ๋ ์ ์ฉ ํ
์คํธ -->
<style>
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
</style>
<script>
// ํค๋ณด๋ ๋จ์ถํค ์ง์ (Ctrl + Shift + D)
document.addEventListener('keydown', (e) => {
if (e.ctrlKey && e.shiftKey && e.key === 'D') {
e.preventDefault();
toggleTheme();
// ์คํฌ๋ฆฐ ๋ฆฌ๋์ ์๋ฆผ
announceToScreenReader(
`${currentTheme === 'dark' ? '๋คํฌ' : '๋ผ์ดํธ'} ๋ชจ๋๋ก ์ ํ๋์์ต๋๋ค`
);
}
});
// ์คํฌ๋ฆฐ ๋ฆฌ๋ ์๋ฆผ ํจ์
function announceToScreenReader(message) {
const announcement = document.createElement('div');
announcement.setAttribute('role', 'status');
announcement.setAttribute('aria-live', 'polite');
announcement.className = 'sr-only';
announcement.textContent = message;
document.body.appendChild(announcement);
setTimeout(() => announcement.remove(), 1000);
}
// ๋ฒํผ ์ํ ์
๋ฐ์ดํธ
function updateToggleButton(theme) {
const button = document.getElementById('theme-toggle');
button.setAttribute('aria-pressed', theme === 'dark');
button.setAttribute('aria-label',
theme === 'dark' ? '๋ผ์ดํธ ๋ชจ๋๋ก ์ ํ' : '๋คํฌ ๋ชจ๋๋ก ์ ํ'
);
}
</script>
๐จ ํฌ์ปค์ค ์ธ๋์ผ์ดํฐ
ํค๋ณด๋๋ก ํ์ํ ๋ ํ์ฌ ํฌ์ปค์ค๋ ์์๊ฐ ๋ช
ํํ ๋ณด์ฌ์ผ ํด.
๋คํฌ ๋ชจ๋์์๋ ํฌ์ปค์ค ํ์๊ฐ ์ ๋ณด์ด๋๋ก ํด์ผ์ง.
/* ์ ๊ทผ ๊ฐ๋ฅํ ํฌ์ปค์ค ์คํ์ผ */
:focus {
outline: 2px solid var(--focus-color);
outline-offset: 2px;
}
/* ๋คํฌ ๋ชจ๋ ํฌ์ปค์ค ์์ */
:root {
--focus-color: #0d6efd;
}
[data-theme="dark"] {
--focus-color: #64b5f6;
}
/* ๋ฒํผ ํฌ์ปค์ค ์คํ์ผ */
button:focus-visible {
outline: 3px solid var(--focus-color);
outline-offset: 3px;
box-shadow: 0 0 0 4px rgba(100, 181, 246, 0.2);
}
/* ๋งํฌ ํฌ์ปค์ค ์คํ์ผ */
a:focus-visible {
outline: 2px solid var(--focus-color);
outline-offset: 2px;
background-color: rgba(100, 181, 246, 0.1);
border-radius: 2px;
}
/* ๋ง์ฐ์ค ํด๋ฆญ ์์๋ ํฌ์ปค์ค ํ์ ์ ํจ */
:focus:not(:focus-visible) {
outline: none;
}
๐ ์คํฌ๋ฆฐ ๋ฆฌ๋ ์ง์
์๊ฐ ์ฅ์ ์ธ ์ฌ์ฉ์๋ฅผ ์ํด ์คํฌ๋ฆฐ ๋ฆฌ๋๊ฐ ๋คํฌ ๋ชจ๋ ์ํ๋ฅผ ์ฝ์ ์ ์์ด์ผ ํด.
<!-- ARIA ๋ผ์ด๋ธ ๋ฆฌ์ -->
<div id="theme-status"
role="status"
aria-live="polite"
aria-atomic="true"
class="sr-only">
</div>
<script>
function setTheme(theme) {
document.documentElement.setAttribute('data-theme', theme);
localStorage.setItem('theme', theme);
// ์คํฌ๋ฆฐ ๋ฆฌ๋์ ์๋ฆผ
const status = document.getElementById('theme-status');
status.textContent = `${theme === 'dark' ? '๋คํฌ' : '๋ผ์ดํธ'} ๋ชจ๋๊ฐ ํ์ฑํ๋์์ต๋๋ค.`;
// ๋ฒํผ ์ํ ์
๋ฐ์ดํธ
updateToggleButton(theme);
}
</script>
๐ ๋ค๊ตญ์ด ์ง์
๋ค์ํ ์ธ์ด์ ์ฌ์ฉ์๋ฅผ ์ํด ๋ค๊ตญ์ด๋ฅผ ์ง์ํ๋ฉด ์ข์.
์๋ํ๋ ์ค์ ๋ฒ์ญ ๊ธฐ๋ฅ์ ํ์ฉํ ์ ์์ด.
// PHP: ๋ฒ์ญ ๊ฐ๋ฅํ ํ
์คํธ
function add_dark_mode_toggle() {
$light_label = __('๋ผ์ดํธ ๋ชจ๋๋ก ์ ํ', 'your-theme');
$dark_label = __('๋คํฌ ๋ชจ๋๋ก ์ ํ', 'your-theme');
echo '<button id="theme-toggle"
class="theme-toggle-btn"
aria-label="' . esc_attr($dark_label) . '"
data-light-label="' . esc_attr($light_label) . '"
data-dark-label="' . esc_attr($dark_label) . '"
type="button">
๐
</button>';
}
// JavaScript: ๋ผ๋ฒจ ์
๋ฐ์ดํธ
function updateToggleButton(theme) {
const button = document.getElementById('theme-toggle');
const label = theme === 'dark'
? button.dataset.lightLabel
: button.dataset.darkLabel;
button.setAttribute('aria-label', label);
}
โก ์ ๋๋ฉ์ด์ ๊ฐ์ ๋ชจ๋
์ผ๋ถ ์ฌ์ฉ์๋ ์ ๋๋ฉ์ด์
์ด ๋ถํธํ๊ฑฐ๋ ์ด์ง๋ฌ์์ ๋๋ ์ ์์ด.
์์คํ
์ค์ ์ "์ ๋๋ฉ์ด์
๊ฐ์" ์ต์
์ ์กด์คํด์ผ ํด.
/* ์ ๋๋ฉ์ด์
๊ฐ์ ๋ชจ๋ ์ง์ */
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
scroll-behavior: auto !important;
}
}
/* JavaScript๋ก๋ ํ์ธ ๊ฐ๋ฅ */
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
function setTheme(theme) {
document.documentElement.setAttribute('data-theme', theme);
if (!prefersReducedMotion) {
// ์ ๋๋ฉ์ด์
์คํ
playThemeTransitionAnimation();
}
}
๐ ์ฑ๋ฅ ์ต์ ํ
๋คํฌ ๋ชจ๋๊ฐ ์๋ฌด๋ฆฌ ๋ฉ์ ธ๋ ์ฌ์ดํธ ์๋๋ฅผ ๋๋ฆฌ๊ฒ ๋ง๋ค๋ฉด ์ ๋๊ฒ ์ง?
์ฑ๋ฅ์ ์ต์ ํํ๋ ๋ฐฉ๋ฒ๋ค์ ์์๋ณด์! โก
๐ CSS ์ต์ ํ
1. CSS ๋ณ์ vs ์ค๋ณต ์คํ์ผ
/* ๋ชจ๋ ์์๋ง๋ค ๋คํฌ ๋ชจ๋ ์คํ์ผ ์ค๋ณต */
.header { background: #fff; color: #000; }
[data-theme="dark"] .header { background: #1a1a1a; color: #e0e0e0; }
.card { background: #fff; color: #000; }
[data-theme="dark"] .card { background: #1a1a1a; color: #e0e0e0; }
.button { background: #fff; color: #000; }
[data-theme="dark"] .button { background: #1a1a1a; color: #e0e0e0; }
โ
ํจ์จ์ ์ธ ๋ฐฉ๋ฒ:/* CSS ๋ณ์๋ก ํ ๋ฒ๋ง ์ ์ */
:root {
--bg: #fff;
--text: #000;
}
[data-theme="dark"] {
--bg: #1a1a1a;
--text: #e0e0e0;
}
.header, .card, .button {
background: var(--bg);
color: var(--text);
}
๐ CSS ํ์ผ ํฌ๊ธฐ๊ฐ ์ฝ 40-60% ๊ฐ์!
2. Critical CSS ์ธ๋ผ์ธํ
๋คํฌ ๋ชจ๋ ๊ด๋ จ ํต์ฌ CSS๋ HTML์ ์ธ๋ผ์ธ์ผ๋ก ๋ฃ์ด์ ๊น๋นก์์ ๋ฐฉ์งํ๊ณ ์ด๊ธฐ ๋ก๋ฉ์ ๋น ๋ฅด๊ฒ ํด.
<head>
<style>
/* Critical CSS: ๋คํฌ ๋ชจ๋ ๊ธฐ๋ณธ ๋ณ์ */
:root{--bg:#fff;--text:#000}
[data-theme="dark"]{--bg:#1a1a1a;--text:#e0e0e0}
body{background:var(--bg);color:var(--text);transition:background .3s,color .3s}
</style>
<!-- ๋๋จธ์ง CSS๋ ๋น๋๊ธฐ ๋ก๋ -->
<link rel="preload" href="style.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="style.css"></noscript>
</head>
โ๏ธ JavaScript ์ต์ ํ
1. ๋๋ฐ์ด์ฑ๊ณผ ์ฐ๋กํ๋ง
ํ ๋ง ์ ํ์ด๋ ์คํฌ๋กค ์ด๋ฒคํธ์์ ๋ถํ์ํ ํจ์ ํธ์ถ์ ์ค์ฌ์ผ ํด.
// ๋๋ฐ์ด์ค ํจ์
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// ์ฐ๋กํ ํจ์
function throttle(func, limit) {
let inThrottle;
return function(...args) {
if (!inThrottle) {
func.apply(this, args);
inThrottle = true;
setTimeout(() => inThrottle = false, limit);
}
};
}
// ์ฌ์ฉ ์์
const handleResize = debounce(() => {
adjustThemeForViewport();
}, 250);
window.addEventListener('resize', handleResize);
2. ์ด๋ฒคํธ ์์
์ฌ๋ฌ ์์์ ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ฅผ ๋ถ์ด๋ ๋์ , ๋ถ๋ชจ ์์ ํ๋์๋ง ๋ถ์ฌ์ ์ฑ๋ฅ์ ๋์ฌ.
// โ ๋นํจ์จ์ : ๊ฐ ๋ฒํผ๋ง๋ค ๋ฆฌ์ค๋
document.querySelectorAll('.theme-option').forEach(btn => {
btn.addEventListener('click', handleThemeChange);
});
// โ
ํจ์จ์ : ๋ถ๋ชจ์ ํ๋๋ง
document.querySelector('.theme-selector').addEventListener('click', (e) => {
if (e.target.matches('.theme-option')) {
handleThemeChange(e);
}
});
๐พ ๋ก์ปฌ ์คํ ๋ฆฌ์ง ์ต์ ํ
1. ์ ์ฅ ๋น๋ ์ ํ
// ํ
๋ง ๋ณ๊ฒฝ ์๋ง๋ค ์ ์ฅํ์ง ๋ง๊ณ , ๋๋ฐ์ด์ค ์ ์ฉ
const saveTheme = debounce((theme) => {
localStorage.setItem('theme', theme);
localStorage.setItem('themeTimestamp', Date.now());
}, 500);
function setTheme(theme) {
document.documentElement.setAttribute('data-theme', theme);
saveTheme(theme);
}
2. ์คํ ๋ฆฌ์ง ํฌ๊ธฐ ๊ด๋ฆฌ
// ์ค๋๋ ์ค์ ์ ๋ฆฌ
function cleanupOldSettings() {
const timestamp = localStorage.getItem('themeTimestamp');
const thirtyDaysAgo = Date.now() - (30 * 24 * 60 * 60 * 1000);
if (timestamp && parseInt(timestamp) < thirtyDaysAgo) {
// 30์ผ ์ด์ ๋ ์ค์ ์ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ๋ฆฌ์
localStorage.removeItem('theme');
localStorage.removeItem('themeTimestamp');
}
}
// ํ์ด์ง ๋ก๋ ์ ์คํ
cleanupOldSettings();
๐ผ๏ธ ์ด๋ฏธ์ง ์ต์ ํ
๋ฐ์ํ ์ด๋ฏธ์ง์ ๋คํฌ ๋ชจ๋
<!-- picture ํ๊ทธ๋ก ๋คํฌ ๋ชจ๋ ์ ์ฉ ์ด๋ฏธ์ง ์ ๊ณต -->
<picture>
<source
srcset="hero-dark.webp"
media="(prefers-color-scheme: dark)"
type="image/webp">
<source
srcset="hero-light.webp"
media="(prefers-color-scheme: light)"
type="image/webp">
<img src="hero-light.jpg" alt="Hero image" loading="lazy">
</picture>
<!-- JavaScript๋ก ๋์ ์ ํ -->
<script>
function updateImages(theme) {
document.querySelectorAll('img[data-light-src][data-dark-src]').forEach(img => {
const src = theme === 'dark' ? img.dataset.darkSrc : img.dataset.lightSrc;
if (img.src !== src) {
img.src = src;
}
});
}
</script>
๐ฆ ์ฝ๋ ์คํ๋ฆฌํ
๋คํฌ ๋ชจ๋ ๊ด๋ จ ์ฝ๋๋ฅผ ๋ณ๋ ํ์ผ๋ก ๋ถ๋ฆฌํด์ ํ์ํ ๋๋ง ๋ก๋ํ์.
// ๋์ import๋ก ํ์ํ ๋๋ง ๋ก๋
async function loadAdvancedThemeFeatures() {
if (userWantsAdvancedFeatures) {
const { initAdvancedTheme } = await import('./advanced-theme.js');
initAdvancedTheme();
}
}
// ๋๋ Intersection Observer๋ก ๋ทฐํฌํธ์ ๋ค์ด์ฌ ๋ ๋ก๋
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
loadAdvancedThemeFeatures();
observer.disconnect();
}
});
});
observer.observe(document.querySelector('.theme-settings'));
๐ ์ฑ๋ฅ ์ธก์
- ์ ์ฒด์ ์ธ ์ฑ๋ฅ, ์ ๊ทผ์ฑ, SEO ์ ์
- ๋คํฌ ๋ชจ๋ ์ ํ ๋น๊ต
2. WebPageTest
- ์ค์ ์ฌ์ฉ์ ํ๊ฒฝ์์์ ๋ก๋ฉ ์๋
- ๋ค์ํ ๊ธฐ๊ธฐ์ ๋คํธ์ํฌ ์กฐ๊ฑด ํ ์คํธ
3. Chrome Performance ํญ
- ํ ๋ง ์ ํ ์ ํ๋ ์ ๋๋กญ ํ์ธ
- JavaScript ์คํ ์๊ฐ ์ธก์
4. Bundle Analyzer
- JavaScript ๋ฒ๋ค ํฌ๊ธฐ ๋ถ์
- ๋ถํ์ํ ์ฝ๋ ์ฐพ๊ธฐ
// Performance API๋ก ์ธก์
function measureThemeSwitch() {
performance.mark('theme-switch-start');
setTheme(newTheme);
performance.mark('theme-switch-end');
performance.measure('theme-switch', 'theme-switch-start', 'theme-switch-end');
const measure = performance.getEntriesByName('theme-switch')[0];
console.log(`Theme switch took ${measure.duration}ms`);
// 100ms ์ด์ ๊ฑธ๋ฆฌ๋ฉด ๊ฒฝ๊ณ
if (measure.duration > 100) {
console.warn('Theme switch is too slow!');
}
}
๐ ์ค์ ์์ : ์์ ํ ๋คํฌ ๋ชจ๋ ์์คํ
์ง๊ธ๊น์ง ๋ฐฐ์ด ๋ชจ๋ ๋ด์ฉ์ ์ข
ํฉํด์, ์ค์ ๋ก ์ฌ์ฉํ ์ ์๋ ์์ ํ ๋คํฌ ๋ชจ๋ ์์คํ
์ ๋ง๋ค์ด๋ณด์!
์ด ์์ ๋ ๋ณต์ฌํด์ ๋ฐ๋ก ์ฌ์ฉํ ์ ์๋๋ก ๋ง๋ค์์ด. ๐
๐ ํ์ผ ๊ตฌ์กฐ
your-theme/
โโโ dark-mode/
โ โโโ dark-mode.css
โ โโโ dark-mode.js
โ โโโ dark-mode.php
โโโ functions.php
โโโ header.php
๐ 1. dark-mode.css
/* ============================================
๋คํฌ ๋ชจ๋ CSS - ์์ ํ ์์คํ
============================================ */
/* CSS ๋ณ์ ์ ์ */
:root {
/* ๋ผ์ดํธ ๋ชจ๋ ์์ */
--bg-primary: #ffffff;
--bg-secondary: #f8f9fa;
--bg-tertiary: #e9ecef;
--text-primary: #212529;
--text-secondary: #6c757d;
--text-tertiary: #adb5bd;
--border-color: #dee2e6;
--shadow-color: rgba(0, 0, 0, 0.1);
--link-color: #0d6efd;
--link-hover: #0a58ca;
--success: #198754;
--warning: #ffc107;
--danger: #dc3545;
--info: #0dcaf0;
--focus-color: #0d6efd;
/* ์ ํ ์๋ */
--transition-speed: 0.3s;
}
/* ๋คํฌ ๋ชจ๋ ์์ */
[data-theme="dark"] {
--bg-primary: #1a1a1a;
--bg-secondary: #2d2d2d;
--bg-tertiary: #3a3a3a;
--text-primary: #e0e0e0;
--text-secondary: #a0a0a0;
--text-tertiary: #707070;
--border-color: #404040;
--shadow-color: rgba(0, 0, 0, 0.5);
--link-color: #64b5f6;
--link-hover: #90caf9;
--success: #4caf50;
--warning: #ffb74d;
--danger: #ef5350;
--info: #4fc3f7;
--focus-color: #64b5f6;
}
/* ๊ธฐ๋ณธ ์์ ์คํ์ผ */
body {
background-color: var(--bg-primary);
color: var(--text-primary);
transition: background-color var(--transition-speed) ease,
color var(--transition-speed) ease;
}
/* ๋งํฌ */
a {
color: var(--link-color);
transition: color 0.2s ease;
}
a:hover {
color: var(--link-hover);
}
/* ๋ฒํผ */
button,
.button {
background-color: var(--bg-secondary);
color: var(--text-primary);
border: 1px solid var(--border-color);
transition: all 0.2s ease;
}
button:hover,
.button:hover {
background-color: var(--bg-tertiary);
}
/* ์
๋ ฅ ํ๋ */
input,
textarea,
select {
background-color: var(--bg-secondary);
color: var(--text-primary);
border: 1px solid var(--border-color);
transition: all 0.2s ease;
}
input:focus,
textarea:focus,
select:focus {
outline: 2px solid var(--focus-color);
outline-offset: 2px;
border-color: var(--focus-color);
}
/* ์นด๋/ํจ๋ */
.card,
.panel,
.widget {
background-color: var(--bg-secondary);
border: 1px solid var(--border-color);
box-shadow: 0 2px 8px var(--shadow-color);
transition: all var(--transition-speed) ease;
}
/* ํ
์ด๋ธ */
table {
background-color: var(--bg-secondary);
border-color: var(--border-color);
}
th {
background-color: var(--bg-tertiary);
color: var(--text-primary);
}
td {
border-color: var(--border-color);
}
tr:hover {
background-color: var(--bg-tertiary);
}
/* ์ฝ๋ ๋ธ๋ก */
code,
pre {
background-color: var(--bg-tertiary);
color: var(--text-primary);
border: 1px solid var(--border-color);
}
/* ๋คํฌ ๋ชจ๋์์ ์ด๋ฏธ์ง ๋ฐ๊ธฐ ์กฐ์ */
[data-theme="dark"] img:not(.no-filter) {
filter: brightness(0.8) contrast(1.1);
transition: filter 0.3s ease;
}
[data-theme="dark"] img:not(.no-filter):hover {
filter: brightness(1) contrast(1);
}
/* ํ ๊ธ ๋ฒํผ ์คํ์ผ */
.theme-toggle-btn {
position: fixed;
bottom: 20px;
right: 20px;
width: 50px;
height: 50px;
border-radius: 50%;
border: 2px solid var(--border-color);
background-color: var(--bg-secondary);
color: var(--text-primary);
font-size: 24px;
cursor: pointer;
box-shadow: 0 4px 12px var(--shadow-color);
transition: all 0.3s ease;
z-index: 1000;
display: flex;
align-items: center;
justify-content: center;
}
.theme-toggle-btn:hover {
transform: scale(1.1);
box-shadow: 0 6px 16px var(--shadow-color);
}
.theme-toggle-btn:active {
transform: scale(0.95);
}
.theme-toggle-btn:focus-visible {
outline: 3px solid var(--focus-color);
outline-offset: 3px;
}
/* ํ
๋ง ์ ํ ์ ๋๋ฉ์ด์
*/
@keyframes themeTransition {
0% { opacity: 1; }
50% { opacity: 0.8; }
100% { opacity: 1; }
}
.theme-transitioning {
animation: themeTransition 0.3s ease;
}
/* ๋ชจ๋ฐ์ผ ์ต์ ํ */
@media (max-width: 768px) {
.theme-toggle-btn {
bottom: 15px;
right: 15px;
width: 45px;
height: 45px;
font-size: 20px;
}
}
/* ์ ๋๋ฉ์ด์
๊ฐ์ ๋ชจ๋ */
@media (prefers-reduced-motion: reduce) {
* {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
/* ์ ๊ทผ์ฑ: ์คํฌ๋ฆฐ ๋ฆฌ๋ ์ ์ฉ */
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
/* ํฌ์ปค์ค ์ธ๋์ผ์ดํฐ */
:focus-visible {
outline: 2px solid var(--focus-color);
outline-offset: 2px;
}
:focus:not(:focus-visible) {
outline: none;
}
โ๏ธ 2. dark-mode.js
/**
* ๋คํฌ ๋ชจ๋ JavaScript - ์์ ํ ์์คํ
* @version 1.0.0
*/
(function() {
'use strict';
// ์ค์
const CONFIG = {
storageKey: 'theme',
dataAttribute: 'data-theme',
transitionClass: 'theme-transitioning',
transitionDuration: 300,
autoSwitchEnabled: false,
darkHourStart: 20,
darkHourEnd: 6
};
// ์ ํธ๋ฆฌํฐ ํจ์
const utils = {
// ์์คํ
๋คํฌ ๋ชจ๋ ์ ํธ๋ ํ์ธ
getSystemPreference: () => {
return window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: 'light';
},
// ์ ์ฅ๋ ํ
๋ง ๊ฐ์ ธ์ค๊ธฐ
getSavedTheme: () => {
return localStorage.getItem(CONFIG.storageKey);
},
// ํ
๋ง ์ ์ฅ
saveTheme: (theme) => {
localStorage.setItem(CONFIG.storageKey, theme);
localStorage.setItem(CONFIG.storageKey + 'Timestamp', Date.now());
},
// ํ์ฌ ์๊ฐ ๊ธฐ๋ฐ ํ
๋ง ๊ฒฐ์
getTimeBasedTheme: () => {
const hour = new Date().getHours();
return (hour >= CONFIG.darkHourStart || hour < CONFIG.darkHourEnd)
? 'dark'
: 'light';
},
// ์ ๋๋ฉ์ด์
๊ฐ์ ๋ชจ๋ ํ์ธ
prefersReducedMotion: () => {
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
}
};
// ํ
๋ง ๊ด๋ฆฌ์
const themeManager = {
currentTheme: null,
// ์ด๊ธฐ ํ
๋ง ๊ฒฐ์
getInitialTheme: () => {
const saved = utils.getSavedTheme();
if (saved) return saved;
if (CONFIG.autoSwitchEnabled) {
return utils.getTimeBasedTheme();
}
return utils.getSystemPreference();
},
// ํ
๋ง ์ ์ฉ
applyTheme: (theme, withTransition = true) => {
const root = document.documentElement;
const oldTheme = themeManager.currentTheme;
// ์ ํ ์ ๋๋ฉ์ด์
if (withTransition && !utils.prefersReducedMotion() && oldTheme) {
root.classList.add(CONFIG.transitionClass);
setTimeout(() => {
root.classList.remove(CONFIG.transitionClass);
}, CONFIG.transitionDuration);
}
// ํ
๋ง ์ ์ฉ
root.setAttribute(CONFIG.dataAttribute, theme);
themeManager.currentTheme = theme;
utils.saveTheme(theme);
// UI ์
๋ฐ์ดํธ
themeManager.updateUI(theme);
// ์ปค์คํ
์ด๋ฒคํธ ๋ฐ์
window.dispatchEvent(new CustomEvent('themechange', {
detail: { theme, oldTheme }
}));
},
// UI ์
๋ฐ์ดํธ
updateUI: (theme) => {
const toggleBtn = document.getElementById('theme-toggle');
if (!toggleBtn) return;
// ์์ด์ฝ ๋ณ๊ฒฝ
toggleBtn.innerHTML = theme === 'dark' ? 'โ๏ธ' : '๐';
// ARIA ์์ฑ ์
๋ฐ์ดํธ
toggleBtn.setAttribute('aria-pressed', theme === 'dark');
toggleBtn.setAttribute('aria-label',
theme === 'dark'
? '๋ผ์ดํธ ๋ชจ๋๋ก ์ ํ'
: '๋คํฌ ๋ชจ๋๋ก ์ ํ'
);
// ์คํฌ๋ฆฐ ๋ฆฌ๋ ์๋ฆผ
themeManager.announceToScreenReader(
`${theme === 'dark' ? '๋คํฌ' : '๋ผ์ดํธ'} ๋ชจ๋๊ฐ ํ์ฑํ๋์์ต๋๋ค.`
);
},
// ํ
๋ง ํ ๊ธ
toggleTheme: () => {
const newTheme = themeManager.currentTheme === 'dark' ? 'light' : 'dark';
themeManager.applyTheme(newTheme);
},
// ์คํฌ๋ฆฐ ๋ฆฌ๋ ์๋ฆผ
announceToScreenReader: (message) => {
const announcement = document.createElement('div');
announcement.setAttribute('role', 'status');
announcement.setAttribute('aria-live', 'polite');
announcement.className = 'sr-only';
announcement.textContent = message;
document.body.appendChild(announcement);
setTimeout(() => announcement.remove(), 1000);
}
};
// ์ด๋ฒคํธ ํธ๋ค๋ฌ
const eventHandlers = {
// ํ ๊ธ ๋ฒํผ ํด๋ฆญ
handleToggleClick: (e) => {
e.preventDefault();
themeManager.toggleTheme();
},
// ํค๋ณด๋ ๋จ์ถํค (Ctrl + Shift + D)
handleKeyboard: (e) => {
if (e.ctrlKey && e.shiftKey && e.key === 'D') {
e.preventDefault();
themeManager.toggleTheme();
}
},
// ์์คํ
ํ
๋ง ๋ณ๊ฒฝ ๊ฐ์ง
handleSystemThemeChange: (e) => {
if (!utils.getSavedTheme()) {
themeManager.applyTheme(e.matches ? 'dark' : 'light', false);
}
},
// ์๊ฐ ๊ธฐ๋ฐ ์๋ ์ ํ
handleAutoSwitch: () => {
if (CONFIG.autoSwitchEnabled && !localStorage.getItem('manualThemeSet')) {
const timeBasedTheme = utils.getTimeBasedTheme();
if (timeBasedTheme !== themeManager.currentTheme) {
themeManager.applyTheme(timeBasedTheme);
}
}
}
};
// ์ด๊ธฐํ
const init = () => {
// ์ด๊ธฐ ํ
๋ง ์ ์ฉ (๊น๋นก์ ๋ฐฉ์ง๋ฅผ ์ํด ๋๊ธฐ์ ์ผ๋ก)
const initialTheme = themeManager.getInitialTheme();
document.documentElement.setAttribute(CONFIG.dataAttribute, initialTheme);
themeManager.currentTheme = initialTheme;
// DOM ๋ก๋ ํ ์ด๋ฒคํธ ๋ฆฌ์ค๋ ๋ฑ๋ก
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', setupEventListeners);
} else {
setupEventListeners();
}
};
// ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์ค์
const setupEventListeners = () => {
// ํ ๊ธ ๋ฒํผ
const toggleBtn = document.getElementById('theme-toggle');
if (toggleBtn) {
toggleBtn.addEventListener('click', eventHandlers.handleToggleClick);
themeManager.updateUI(themeManager.currentTheme);
}
// ํค๋ณด๋ ๋จ์ถํค
document.addEventListener('keydown', eventHandlers.handleKeyboard);
// ์์คํ
ํ
๋ง ๋ณ๊ฒฝ ๊ฐ์ง
window.matchMedia('(prefers-color-scheme: dark)')
.addEventListener('change', eventHandlers.handleSystemThemeChange);
// ์๊ฐ ๊ธฐ๋ฐ ์๋ ์ ํ (1์๊ฐ๋ง๋ค ์ฒดํฌ)
if (CONFIG.autoSwitchEnabled) {
setInterval(eventHandlers.handleAutoSwitch, 3600000);
}
};
// ์ ์ญ API ๋
ธ์ถ
window.darkMode = {
toggle: themeManager.toggleTheme,
set: themeManager.applyTheme,
get: () => themeManager.currentTheme,
config: CONFIG
};
// ์ด๊ธฐํ ์คํ
init();
})();
๐ง 3. dark-mode.php
<?php
/**
* ๋คํฌ ๋ชจ๋ PHP ํจ์
* functions.php์ includeํ์ฌ ์ฌ์ฉ
*/
// ๋คํฌ ๋ชจ๋ ์คํฌ๋ฆฝํธ ๋ฐ ์คํ์ผ ๋ฑ๋ก
function enqueue_dark_mode_assets() {
// CSS ๋ฑ๋ก
wp_enqueue_style(
'dark-mode-styles',
get_stylesheet_directory_uri() . '/dark-mode/dark-mode.css',
array(),
'1.0.0'
);
// JavaScript ๋ฑ๋ก
wp_enqueue_script(
'dark-mode-script',
get_stylesheet_directory_uri() . '/dark-mode/dark-mode.js',
array(),
'1.0.0',
true
);
}
add_action('wp_enqueue_scripts', 'enqueue_dark_mode_assets');
// ํ ๊ธ ๋ฒํผ HTML ์ถ๋ ฅ
function render_dark_mode_toggle() {
?>
<button
id="theme-toggle"
class="theme-toggle-btn"
aria-label="<?php esc_attr_e('๋คํฌ ๋ชจ๋ ์ ํ', 'your-theme'); ?>"
aria-pressed="false"
type="button">
<span aria-hidden="true">๐</span>
<span class="sr-only"><?php esc_html_e('๋คํฌ ๋ชจ๋๋ก ์ ํ', 'your-theme'); ?></span>
</button>
<?php
}
add_action('wp_footer', 'render_dark_mode_toggle');
// ์ฌ์ฉ์ ํ
๋ง ์ค์ ์ ์ฅ (๋ก๊ทธ์ธํ ์ฌ์ฉ์์ฉ)
function save_user_theme_preference() {
check_ajax_referer('theme_nonce', 'nonce');
if (!is_user_logged_in()) {
wp_send_json_error('User not logged in');
return;
}
$user_id = get_current_user_id();
$theme = sanitize_text_field($_POST['theme']);
if (!in_array($theme, array('light', 'dark'))) {
wp_send_json_error('Invalid theme');
return;
}
update_user_meta($user_id, 'preferred_theme', $theme);
wp_send_json_success(array('theme' => $theme));
}
add_action('wp_ajax_save_theme', 'save_user_theme_preference');
// ์ฌ์ฉ์ ํ
๋ง ์ค์ ๋ถ๋ฌ์ค๊ธฐ
function get_user_theme_preference() {
if (!is_user_logged_in()) {
return null;
}
$user_id = get_current_user_id();
return get_user_meta($user_id, 'preferred_theme', true);
}
// head์ ์ธ๋ผ์ธ ์คํฌ๋ฆฝํธ ์ถ๊ฐ (๊น๋นก์ ๋ฐฉ์ง)
function add_dark_mode_inline_script() {
$user_theme = get_user_theme_preference();
?>
<script>
(function() {
<?php if ($user_theme): ?>
// ๋ก๊ทธ์ธํ ์ฌ์ฉ์์ ์ ์ฅ๋ ์ค์ ์ฌ์ฉ
const theme = '<?php echo esc_js($user_theme); ?>';
<?php else: ?>
// ๋ก์ปฌ ์คํ ๋ฆฌ์ง ๋๋ ์์คํ
์ค์ ์ฌ์ฉ
const theme = localStorage.getItem('theme') ||
(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
<?php endif; ?>
document.documentElement.setAttribute('data-theme', theme);
})();
</script>
<?php
}
add_action('wp_head', 'add_dark_mode_inline_script', 1);
// AJAX nonce ์ถ๊ฐ
function add_theme_ajax_nonce() {
if (is_user_logged_in()) {
?>
<script>
window.themeAjax = {
ajaxurl: '<?php echo admin_url('admin-ajax.php'); ?>',
nonce: '<?php echo wp_create_nonce('theme_nonce'); ?>'
};
</script>
<?php
}
}
add_action('wp_footer', 'add_theme_ajax_nonce', 5);
// ๊ด๋ฆฌ์ ํ์ด์ง์๋ ๋คํฌ ๋ชจ๋ ์ ์ฉ (์ ํ์ฌํญ)
function enqueue_admin_dark_mode() {
wp_enqueue_style(
'admin-dark-mode',
get_stylesheet_directory_uri() . '/dark-mode/dark-mode.css',
array(),
'1.0.0'
);
wp_enqueue_script(
'admin-dark-mode-script',
get_stylesheet_directory_uri() . '/dark-mode/dark-mode.js',
array(),
'1.0.0',
true
);
}
// add_action('admin_enqueue_scripts', 'enqueue_admin_dark_mode'); // ์ฃผ์ ํด์ ํ์ฌ ํ์ฑํ
?>
๐ 4. functions.php์ ์ถ๊ฐ
<?php
// ๋คํฌ ๋ชจ๋ ๊ธฐ๋ฅ ํฌํจ
require_once get_stylesheet_directory() . '/dark-mode/dark-mode.php';
// ์ถ๊ฐ ์ปค์คํฐ๋ง์ด์ง (์ ํ์ฌํญ)
function customize_dark_mode_config() {
?>
<script>
// ๋คํฌ ๋ชจ๋ ์ค์ ์ปค์คํฐ๋ง์ด์ง
if (window.darkMode) {
window.darkMode.config.autoSwitchEnabled = true; // ์๋ ์ ํ ํ์ฑํ
window.darkMode.config.darkHourStart = 19; // ์ ๋
7์๋ถํฐ
window.darkMode.config.darkHourEnd = 7; // ์์นจ 7์๊น์ง
}
</script>
<?php
}
add_action('wp_footer', 'customize_dark_mode_config', 20);
?>
์ด ์ฝ๋๋ ๋ค์ ๊ธฐ๋ฅ๋ค์ ๋ชจ๋ ํฌํจํ๊ณ ์์ด:
โ ๋ผ์ดํธ/๋คํฌ ๋ชจ๋ ์ ํ
โ ์ฌ์ฉ์ ์ ํ ์ ์ฅ (๋ก์ปฌ ์คํ ๋ฆฌ์ง + ์ฌ์ฉ์ ๋ฉํ)
โ ์์คํ ์ค์ ์๋ ๊ฐ์ง
โ ์๊ฐ ๊ธฐ๋ฐ ์๋ ์ ํ (์ ํ์ฌํญ)
โ ํค๋ณด๋ ๋จ์ถํค ์ง์
โ ์ ๊ทผ์ฑ ์๋ฒฝ ์ง์
โ ์ฑ๋ฅ ์ต์ ํ
โ ๊น๋นก์ ๋ฐฉ์ง
โ ๋ชจ๋ฐ์ผ ์ต์ ํ
๐ก ์ค๋ฌด ํ๊ณผ ์ฃผ์์ฌํญ
๋คํฌ ๋ชจ๋๋ฅผ ์ค์ ํ๋ก์ ํธ์ ์ ์ฉํ ๋ ์์๋๋ฉด ์ข์ ํ๋ค์ ๊ณต์ ํ ๊ฒ!
์ค๋ฌด์์ ๊ฒช์ ์ ์๋ ํจ์ ๋ค์ ๋ฏธ๋ฆฌ ํผํด๊ฐ์. ๐
โจ ๋์์ธ ํ
๋คํฌ ๋ชจ๋์์๋ ๋ธ๋๋ ์์ด๋ดํฐํฐ๋ ์ ์งํด์ผ ํด.
๋ก๊ณ ๋ ๋ธ๋๋ ์์์ ๋คํฌ ๋ชจ๋์์๋ ์ธ์ ๊ฐ๋ฅํ๋๋ก ์กฐ์ ํ๋, ์์ ํ ๋ฐ๊พธ์ง๋ ๋ง์.
/* ๋ธ๋๋ ์์์ ์ฝ๊ฐ๋ง ์กฐ์ */
:root {
--brand-primary: #ff6b6b; /* ๋ฐ์ ๋นจ๊ฐ */
}
[data-theme="dark"] {
--brand-primary: #ff8787; /* ์กฐ๊ธ ๋ ๋ฐ๊ฒ */
}
๋ผ์ดํธ ๋ชจ๋์์ ์์ ๊ทธ๋ผ๋์ธํธ๊ฐ ๋คํฌ ๋ชจ๋์์๋ ์ด์ํด ๋ณด์ผ ์ ์์ด.
๋คํฌ ๋ชจ๋ ์ ์ฉ ๊ทธ๋ผ๋์ธํธ๋ฅผ ๋ฐ๋ก ๋ง๋๋ ๊ฒ ์ข์.
/* ๋ผ์ดํธ ๋ชจ๋ ๊ทธ๋ผ๋์ธํธ */
.hero {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
/* ๋คํฌ ๋ชจ๋ ๊ทธ๋ผ๋์ธํธ */
[data-theme="dark"] .hero {
background: linear-gradient(135deg, #4a5fc1 0%, #5a3a7a 100%);
}
SVG ์์ด์ฝ์ currentColor๋ฅผ ์ฌ์ฉํ๋ฉด ์๋์ผ๋ก ์์์ด ๋ฐ๋์ด์ ํธํด.
<svg fill="currentColor" ...>
<!-- ์๋์ผ๋ก ํ
์คํธ ์์์ ๋ฐ๋ผ๊ฐ -->
</svg>
โ ๏ธ ์ฃผ์์ฌํญ
โข ๋ค์ํ ๋ธ๋ผ์ฐ์ ์์ ํ ์คํธ (Chrome, Firefox, Safari, Edge)
โข ๋ชจ๋ฐ์ผ ๊ธฐ๊ธฐ์์ ํ ์คํธ
โข ๋ค์ํ ํ๋ฌ๊ทธ์ธ ์กฐํฉ์์ ํ ์คํธ
โข ์ ๊ทผ์ฑ ๋๊ตฌ๋ก ํ ์คํธ (์คํฌ๋ฆฐ ๋ฆฌ๋, ํค๋ณด๋ ๋ค๋น๊ฒ์ด์ )
Lighthouse ์ ์๋ฅผ ๋น๊ตํด๋ณด๊ณ , ํ์ํ๋ฉด ์ต์ ํํ์.
์ด๋ค ๋ถ๋ถ์ด ๋ถํธํ์ง, ์ด๋ค ์์์ด ์ ์ ๋ณด์ด๋์ง ๋ฑ์ ํ์ ํ๊ณ ๊ฐ์ ํ์.
๐ ์ ์ง๋ณด์ ํ
์ฌ์ฉํ๋ CSS ๋ณ์๋ค์ ๋ฌธ์ํํด๋๋ฉด ๋์ค์ ์์ ํ ๋ ํธํด.
/**
* CSS ๋ณ์ ๊ฐ์ด๋
*
* ๋ฐฐ๊ฒฝ์:
* --bg-primary: ๋ฉ์ธ ๋ฐฐ๊ฒฝ
* --bg-secondary: ์นด๋, ํจ๋ ๋ฐฐ๊ฒฝ
* --bg-tertiary: ํธ๋ฒ ์ํ ๋ฐฐ๊ฒฝ
*
* ํ
์คํธ ์์:
* --text-primary: ์ฃผ์ ํ
์คํธ
* --text-secondary: ๋ณด์กฐ ํ
์คํธ
* --text-tertiary: ๋นํ์ฑ ํ
์คํธ
*
* ... (๊ณ์)
*/
ํนํ ์์ ๊ฐ์ ๋ณ๊ฒฝํ ๋๋ ์ด์ ๋ฅผ ์ปค๋ฐ ๋ฉ์์ง์ ๋จ๊ธฐ๋ ๊ฒ ์ข์.
ํนํ ๋ฉ์ด์ ์ ๋ฐ์ดํธ ํ์๋ ๊ผญ ํ ์คํธํ์.
๐ฏ SEO ๊ณ ๋ ค์ฌํญ
๋คํฌ ๋ชจ๋๊ฐ SEO์ ์ง์ ์ ์ธ ์ํฅ์ ์ฃผ์ง๋ ์์ง๋ง, ์ฌ์ฉ์ ๊ฒฝํ์ด ์ข์์ง๋ฉด
์ฒด๋ฅ ์๊ฐ์ด ๋์ด๋๊ณ ์ดํ๋ฅ ์ด ๋ฎ์์ ธ์ ๊ฐ์ ์ ์ผ๋ก SEO์ ๋์์ด ๋ผ.
- โ๏ธ ๋คํฌ ๋ชจ๋์์๋ ํ ์คํธ๊ฐ ๊ฒ์ ์์ง์ ์ ๋ณด์ด๋๊ฐ?
- โ๏ธ ์ด๋ฏธ์ง alt ํ ์คํธ๊ฐ ์ ๋๋ก ์ค์ ๋์ด ์๋๊ฐ?
- โ๏ธ ๊ตฌ์กฐํ๋ ๋ฐ์ดํฐ(Schema)๊ฐ ์ฌ์ ํ ์ ํจํ๊ฐ?
- โ๏ธ ํ์ด์ง ๋ก๋ฉ ์๋๊ฐ ๋๋ ค์ง์ง ์์๋๊ฐ?
- โ๏ธ ๋ชจ๋ฐ์ผ ์นํ์ฑ์ด ์ ์ง๋๋๊ฐ?
๐ผ ํด๋ผ์ด์ธํธ ํ๋ก์ ํธ์์
ํด๋ผ์ด์ธํธ ํ๋ก์ ํธ์์ ๋คํฌ ๋ชจ๋๋ฅผ ๊ตฌํํ ๋๋ ๋ค์ ์ฌํญ๋ค์ ๊ณ ๋ คํด์ผ ํด.
โข ์ถ๊ฐ ๋น์ฉ๊ณผ ๊ฐ๋ฐ ์๊ฐ ์๋ด
โข ์ ์ง๋ณด์ ๋ฐฉ๋ฒ ๊ต์ก
โข ์ฌ์ฉ์ ํผ๋๋ฐฑ ์์ง ๋ฐฉ๋ฒ ์๋ด
โข ์ง์ ๋ธ๋ผ์ฐ์ ๋ชฉ๋ก
โข ํ ์คํธ ๋ฒ์
โข ์ ์ง๋ณด์ ์กฐ๊ฑด
โข ์์ ํ๋ ํธ ๊ฐ์ด๋
โข ๋ฌธ์ ํด๊ฒฐ ๋งค๋ด์ผ
โข ์ปค์คํฐ๋ง์ด์ง ๋ฐฉ๋ฒ
๐ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์ฌ๊ธฐ๊น์ง ์๋ํ๋ ์ค ๋คํฌ ๋ชจ๋ ๊ตฌํ์ ๋ํ ๋ชจ๋ ๊ฒ์ ์์๋ดค์ด! ๐
์ฒ์์๋ ๋ณต์กํด ๋ณด์ผ ์ ์์ง๋ง, ๋จ๊ณ๋ณ๋ก ๋ฐ๋ผํ๋ค ๋ณด๋ฉด ์๊ฐ๋ณด๋ค ์ด๋ ต์ง ์์.
๐ ํต์ฌ ์์ฝ
2. ํ ๋ง ๊ธฐ๋ฅ ํ์ฉ - ํ ๋ง์ ๋ด์ฅ๋ ๊ธฐ๋ฅ ์ฌ์ฉ
3. ์ง์ ์ฝ๋ฉ - ์์ ํ ์ปค์คํฐ๋ง์ด์ง ๊ฐ๋ฅ (๊ฐ๋ฐ์ ์ถ์ฒ)
- โ ์์ํ ๊ฒ์์(#000000) ๋์ ๋ถ๋๋ฌ์ด ํ์ ์ฌ์ฉ
- โ ๋ช ์๋น ์ต์ 4.5:1 ์ด์ ์ ์ง (WCAG ๊ธฐ์ค)
- โ CSS ๋ณ์๋ก ์์ ์ฒด๊ณ ๊ด๋ฆฌ
- โ ๊น๋นก์ ๋ฐฉ์ง๋ฅผ ์ํ ์ธ๋ผ์ธ ์คํฌ๋ฆฝํธ
- โ ์ ๊ทผ์ฑ ๊ณ ๋ ค (ํค๋ณด๋, ์คํฌ๋ฆฐ ๋ฆฌ๋)
- โ ์ฑ๋ฅ ์ต์ ํ (transition, ์ด๋ฏธ์ง)
- โ ์ถฉ๋ถํ ํ ์คํธ (๋ค์ํ ํ๊ฒฝ)
๐ ๋ค์ ๋จ๊ณ
๋คํฌ ๋ชจ๋๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ๊ตฌํํ๋ค๋ฉด, ์ด์ ๋ค์ ๋จ๊ณ๋ก ๋์๊ฐ๋ณด์!
โข ์ฌ์ฉ์ ์ปค์คํ ์์ ์ ํ ๊ธฐ๋ฅ
โข ํ์ด์ง๋ณ ๋ค๋ฅธ ํ ๋ง ์ ์ฉ
โข ์๊ฐ๋๋ณ ์๋ ์ ํ ๊ณ ๋ํ
โข ๋คํฌ ๋ชจ๋ ์ฌ์ฉ ํต๊ณ ์์ง
โข A/B ํ ์คํธ๋ก ์ต์ ์ ์์ ์ฐพ๊ธฐ
๐ฌ ์ปค๋ฎค๋ํฐ์ ํจ๊ป
๋คํฌ ๋ชจ๋ ๊ตฌํ ์ค์ ๋งํ๋ ๋ถ๋ถ์ด ์๋ค๋ฉด, ์๋ํ๋ ์ค ์ปค๋ฎค๋ํฐ์ ์ง๋ฌธํด๋ด.
์ฌ๋ฅ๋ท(https://www.jaenung.net)์์๋ ์น๊ฐ๋ฐ ์ ๋ฌธ๊ฐ๋ค์ ๋ง๋ ์ ์์ด.
ํผ์ ๊ณ ๋ฏผํ์ง ๋ง๊ณ , ํจ๊ป ํด๊ฒฐํด๋๊ฐ์! ๐ค
โข WCAG Guidelines - ์น ์ ๊ทผ์ฑ ๊ฐ์ด๋๋ผ์ธ
โข Material Design - ๊ตฌ๊ธ์ ๋คํฌ ํ ๋ง ๊ฐ์ด๋
โข WordPress Codex - ์๋ํ๋ ์ค ๊ฐ๋ฐ ๋ฌธ์
โข ์ฌ๋ฅ๋ท ์ง์์ธ์ ์ฒ - ๋ค์ํ ์น๊ฐ๋ฐ ์ง์ ๊ณต์
โจ ๋ง์ง๋ง ์กฐ์ธ
๋คํฌ ๋ชจ๋๋ ๋จ์ํ '์์ผ๋ฉด ์ข์' ๊ธฐ๋ฅ์ด ์๋๋ผ, ์ฌ์ฉ์ ๊ฒฝํ์ ํฌ๊ฒ ํฅ์์ํค๋ ํ์ ๊ธฐ๋ฅ์ด ๋์ด๊ฐ๊ณ ์์ด.
ํนํ ๋ชจ๋ฐ์ผ ์ฌ์ฉ์ด ์ฆ๊ฐํ๊ณ , ์ฌ๋๋ค์ด ๋ฐค๋ฆ๊ฒ๊น์ง ๋์งํธ ๊ธฐ๊ธฐ๋ฅผ ์ฌ์ฉํ๋ ์์ฆ,
๋คํฌ ๋ชจ๋๋ ์ฌ์ฉ์์ ๋ ๊ฑด๊ฐ๊ณผ ํธ์์ฑ์ ์ํ ๋ฐฐ๋ ค์ ํํ์ด์ผ. ๐
์ฒ์์๋ ์์ ์กฐํฉ์ด ์ด๋ ต๊ณ , ๋ชจ๋ ์์๋ฅผ ๋คํฌ ๋ชจ๋์ ๋ง๊ฒ ์กฐ์ ํ๋ ๊ฒ ๋ฒ๊ฑฐ๋ก์ธ ์ ์์ด.
ํ์ง๋ง ํ ๋ฒ ์ ๋๋ก ๊ตฌ์ถํด๋๋ฉด, ์ฌ์ฉ์๋ค์ ๋ง์กฑ๋๊ฐ ๋์ ๋๊ฒ ๋์์ง๋ ๊ฑธ ๋๋ ์ ์์ ๊ฑฐ์ผ.
ํนํ ๋ฐค์ ์ฌ์ดํธ๋ฅผ ๋ฐฉ๋ฌธํ๋ ์ฌ์ฉ์๋ค์ด "์, ๋คํฌ ๋ชจ๋ ์๋ค!"๋ผ๊ณ ๋ฐ์ํ ๋์ ๋ฟ๋ฏํจ์ ๋ง๋ก ํํํ ์ ์์ง. ๐
์ด ๊ฐ์ด๋๊ฐ ๋ค ์๋ํ๋ ์ค ์ฌ์ดํธ์ ๋ฉ์ง ๋คํฌ ๋ชจ๋๋ฅผ ๊ตฌํํ๋ ๋ฐ ๋์์ด ๋์์ผ๋ฉด ์ข๊ฒ ์ด.
๊ถ๊ธํ ์ ์ด ์๊ฑฐ๋, ๋ ๊น์ด ์๋ ๋ด์ฉ์ด ํ์ํ๋ค๋ฉด ์ธ์ ๋ ์ฌ๋ฅ๋ท์์ ์ ๋ฌธ๊ฐ๋ค๊ณผ ์ํตํด๋ด!
ํจ๊ป ๋ ๋์ ์น์ ๋ง๋ค์ด๊ฐ์! ๐
๐ Happy Dark Mode Coding! โ๏ธ
์ฌ์ฉ์์ ๋์ ํธ์ํ๊ฒ, ๊ฒฝํ์ ํ์๋กญ๊ฒ!
๋น์ ์ ์ฌ์ดํธ๊ฐ ๋ฐค๋ฎ์ผ๋ก ๋น๋๊ธธ ๋ฐ๋ผ! โจ
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.