<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ページごと &#8211; ケケンタの独学ITブログ</title>
	<atom:link href="https://kekenta-it-blog.com/tag/%E3%83%9A%E3%83%BC%E3%82%B8%E3%81%94%E3%81%A8/feed/" rel="self" type="application/rss+xml" />
	<link>https://kekenta-it-blog.com</link>
	<description>プログラミングやWeb制作の情報を発信</description>
	<lastBuildDate>Tue, 18 Mar 2025 02:08:33 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://kekenta-it-blog.com/wp-content/uploads/2023/07/cropped-KEKENTA-BLOG-32x32.png</url>
	<title>ページごと &#8211; ケケンタの独学ITブログ</title>
	<link>https://kekenta-it-blog.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【WordPress】特定ページにCSSを読み込む「５つ」の方法【早見リスト付】</title>
		<link>https://kekenta-it-blog.com/wp-read-css-per-page/</link>
					<comments>https://kekenta-it-blog.com/wp-read-css-per-page/#respond</comments>
		
		<dc:creator><![CDATA[ケケンタ]]></dc:creator>
		<pubDate>Wed, 21 Aug 2024 10:22:25 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[ページごと]]></category>
		<guid isPermaLink="false">https://kekenta-it-blog.com/?p=10409</guid>

					<description><![CDATA[<p><img src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/eye-catch__wp-read-css-per-page__10409-1024x576.jpg" class="webfeedsFeaturedVisual" /></p>今回はこのようなお悩みをお持ちの方へ向けて WordPressで特定のページごとにCSSを読み込ませる方法 をご紹介します。 ５の方法をご紹介するので、ご自身に適した方法をお選びいただければと思います。 状況別！おすすめ [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/eye-catch__wp-read-css-per-page__10409-1024x576.jpg" class="webfeedsFeaturedVisual" /></p><div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/困った顔-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/困った顔-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>WordPressでページごとに別のCSSを読み込ませたいんだけど、どうすればいいのかな……？</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p class="wp-block-paragraph">今回はこのようなお悩みをお持ちの方へ向けて</p>



<p class="has-text-align-center is-style-big_kakko_box wp-block-paragraph"><strong><span class="swl-marker mark_yellow">WordPressで特定のページごとにCSSを読み込ませる方法</span></strong></p>



<p class="wp-block-paragraph">をご紹介します。</p>



<p class="is-style-bg_stripe wp-block-paragraph"><strong>５の方法をご紹介</strong>するので、ご自身に適した方法をお選びいただければと思います。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type2" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2024/05/eye-catch__wp-bg-up__6665-300x169.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://kekenta-it-blog.com/wp-bg-up/">【WordPress】特定のページのみ背景色を変える方法</a>
						<span class="p-blogCard__excerpt">WordPressで特定のページだけ背景色を変えたいんだけどやり方がわからない…… 今回はこのようなお悩みについて解説をしていきます。  この記事で分かること WordPressの&#8230;</span>					</div>
				</div>
			</div>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-edit-functions/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】functions.phpを編集する「３つ」の方法と編集時の注意点</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-how-to-load-js/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】JavaScriptはどこに書けばいい？「３つの方法」を解説</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/change-to-swell/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">無料テーマCocoonからSWELLに乗り換えた７つの理由【WordPress】</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/school-php-and-wp/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">PHPやWordPressを学ぶのにおすすめのプログラミングスクール【７選】</span>
			</a>
		</div>


<h2 class="wp-block-heading" id="fast-list">状況別！おすすめの方法一覧</h2>



<p class="is-style-bg_stripe wp-block-paragraph">今回はページごとにCSSを読み込ませる方法を複数ご紹介しますが、<strong><span class="swl-marker mark_yellow">WordPressの現在のご状況によって向き不向きがある</span></strong>ため、まずは「状況ごとにおすすめの方法」を一覧でお見せしたいと思います。</p>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>ご自身のご状況に合わせて、<strong>使いやすそうな方法</strong>をお選びください！</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p class="is-style-balloon_box wp-block-paragraph">無料・有料テーマの子テーマを「使用している」場合</p>



<div class="wp-block-group has-border -border01"><div class="wp-block-group__inner-container">
<ul class="wp-block-list is-style-check_list -list-under-dashed">
<li><a href="#in-functions">【方法①】functions.phpで読み込ませる</a>（★推奨）</li>



<li><a href="#in-edit">【方法③】記事編集ページで読み込ませる</a></li>



<li><a href="#use-plugin">【方法⑤】プラグイン「WP Add Custom CSS」を使用する</a></li>
</ul>
</div></div>



<p class="is-style-balloon_box wp-block-paragraph">無料・有料テーマの子テーマを「使用していない（親テーマを直接使用している）」場合</p>



<div class="wp-block-group has-border -border01"><div class="wp-block-group__inner-container">
<ul class="wp-block-list is-style-check_list -list-under-dashed">
<li><a href="#in-edit">【方法③】記事編集ページで読み込ませる</a>（★推奨）</li>



<li><a href="#use-plugin">【方法⑤】プラグイン「WP Add Custom CSS」を使用する</a></li>
</ul>
</div></div>



<p class="is-style-balloon_box wp-block-paragraph">オリジナルテーマを使用している場合</p>



<div class="wp-block-group has-border -border01"><div class="wp-block-group__inner-container">
<ul class="wp-block-list is-style-check_list -list-under-dashed">
<li><a href="#in-functions">【方法①】functions.phpで読み込ませる</a>（★推奨）</li>



<li><a href="#in-head">【方法②】headタグ内で読み込ませる</a></li>



<li><a href="#in-template">【方法④】テンプレートファイルで読み込ませる</a></li>



<li><a href="#use-plugin">【方法⑤】プラグイン「WP Add Custom CSS」を使用する</a></li>
</ul>
</div></div>



<p class="is-style-icon_info wp-block-paragraph"><a href="##use-plugin">【方法⑤】プラグイン「WP Add Custom CSS」</a>を使用する際の留意点として「アップデートが2022年でストップしている」ことが挙げられます。<br>これはセキュリティリスクにも関わることのため、利用する際はその点をご留意ください。</p>



<p class="is-style-balloon_box wp-block-paragraph"><strong>【代替案】プラグイン「WP Add Custom CSS」の機能を自分で実装する</strong></p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type2" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/eye-catch__wp-inputform-for-css-js__10597-300x169.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://kekenta-it-blog.com/wp-inputform-for-css-js/">【WordPress】固定・投稿ページ編集画面にCSSやJSの入力フォームを設置する</a>
						<span class="p-blogCard__excerpt">特定の固定ページや投稿ページごとに簡単にCSSとかJavaScriptを設定できるようにしたいな…… 今回はこのようなお悩みをお持ちの方に向けて 固定ページ編集画面や投稿ペー&#8230;</span>					</div>
				</div>
			</div>
		</div>

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4374558503914683"
     crossorigin="anonymous"></script>
<!-- ディスプレイ【横長】 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-4374558503914683"
     data-ad-slot="9744298852"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<h2 class="wp-block-heading" id="in-functions">【方法①】functions.phpで読み込ませる</h2>



<p class="has-text-align-center is-style-bg_stripe wp-block-paragraph"><strong>functions.phpを利用してCSSを読み込ませる方法</strong>です。<br>※基本的にはこの方法がもっとも推奨されます。</p>



<p class="is-style-icon_info wp-block-paragraph">functions.phpを編集するときは必ずバックアップを取るようにしましょう。</p>



<p class="is-style-balloon_box wp-block-paragraph">（例１）「固定ページ」にsample.cssを読み込ませる</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="functions.php" data-lang="PHP"><code>function my_styles_include()  {
  // 固定ページにCSSを読み込む
  if ( is_page() ) {
    wp_enqueue_style( &#39;sample&#39;, get_template_directory_uri() . &#39;/css/sample.css&#39;, array(), &#39;1.0.0&#39; );
  }
}
add_action( &#39;wp_enqueue_scripts&#39;, &#39;my_styles_include&#39; );</code></pre></div>



<p class="is-style-big_icon_check wp-block-paragraph">条件分岐タグのひとつである<strong>is_page()</strong>でページ判定を行い、「固定ページ」にだけsample.cssを読み込ませています。</p>



<p class="is-style-balloon_box wp-block-paragraph">（例２-１）「特定の固定ページ」にsample.cssを読み込ませる</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="functions.php" data-lang="PHP"><code>function my_styles_include()  {
  // 固定ページ「sample」にCSSを読み込む
  if ( is_page( &#39;sample&#39; ) ) {
    wp_enqueue_style( &#39;sample&#39;, get_template_directory_uri() . &#39;/css/sample.css&#39;, array(), &#39;1.0.0&#39; );
  }
}
add_action( &#39;wp_enqueue_scripts&#39;, &#39;my_styles_include&#39; );</code></pre></div>



<p class="is-style-balloon_box wp-block-paragraph">（例２-２）複数の「特定の固定ページ」にsample.cssを読み込ませる</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="functions.php" data-lang="PHP"><code>function my_styles_include()  {
  // 固定ページ「sample01」と「sample02」にCSSを読み込む
  if ( is_page( array( &#39;sample01&#39;, &#39;sample02&#39; ) ) ) {
    wp_enqueue_style( &#39;sample&#39;, get_template_directory_uri() . &#39;/css/sample.css&#39;, array(), &#39;1.0.0&#39; );
  }
}
add_action( &#39;wp_enqueue_scripts&#39;, &#39;my_styles_include&#39; );</code></pre></div>



<div class="wp-block-group is-style-big_icon_good"><div class="wp-block-group__inner-container">
<p class="wp-block-paragraph"><strong>is_page()</strong>の引数に<strong>固定ページのスラッグ</strong>を指定することで、そのページにだけsample.cssを読み込ませています。<br><strong>複数のページを指定する場合（例２-２）</strong>は、array()で配列として指定します。</p>
</div></div>



<p class="is-style-balloon_box wp-block-paragraph">（例３）「特定の固定ページ」と「特定の投稿ページ」にそれぞれのCSSファイルを読み込ませる</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="functions.php" data-lang="PHP"><code>function my_styles_include()  {
  if ( is_page( &#39;sample-page&#39; ) ) {
    // 固定ページ「sample-page」にCSSを読み込む
    wp_enqueue_style( &#39;sample-page&#39;, get_template_directory_uri() . &#39;/css/sample-page.css&#39;, array(), &#39;1.0.0&#39; );
  
  } elseif ( is_page( &#39;sample-page&#39; ) ) {
    // 投稿ページ「sample-single」にCSSを読み込む
    wp_enqueue_style( &#39;sample-single&#39;, get_template_directory_uri() . &#39;/css/sample-single.css&#39;, array(), &#39;1.0.0&#39; );  
  }
}
add_action( &#39;wp_enqueue_scripts&#39;, &#39;my_styles_include&#39; );</code></pre></div>



<div class="wp-block-group is-style-big_icon_good"><div class="wp-block-group__inner-container">
<p class="wp-block-paragraph"><strong>is_page()とis_single()をelseif文で分岐する</strong>ことで「固定ページ」と「投稿ページ」にそれぞれのCSSファイルを読み込ませています。</p>
</div></div>



<p class="is-style-balloon_box wp-block-paragraph">（例４）「特定の固定ページ」と「特定の投稿ページ」に同じCSSファイルを読み込ませる</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="functions.php" data-lang="PHP"><code>function my_styles_include()  {
  if ( is_page( &#39;sample-page&#39; ) || is_page( &#39;sample-single&#39; ) ) {
    // 固定ページ「sample-page」と投稿ページ「sample-single」にCSSを読み込む
    wp_enqueue_style( &#39;sample-page&#39;, get_template_directory_uri() . &#39;/css/sample-page.css&#39;, array(), &#39;1.0.0&#39; );
  }
}
add_action( &#39;wp_enqueue_scripts&#39;, &#39;my_styles_include&#39; );</code></pre></div>



<p class="is-style-big_icon_check wp-block-paragraph"><strong>複数の特定のページに同じCSSファイルを読み込ませたいとき</strong>は<strong>「||（または）」演算子</strong>で条件をつなぎます。</p>



<div class="swell-block-capbox cap_box"><div class="cap_box_ttl"><span>wp_enqueue_style()関数について</span></div><div class="cap_box_content">
<p class="wp-block-paragraph"><strong>wp_enqueue_style()</strong>は、<strong>CSSを読み込ませるための関数</strong>です。</p>



<ul class="wp-block-list is-style-check_list -list-under-dashed">
<li>第１引数……ハンドル名（ほかの処理でこのCSSファイルを指定するためのキー名）※任意の名称</li>



<li>第２引数……CSSファイルのパス</li>



<li>第３引数……ほかファイルとの依存関係。ここに記述したハンドル名のファイルよりも後に読み込まれます。</li>



<li>第４引数……バージョン番号。キャッシュによって最新バージョンが即座に反映されないのを防止するのに役立ちます。</li>
</ul>
</div></div>



<p class="has-text-align-center is-style-balloon_box2 wp-block-paragraph"><strong>スラッグ</strong>は<strong><span style="background-color:#fff2cf" class="swl-bg-color">管理画面「投稿（固定ページ）一覧」→ 記事の「クイック編集」</span></strong>でご確認いただけます。</p>


<div class="wp-block-image is-style-shadow size_s">
<figure class="aligncenter size-full"><img decoding="async" width="858" height="364" src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page01.jpg" alt="スラッグの確認方法" class="wp-image-10572" srcset="https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page01.jpg 858w, https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page01-300x127.jpg 300w, https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page01-768x326.jpg 768w" sizes="(max-width: 858px) 100vw, 858px" /><figcaption class="wp-element-caption">スラッグの確認方法</figcaption></figure>
</div>


<p class="is-style-balloon_box2 wp-block-paragraph"><strong>条件分岐タグ</strong>について詳しく知りたい方は<a href="https://kekenta-it-blog.com/wp-temptag-ispage/">以下の記事</a>がおすすめです</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type2" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2024/07/eye-catch__wp-temptag-ispage__8933-300x169.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://kekenta-it-blog.com/wp-temptag-ispage/">【WordPress】is_page？条件分岐タグって？分かりやすく解説！</a>
						<span class="p-blogCard__excerpt">WordPressには「テンプレートタグ」という、プログラミング言語で言うところの「関数」が多数用意されています。 今回はその中でも比較的使用頻度が高いis_page()につい&#8230;</span>					</div>
				</div>
			</div>
		</div>


<p class="wp-block-paragraph"><span style="--the-icon-svg: url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjFlbSIgd2lkdGg9IjFlbSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBhcmlhLWhpZGRlbj0idHJ1ZSIgdmlld0JveD0iMCAwIDQ4IDQ4Ij48cGF0aCBkPSJtMjUuMSAxNSAxMy4xIDEzLjFjLjguOC44IDIgMCAyLjgtLjguOC0yIC44LTIuOCAwTDI0IDE5LjYgMTIuNyAzMC45Yy0uOC44LTIgLjgtMi44IDAtLjgtLjgtLjgtMiAwLTIuOGwxMy0xMy4xYy42LS42IDEuNi0uNiAyLjIgMHoiPjwvcGF0aD48L3N2Zz4=)" data-icon="LsChevronTop" data-id="0" aria-hidden="true" class="swl-inline-icon"> </span><a href="#fast-list">おすすめの</a><a href="#fast-list">方法一覧に戻る</a></p>


<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4374558503914683"
     crossorigin="anonymous"></script>
<!-- ディスプレイ【横長】 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-4374558503914683"
     data-ad-slot="9744298852"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<h2 class="wp-block-heading" id="in-head">【方法②】headタグ内で読み込ませる</h2>



<p class="has-text-align-center is-style-bg_stripe wp-block-paragraph"><strong>header.phpにあるheadタグ内でページの判定を行ないCSSを読み込ませる方法</strong>です。</p>



<p class="is-style-balloon_box wp-block-paragraph">（例１）「固定ページ」にsample.cssを読み込ませる</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="header.php" data-lang="PHP"><code>&lt;head&gt;
  &lt;?php if ( is_page() ): ?&gt;
    &lt;!-- 固定ページに読み込むCSS --&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php echo get_template_directory_uri(); ?&gt;/css/sample.css&quot;&gt;
  &lt;?php endif; ?&gt;
&lt;/head&gt;</code></pre></div>



<p class="is-style-big_icon_check wp-block-paragraph">条件分岐タグのひとつである<strong>is_page()</strong>でページ判定を行い、「固定ページ」にだけsample.cssを読み込ませています。</p>



<p class="is-style-balloon_box wp-block-paragraph">（例２-１）「特定の固定ページ」にsample.cssを読み込ませる</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="header.php" data-lang="PHP"><code>&lt;head&gt;
  &lt;?php if ( is_page( &#39;sample&#39; ) ): ?&gt;
    &lt;!-- 固定ページ「sample」に読み込むCSS --&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php echo get_template_directory_uri(); ?&gt;/css/sample.css&quot;&gt;
  &lt;?php endif; ?&gt;
&lt;/head&gt;</code></pre></div>



<p class="is-style-balloon_box wp-block-paragraph">（例２-２）複数の「特定の固定ページ」にsample.cssを読み込ませる</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="header.php" data-lang="PHP"><code>&lt;head&gt;
  &lt;?php if ( is_page( array( &#39;sample01&#39;, &#39;sample02&#39; ) ) ): ?&gt;
    &lt;!-- 固定ページ「sample01」と「sample02」に読み込むCSS --&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php echo get_template_directory_uri(); ?&gt;/css/sample.css&quot;&gt;
  &lt;?php endif; ?&gt;
&lt;/head&gt;</code></pre></div>



<div class="wp-block-group is-style-big_icon_good"><div class="wp-block-group__inner-container">
<p class="wp-block-paragraph"><strong>is_page()</strong>の引数に<strong>固定ページのスラッグ</strong>を指定することで、そのページにだけsample.cssを読み込ませています。<br><strong>複数のページを指定する場合（例２-２）</strong>は、array()で配列として指定します。</p>
</div></div>



<p class="is-style-balloon_box wp-block-paragraph">（例３）「特定の固定ページ」と「特定の投稿ページ」にそれぞれのCSSファイルを読み込ませる</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="header.php" data-lang="PHP"><code>&lt;head&gt;
  &lt;?php if ( is_page( &#39;sample-page&#39; ) ): ?&gt;
    &lt;!-- 固定ページ「sample-page」に読み込むCSS --&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php echo get_template_directory_uri(); ?&gt;/css/sample-page.css&quot;&gt;
  &lt;?php elseif ( is_single( &#39;sample-single&#39; ) ): ?&gt;
    &lt;!-- 投稿ページ「sample-single」に読み込むCSS --&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php echo get_template_directory_uri(); ?&gt;/css/sample-single.css&quot;&gt;
  &lt;?php endif; ?&gt;
&lt;/head&gt;</code></pre></div>



<p class="is-style-big_icon_check wp-block-paragraph"><strong>is_page()とis_single()をelseif文で分岐する</strong>ことで「固定ページ」と「投稿ページ」にそれぞれのCSSファイルを読み込ませています。</p>



<p class="is-style-balloon_box wp-block-paragraph">（例４）「特定の固定ページ」と「特定の投稿ページ」に同じCSSファイルを読み込ませる</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="header.php" data-lang="PHP"><code>&lt;head&gt;
  &lt;?php if ( is_page( &#39;sample-page&#39; ) || is_single( &#39;sample-single&#39; ) ): ?&gt;
    &lt;!-- 固定ページ「sample-page」と投稿ページ「sample-single」に読み込むCSS --&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php echo get_template_directory_uri(); ?&gt;/css/sample.css&quot;&gt;
  &lt;?php endif; ?&gt;
&lt;/head&gt;</code></pre></div>



<p class="is-style-big_icon_check wp-block-paragraph"><strong>複数の特定のページに同じCSSファイルを読み込ませたいとき</strong>は<strong>「||（または）」演算子</strong>で条件をつなぎます。</p>



<p class="has-text-align-center is-style-balloon_box2 wp-block-paragraph"><strong>スラッグ</strong>は<strong><span style="background-color:#fff2cf" class="swl-bg-color">管理画面「投稿（固定ページ）一覧」→ 記事の「クイック編集」</span></strong>でご確認いただけます。</p>


<div class="wp-block-image is-style-shadow size_s">
<figure class="aligncenter size-full"><img decoding="async" width="858" height="364" src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page01.jpg" alt="スラッグの確認方法" class="wp-image-10572" srcset="https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page01.jpg 858w, https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page01-300x127.jpg 300w, https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page01-768x326.jpg 768w" sizes="(max-width: 858px) 100vw, 858px" /><figcaption class="wp-element-caption">スラッグの確認方法</figcaption></figure>
</div>


<p class="is-style-balloon_box2 wp-block-paragraph"><strong>条件分岐タグ</strong>について詳しく知りたい方は<a href="https://kekenta-it-blog.com/wp-temptag-ispage/">以下の記事</a>がおすすめです</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type2" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2024/07/eye-catch__wp-temptag-ispage__8933-300x169.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://kekenta-it-blog.com/wp-temptag-ispage/">【WordPress】is_page？条件分岐タグって？分かりやすく解説！</a>
						<span class="p-blogCard__excerpt">WordPressには「テンプレートタグ」という、プログラミング言語で言うところの「関数」が多数用意されています。 今回はその中でも比較的使用頻度が高いis_page()につい&#8230;</span>					</div>
				</div>
			</div>
		</div>


<p class="wp-block-paragraph"><span style="--the-icon-svg: url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjFlbSIgd2lkdGg9IjFlbSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBhcmlhLWhpZGRlbj0idHJ1ZSIgdmlld0JveD0iMCAwIDQ4IDQ4Ij48cGF0aCBkPSJtMjUuMSAxNSAxMy4xIDEzLjFjLjguOC44IDIgMCAyLjgtLjguOC0yIC44LTIuOCAwTDI0IDE5LjYgMTIuNyAzMC45Yy0uOC44LTIgLjgtMi44IDAtLjgtLjgtLjgtMiAwLTIuOGwxMy0xMy4xYy42LS42IDEuNi0uNiAyLjIgMHoiPjwvcGF0aD48L3N2Zz4=)" data-icon="LsChevronTop" data-id="0" aria-hidden="true" class="swl-inline-icon"> </span><a href="#fast-list">おすすめの</a><a href="#fast-list">方法一覧に戻る</a></p>


<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4374558503914683"
     crossorigin="anonymous"></script>
<!-- ディスプレイ【横長】 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-4374558503914683"
     data-ad-slot="9744298852"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<h2 class="wp-block-heading" id="in-edit">【方法③】記事編集ページで読み込ませる</h2>



<p class="has-text-align-center is-style-bg_stripe wp-block-paragraph"><strong>記事の編集ページの「カスタムHTML」に直書きする方法</strong>です。<br>※ご紹介する方法の中で<strong>もっとも手軽な方法である一方、メンテナンス性に欠けます。</strong></p>



<p class="wp-block-paragraph">以下のように、<strong>記事に「カスタムHTML」を設置し、その中に「&lt;style&gt;タグ」を記述</strong>します。</p>


<div class="wp-block-image is-style-shadow size_s">
<figure class="aligncenter size-full"><img decoding="async" width="885" height="312" src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/image-6.png" alt="カスタムHTMLでCSSを記述" class="wp-image-10530" srcset="https://kekenta-it-blog.com/wp-content/uploads/2024/08/image-6.png 885w, https://kekenta-it-blog.com/wp-content/uploads/2024/08/image-6-300x106.png 300w, https://kekenta-it-blog.com/wp-content/uploads/2024/08/image-6-768x271.png 768w" sizes="(max-width: 885px) 100vw, 885px" /><figcaption class="wp-element-caption">カスタムHTMLでCSSを記述</figcaption></figure>
</div>


<p class="wp-block-paragraph">このようにすることで、<strong><span class="swl-marker mark_yellow">簡単に記事ごとにCSSを書き分けることが可能</span></strong>です。</p>



<p class="wp-block-paragraph"><span style="--the-icon-svg: url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjFlbSIgd2lkdGg9IjFlbSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBhcmlhLWhpZGRlbj0idHJ1ZSIgdmlld0JveD0iMCAwIDQ4IDQ4Ij48cGF0aCBkPSJtMjUuMSAxNSAxMy4xIDEzLjFjLjguOC44IDIgMCAyLjgtLjguOC0yIC44LTIuOCAwTDI0IDE5LjYgMTIuNyAzMC45Yy0uOC44LTIgLjgtMi44IDAtLjgtLjgtLjgtMiAwLTIuOGwxMy0xMy4xYy42LS42IDEuNi0uNiAyLjIgMHoiPjwvcGF0aD48L3N2Zz4=)" data-icon="LsChevronTop" data-id="0" aria-hidden="true" class="swl-inline-icon"> </span><a href="#fast-list">おすすめの</a><a href="#fast-list">方法一覧に戻る</a></p>



<h2 class="wp-block-heading" id="in-template">【方法④】テンプレートファイルで読み込ませる</h2>



<p class="has-text-align-center is-style-bg_stripe wp-block-paragraph"><strong>テンプレートファイル内に直書きする方法</strong>です。</p>



<p class="wp-block-paragraph">以下のように、対象となるテンプレートファイルに直接CSSファイルを読み込みます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="テンプレートファイル.php" data-lang="PHP"><code>&lt;link rel=&quot;stylesheet&quot; href=“&lt;?php echo get_template_directory_uri(); ?&gt;/css/page-sample.css”&gt;

&lt;?php get_header(); ?&gt;

/* 省略 */</code></pre></div>



<p class="is-style-icon_info wp-block-paragraph">メンテナンス性に欠けるため基本的におすすめはしません。<br>この方法を採用できる方は、恐らく大半がオリジナルテーマを利用されている＝一定の技術力をお持ちかと思うので、可能なら<a href="#in-functions">functions.phpで読み込む方法</a>を推奨します。</p>



<p class="wp-block-paragraph"><span style="--the-icon-svg: url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjFlbSIgd2lkdGg9IjFlbSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBhcmlhLWhpZGRlbj0idHJ1ZSIgdmlld0JveD0iMCAwIDQ4IDQ4Ij48cGF0aCBkPSJtMjUuMSAxNSAxMy4xIDEzLjFjLjguOC44IDIgMCAyLjgtLjguOC0yIC44LTIuOCAwTDI0IDE5LjYgMTIuNyAzMC45Yy0uOC44LTIgLjgtMi44IDAtLjgtLjgtLjgtMiAwLTIuOGwxMy0xMy4xYy42LS42IDEuNi0uNiAyLjIgMHoiPjwvcGF0aD48L3N2Zz4=)" data-icon="LsChevronTop" data-id="0" aria-hidden="true" class="swl-inline-icon"> </span><a href="#fast-list">おすすめの</a><a href="#fast-list">方法一覧に戻る</a></p>



<h2 class="wp-block-heading" id="use-plugin">【方法⑤】プラグイン「WP Add Custom CSS」を使用する</h2>



<p class="has-text-align-center is-style-bg_stripe wp-block-paragraph"><strong>プラグイン「WP Add Custom CSS」を使用して、<br>各記事編集ページにCSS入力用のフォームを設置する方法</strong>です。</p>



<p class="is-style-icon_info wp-block-paragraph">冒頭でもお伝えしましたが、プラグイン「WP Add Custom CSS」は<strong><span class="swl-marker mark_orange">最終アップデートが2022年でストップ</span></strong>しています。<br>これはセキュリティリスクにも関わることのため、利用する際はその点をご留意ください。</p>



<p class="is-style-balloon_box wp-block-paragraph"><strong>【代替案】プラグイン「WP Add Custom CSS」の機能を自分で実装する</strong></p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type2" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/eye-catch__wp-inputform-for-css-js__10597-300x169.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://kekenta-it-blog.com/wp-inputform-for-css-js/">【WordPress】固定・投稿ページ編集画面にCSSやJSの入力フォームを設置する</a>
						<span class="p-blogCard__excerpt">特定の固定ページや投稿ページごとに簡単にCSSとかJavaScriptを設定できるようにしたいな…… 今回はこのようなお悩みをお持ちの方に向けて 固定ページ編集画面や投稿ペー&#8230;</span>					</div>
				</div>
			</div>
		</div>


<h3 class="wp-block-heading"><strong>プラグイン「WP Add Custom CSS」</strong>の使い方</h3>



<div class="swell-block-step" data-num-style="circle">
<div class="swell-block-step__item"><div class="swell-block-step__number u-bg-main"><span class="__label">STEP</span></div><div class="swell-block-step__title u-fz-l"><strong>プラグイン「WP Add Custom CSS」をインストールする</strong></div><div class="swell-block-step__body"><div class="wp-block-image is-style-shadow">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="570" src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page02-1024x570.jpg" alt="プラグイン「WP Add Custom CSS」をインストールする" class="wp-image-10570" srcset="https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page02-1024x570.jpg 1024w, https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page02-300x167.jpg 300w, https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page02-768x427.jpg 768w, https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page02-1536x855.jpg 1536w, https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page02.jpg 1553w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">プラグイン「WP Add Custom CSS」をインストールする</figcaption></figure>
</div>


<p class="is-style-icon_pen wp-block-paragraph">僕がインストールするときは<strong>検索結果のかなり下の方</strong>にありました。</p>
</div></div>



<div class="swell-block-step__item"><div class="swell-block-step__number u-bg-main"><span class="__label">STEP</span></div><div class="swell-block-step__title u-fz-l">固定・投稿ページの編集画面でCSSを記述する</div><div class="swell-block-step__body">
<p class="is-style-bg_stripe wp-block-paragraph">プラグイン「WP Add Custom CSS」を有効化すると、固定・投稿ページの下の方にCSSの入力フォームが表示されるようになります。</p>


<div class="wp-block-image is-style-shadow">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="738" src="https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page03-1024x738.jpg" alt="固定・投稿ページの編集画面でCSSを記述する" class="wp-image-10571" srcset="https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page03-1024x738.jpg 1024w, https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page03-300x216.jpg 300w, https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page03-768x553.jpg 768w, https://kekenta-it-blog.com/wp-content/uploads/2024/08/wp-read-css-per-page03.jpg 1199w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">固定・投稿ページの編集画面でCSSを記述する</figcaption></figure>
</div>


<p class="is-style-big_icon_check wp-block-paragraph">この入力フォームに記述したCSSは、そのページにだけ適用されます。</p>
</div></div>
</div>



<p class="wp-block-paragraph"><span style="--the-icon-svg: url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjFlbSIgd2lkdGg9IjFlbSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBhcmlhLWhpZGRlbj0idHJ1ZSIgdmlld0JveD0iMCAwIDQ4IDQ4Ij48cGF0aCBkPSJtMjUuMSAxNSAxMy4xIDEzLjFjLjguOC44IDIgMCAyLjgtLjguOC0yIC44LTIuOCAwTDI0IDE5LjYgMTIuNyAzMC45Yy0uOC44LTIgLjgtMi44IDAtLjgtLjgtLjgtMiAwLTIuOGwxMy0xMy4xYy42LS42IDEuNi0uNiAyLjIgMHoiPjwvcGF0aD48L3N2Zz4=)" data-icon="LsChevronTop" data-id="0" aria-hidden="true" class="swl-inline-icon"> </span><a href="#fast-list">おすすめの</a><a href="#fast-list">方法一覧に戻る</a></p>


<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4374558503914683"
     crossorigin="anonymous"></script>
<!-- ディスプレイ【横長】 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-4374558503914683"
     data-ad-slot="9744298852"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<h2 class="wp-block-heading">まとめ</h2>



<p class="wp-block-paragraph">以上が<strong>WordPressの特定のページでCSSを読み込む方法</strong>です。</p>



<p class="wp-block-paragraph">方法自体はいくつもありますが、<strong><span class="swl-marker mark_yellow">適切な方法はテーマの使用状況によって変わってきます。</span></strong></p>



<p class="wp-block-paragraph">今回は<a href="#fast-list">おすすめの方法一覧</a>もご用意していますので、ぜひその中からご自身の状況にあった方法をお選びいただければと思います。</p>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>最後までご覧いただきありがとうございました！</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p class="wp-block-paragraph">このブログではWordPressやWeb制作、PHPに関する情報を発信しています。</p>



<p class="wp-block-paragraph">ご興味のある方はほかの記事もご覧いただけるとうれしいです。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://kekenta-it-blog.com/wp-read-css-per-page/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【WordPress】固定ページや投稿ページなどページ種別ごとに背景色を設定する</title>
		<link>https://kekenta-it-blog.com/wp-init-bg-by-pagetype/</link>
					<comments>https://kekenta-it-blog.com/wp-init-bg-by-pagetype/#respond</comments>
		
		<dc:creator><![CDATA[ケケンタ]]></dc:creator>
		<pubDate>Wed, 26 Jun 2024 08:11:24 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[ページごと]]></category>
		<category><![CDATA[背景色]]></category>
		<guid isPermaLink="false">https://kekenta-it-blog.com/?p=8690</guid>

					<description><![CDATA[<p><img src="https://kekenta-it-blog.com/wp-content/uploads/2024/06/eye-catch__wp-init-bg-by-pagetype__8690-1024x576.jpg" class="webfeedsFeaturedVisual" /></p>以前に以下の記事で「特定のページごとに背景色を変更する方法」を解説しました。 しかし、中には という方もいらっしゃるかと思います。 そこで今回は、 固定ページ・投稿ページ・カテゴリーページなどページ種類に応じて背景色を設 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://kekenta-it-blog.com/wp-content/uploads/2024/06/eye-catch__wp-init-bg-by-pagetype__8690-1024x576.jpg" class="webfeedsFeaturedVisual" /></p>
<p class="wp-block-paragraph">以前に以下の記事で「特定のページごとに背景色を変更する方法」を解説しました。</p>


<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-bg-up/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-externalLink __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M44 2H30c-1.1 0-2 .9-2 2s.9 2 2 2h9.2L24 21.2c-.8.8-.8 2 0 2.8s2 .8 2.8 0L42 8.8V18c0 1.1.9 2 2 2s2-.9 2-2V4c0-1.1-.9-2-2-2z" /><path d="M41 27c-1.1 0-2 .9-2 2v10c0 1.1-.9 2-2 2H9c-1.1 0-2-.9-2-2V11c0-1.1.9-2 2-2h10c1.1 0 2-.9 2-2s-.9-2-2-2H9c-3.3 0-6 2.7-6 6v28c0 3.3 2.7 6 6 6h28c3.3 0 6-2.7 6-6V29c0-1.1-.9-2-2-2z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】特定のページのみ背景色を変える方法</span>
			</a>
		</div>


<p class="wp-block-paragraph">しかし、中には</p>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/困った顔-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/困った顔-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>「ページごと」っていう細かい括りじゃなくて、「固定ページ」、「投稿ページ」って感じで<strong><span class="swl-marker mark_yellow">もっと大きな枠ごとに設定したいんだよな</span></strong></p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p class="wp-block-paragraph">という方もいらっしゃるかと思います。</p>



<p class="wp-block-paragraph">そこで今回は、</p>



<p class="has-text-align-center is-style-big_kakko_box wp-block-paragraph"><strong>固定ページ・投稿ページ・カテゴリーページなど<br>ページ種類に応じて背景色を設定する方法</strong></p>



<p class="wp-block-paragraph">をご紹介していきます。</p>


<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-subloop-wq/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】WP_Query（サブループ）の使い方とパラメータ一覧を紹介</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-edit-functions/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】functions.phpを編集する「３つ」の方法と編集時の注意点</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-how-to-load-js/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】JavaScriptはどこに書けばいい？「３つの方法」を解説</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/change-to-swell/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">無料テーマCocoonからSWELLに乗り換えた７つの理由【WordPress】</span>
			</a>
		</div>

<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type2" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2025/03/eye-catch__school-php-and-wp__14099-300x169.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://kekenta-it-blog.com/school-php-and-wp/">PHPやWordPressを学ぶのにおすすめのプログラミングスクール【７選】</a>
						<span class="p-blogCard__excerpt">僕はこれまで独学でPHPを学習してきました。結論から言えば、それでもPHPを習得することはできました。 しかし、それに費やした累計学習期間は1年ほど。モチベーション&#8230;</span>					</div>
				</div>
			</div>
		</div>


<h2 class="wp-block-heading">ソースコード</h2>



<p class="is-style-bg_stripe wp-block-paragraph">早速ですが、<strong>ベースとなるソースコード</strong>は以下のようになります。</p>



<p class="is-style-balloon_box wp-block-paragraph"><span data-icon="LsLightbulb" data-id="0" style="--the-icon-svg: url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjFlbSIgd2lkdGg9IjFlbSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBhcmlhLWhpZGRlbj0idHJ1ZSIgdmlld0JveD0iMCAwIDQ4IDQ4Ij48cGF0aCBkPSJNMzIgNDYuNUgxNmMtMS4xIDAtMi0uOS0yLTJzLjktMiAyLTJoMTZjMS4xIDAgMiAuOSAyIDJzLS45IDItMiAyek00MS43IDE1LjlDNDEuMyAxMyA0MCAxMC4zIDM4LjIgOCAzNC41IDMuMiAyOSAuOCAyMy4xIDEgMTQgMS40IDYuNSA4LjkgNiAxOGMtLjMgNiAyLjQgMTEuNyA3LjIgMTUuNC41LjQuOC45LjggMS41djEuNmMwIDIuMiAxLjggNCA0IDRoMTJjMi4yIDAgNC0xLjggNC00VjM1YzAtLjYuMy0xLjIuOS0xLjcgNS4zLTQgOC0xMC42IDYuOC0xNy40em0tNy4xIDEuN2gtLjNjLS43IDAtMS4zLS41LTEuNS0xLjItLjctMy4yLTMuMi01LjctNi40LTYuMy0uOC0uMS0xLjQtLjktMS4yLTEuN3MuOS0xLjQgMS43LTEuMmM0LjQuOCA4IDQuMiA4LjkgOC42LjEuOC0uNCAxLjYtMS4yIDEuOHoiPjwvcGF0aD48L3N2Zz4=)" aria-hidden="true" class="swl-inline-icon"> </span><strong>下記のソースコードをfunctions.phpへ記述する</strong></p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>function my_headinputtags() {
  $headinputtag = &#39;&#39;;

  if ( ページ種類の判定条件 ) {
    $headinputtag = &lt;&lt;&lt;EOM
      &lt;style&gt;
        body {
          background-color: ここに任意のカラーを設定;
        }
      &lt;/style&gt;
    EOM;
  } 
  echo $headinputtag;
  }
  add_action( &#39;wp_head&#39;, &#39;my_headinputtags&#39;, 99);</code></pre></div>



<p class="is-style-big_icon_check wp-block-paragraph">上記のソースコードに、「<strong>ページ種類を判定するための条件分岐タグ</strong>」と「<strong>任意のカラー</strong>」を設定するだけで、ページ種類ごとに背景色を変えることが可能です。</p>



<p class="has-text-align-center is-style-balloon_box2 wp-block-paragraph">（例）固定ページの背景色を「green」に設定</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>function my_headinputtags() {
  $headinputtag = &#39;&#39;;

  if ( is_page() ) {  // 固定ページかどうかを判定
    $headinputtag = &lt;&lt;&lt;EOM
      &lt;style&gt;
        body {
          background-color: green; // カラーに「green（緑）」を指定
        }
      &lt;/style&gt;
    EOM;
  } 
  echo $headinputtag;
  }
  add_action( &#39;wp_head&#39;, &#39;my_headinputtags&#39;, 99);</code></pre></div>



<p class="is-style-balloon_box wp-block-paragraph"><span style="--the-icon-svg: url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjFlbSIgd2lkdGg9IjFlbSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBhcmlhLWhpZGRlbj0idHJ1ZSIgdmlld0JveD0iMCAwIDQ4IDQ4Ij48cGF0aCBkPSJNMzIgNDYuNUgxNmMtMS4xIDAtMi0uOS0yLTJzLjktMiAyLTJoMTZjMS4xIDAgMiAuOSAyIDJzLS45IDItMiAyek00MS43IDE1LjlDNDEuMyAxMyA0MCAxMC4zIDM4LjIgOCAzNC41IDMuMiAyOSAuOCAyMy4xIDEgMTQgMS40IDYuNSA4LjkgNiAxOGMtLjMgNiAyLjQgMTEuNyA3LjIgMTUuNC41LjQuOC45LjggMS41djEuNmMwIDIuMiAxLjggNCA0IDRoMTJjMi4yIDAgNC0xLjggNC00VjM1YzAtLjYuMy0xLjIuOS0xLjcgNS4zLTQgOC0xMC42IDYuOC0xNy40em0tNy4xIDEuN2gtLjNjLS43IDAtMS4zLS41LTEuNS0xLjItLjctMy4yLTMuMi01LjctNi40LTYuMy0uOC0uMS0xLjQtLjktMS4yLTEuN3MuOS0xLjQgMS43LTEuMmM0LjQuOCA4IDQuMiA4LjkgOC42LjEuOC0uNCAxLjYtMS4yIDEuOHoiPjwvcGF0aD48L3N2Zz4=)" data-icon="LsLightbulb" data-id="0" aria-hidden="true" class="swl-inline-icon"> </span><strong>functions.phpの編集方法がご不明な場合は、こちらの記事をご覧ください</strong></p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type2" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2024/10/eye-catch__wp-edit-functions__11133-300x169.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://kekenta-it-blog.com/wp-edit-functions/">【WordPress】functions.phpを編集する「３つ」の方法と編集時の注意点</a>
						<span class="p-blogCard__excerpt">WordPressで機能カスタマイズをする際は、必ずと言っていいほどfunctions.phpを編集することになります。 しかし、functions.phpを編集したことで何らかのエラーが発生&#8230;</span>					</div>
				</div>
			</div>
		</div>


<h2 class="wp-block-heading">主要な条件分岐タグ</h2>



<p class="is-style-bg_stripe wp-block-paragraph">ご参考までに、主要な条件分岐タグをいくつか掲載します。</p>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>ページ種類の判定にご活用ください。</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<figure class="wp-block-table is-thead-centered"><table><thead><tr><th>条件分岐タグ</th><th>判定内容</th></tr></thead><tbody><tr><th>is_front_page()</th><td>トップページかどうか判定</td></tr><tr><th>is_home()</th><td>投稿一覧ページかどうか判定</td></tr><tr><th>is_page()</th><td>固定ページかどうか判定</td></tr><tr><th>is_single()</th><td>投稿ページかどうか判定</td></tr><tr><th>is_category()</th><td>カテゴリーページかどうか判定</td></tr><tr><th>is_tag()</th><td>タグページかどうか判定</td></tr></tbody></table><figcaption class="wp-element-caption">主要な条件分岐タグ</figcaption></figure>



<h2 class="wp-block-heading">まとめ</h2>



<p class="wp-block-paragraph">以上が<strong>ページ種類ごとに背景色を変更する方法</strong>でした。</p>



<p class="wp-block-paragraph">今回ご紹介したソースコードを使用すれば簡単に実装可能ですので、ぜひご活用いただけると嬉しいです。</p>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>それでは、最後までご覧いただきありがとうございました。</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p class="wp-block-paragraph">当ブログではWordPressやWeb制作、PHPに関する情報を発信しています。<br>他の記事もご覧いただけると嬉しいです。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type2" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2024/10/eye-catch__wp-edit-functions__11133-300x169.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://kekenta-it-blog.com/wp-edit-functions/">【WordPress】functions.phpを編集する「３つ」の方法と編集時の注意点</a>
						<span class="p-blogCard__excerpt">WordPressで機能カスタマイズをする際は、必ずと言っていいほどfunctions.phpを編集することになります。 しかし、functions.phpを編集したことで何らかのエラーが発生&#8230;</span>					</div>
				</div>
			</div>
		</div>

<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type2" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2024/05/eye-catch__wp-bg-up__6665-300x169.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://kekenta-it-blog.com/wp-bg-up/">【WordPress】特定のページのみ背景色を変える方法</a>
						<span class="p-blogCard__excerpt">WordPressで特定のページだけ背景色を変えたいんだけどやり方がわからない…… 今回はこのようなお悩みについて解説をしていきます。  この記事で分かること WordPressの&#8230;</span>					</div>
				</div>
			</div>
		</div>]]></content:encoded>
					
					<wfw:commentRss>https://kekenta-it-blog.com/wp-init-bg-by-pagetype/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
