<?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>Developry Plugins</title>
	<atom:link href="https://developryplugins.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://developryplugins.com/</link>
	<description></description>
	<lastBuildDate>Mon, 24 Nov 2025 11:18:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://developryplugins.com/wp-content/uploads/2026/06/cropped-favicon-alt-32x32.webp</url>
	<title>Developry Plugins</title>
	<link>https://developryplugins.com/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to Add Custom Block Patterns to WordPress Block Editor</title>
		<link>https://developryplugins.com/how-to-add-custom-block-patterns-to-wordpress-block-editor/</link>
		
		<dc:creator><![CDATA[Krasen Slavov]]></dc:creator>
		<pubDate>Tue, 25 Aug 2026 09:00:00 +0000</pubDate>
				<category><![CDATA[Block Editor & Gutenberg Tutorials]]></category>
		<category><![CDATA[block patterns]]></category>
		<category><![CDATA[content templates]]></category>
		<category><![CDATA[gutenberg patterns]]></category>
		<category><![CDATA[pattern library]]></category>
		<category><![CDATA[wordpress patterns]]></category>
		<guid isPermaLink="false">https://developryplugins.com/?p=127</guid>

					<description><![CDATA[<p>Block patterns revolutionize WordPress content creation by providing pre-designed layouts users can insert with one click. This guide shows you how to create custom patterns that accelerate workflow, maintain design...</p>
<p>The post <a href="https://developryplugins.com/how-to-add-custom-block-patterns-to-wordpress-block-editor/">How to Add Custom Block Patterns to WordPress Block Editor</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><!-- @format --></p>
<p>Block patterns revolutionize WordPress content creation by providing pre-designed layouts users can insert with one click. This guide shows you how to create custom patterns that accelerate workflow, maintain design consistency, and empower non-technical users.</p>
<h2 id="what-are-block-patterns">What Are Block Patterns?</h2>
<p>Block patterns are pre-configured collections of blocks arranged into ready-to-use designs. Unlike reusable blocks (synchronized across posts), patterns insert independent copies—users can modify them freely without affecting other instances.</p>
<p>Patterns bridge the gap between full-page templates and individual blocks, offering flexible starting points for common layouts like hero sections, testimonials, pricing tables, and calls-to-action.</p>
<h2 id="creating-your-first-custom-pattern">Creating Your First Custom Pattern</h2>
<p>Register patterns using <code>register_block_pattern()</code> in your theme’s <code>functions.php</code> or plugin:</p>
<div class="sourceCode" id="cb1">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true"></a><span class="kw">function</span> register_custom_patterns<span class="ot">()</span> {</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true"></a>    register_block_pattern<span class="ot">(</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true"></a>        <span class="st">&#39;myplugin/hero-section&#39;</span><span class="ot">,</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true"></a>            <span class="st">&#39;title&#39;</span>       =&gt; <span class="st">&#39;Hero Section&#39;</span><span class="ot">,</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true"></a>            <span class="st">&#39;description&#39;</span> =&gt; <span class="st">&#39;Eye-catching hero with heading, text, and button&#39;</span><span class="ot">,</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true"></a>            <span class="st">&#39;categories&#39;</span>  =&gt; <span class="kw">array</span><span class="ot">(</span> <span class="st">&#39;featured&#39;</span> <span class="ot">),</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true"></a>            <span class="st">&#39;content&#39;</span>     =&gt; <span class="st">&#39;&lt;!-- wp:cover {&quot;url&quot;:&quot;https://example.com/hero.jpg&quot;,&quot;dimRatio&quot;:50} --&gt;</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true"></a><span class="st">                &lt;div class=&quot;wp-block-cover&quot;&gt;</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true"></a><span class="st">                    &lt;span aria-hidden=&quot;true&quot; class=&quot;wp-block-cover__background has-background-dim&quot;&gt;&lt;/span&gt;</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true"></a><span class="st">                    &lt;img class=&quot;wp-block-cover__image-background&quot; src=&quot;https://example.com/hero.jpg&quot; /&gt;</span></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true"></a><span class="st">                    &lt;div class=&quot;wp-block-cover__inner-container&quot;&gt;</span></span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true"></a><span class="st">                        &lt;!-- wp:heading {&quot;level&quot;:1} --&gt;</span></span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true"></a><span class="st">                        &lt;h1&gt;Welcome to Our Site&lt;/h1&gt;</span></span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true"></a><span class="st">                        &lt;!-- /wp:heading --&gt;</span></span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true"></a></span>
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true"></a><span class="st">                        &lt;!-- wp:paragraph --&gt;</span></span>
<span id="cb1-18"><a href="#cb1-18" aria-hidden="true"></a><span class="st">                        &lt;p&gt;Discover amazing products and services.&lt;/p&gt;</span></span>
<span id="cb1-19"><a href="#cb1-19" aria-hidden="true"></a><span class="st">                        &lt;!-- /wp:paragraph --&gt;</span></span>
<span id="cb1-20"><a href="#cb1-20" aria-hidden="true"></a></span>
<span id="cb1-21"><a href="#cb1-21" aria-hidden="true"></a><span class="st">                        &lt;!-- wp:buttons --&gt;</span></span>
<span id="cb1-22"><a href="#cb1-22" aria-hidden="true"></a><span class="st">                        &lt;div class=&quot;wp-block-buttons&quot;&gt;</span></span>
<span id="cb1-23"><a href="#cb1-23" aria-hidden="true"></a><span class="st">                            &lt;!-- wp:button --&gt;</span></span>
<span id="cb1-24"><a href="#cb1-24" aria-hidden="true"></a><span class="st">                            &lt;div class=&quot;wp-block-button&quot;&gt;</span></span>
<span id="cb1-25"><a href="#cb1-25" aria-hidden="true"></a><span class="st">                                &lt;a class=&quot;wp-block-button__link&quot;&gt;Get Started&lt;/a&gt;</span></span>
<span id="cb1-26"><a href="#cb1-26" aria-hidden="true"></a><span class="st">                            &lt;/div&gt;</span></span>
<span id="cb1-27"><a href="#cb1-27" aria-hidden="true"></a><span class="st">                            &lt;!-- /wp:button --&gt;</span></span>
<span id="cb1-28"><a href="#cb1-28" aria-hidden="true"></a><span class="st">                        &lt;/div&gt;</span></span>
<span id="cb1-29"><a href="#cb1-29" aria-hidden="true"></a><span class="st">                        &lt;!-- /wp:buttons --&gt;</span></span>
<span id="cb1-30"><a href="#cb1-30" aria-hidden="true"></a><span class="st">                    &lt;/div&gt;</span></span>
<span id="cb1-31"><a href="#cb1-31" aria-hidden="true"></a><span class="st">                &lt;/div&gt;</span></span>
<span id="cb1-32"><a href="#cb1-32" aria-hidden="true"></a><span class="st">                &lt;!-- /wp:cover --&gt;&#39;</span><span class="ot">,</span></span>
<span id="cb1-33"><a href="#cb1-33" aria-hidden="true"></a>        <span class="ot">)</span></span>
<span id="cb1-34"><a href="#cb1-34" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb1-35"><a href="#cb1-35" aria-hidden="true"></a>}</span>
<span id="cb1-36"><a href="#cb1-36" aria-hidden="true"></a>add_action<span class="ot">(</span> <span class="st">&#39;init&#39;</span><span class="ot">,</span> <span class="st">&#39;register_custom_patterns&#39;</span> <span class="ot">);</span></span></code></pre>
</div>
<h2 id="getting-block-markup">Getting Block Markup</h2>
<p>The easiest way to create pattern content is building it in the editor, then copying the markup:</p>
<ol type="1">
<li>Create your design in the editor</li>
<li>Switch to Code Editor (⋮ menu → Code editor)</li>
<li>Copy the HTML comments and blocks</li>
<li>Paste into the <code>content</code> property</li>
</ol>
<h2 id="creating-pattern-categories">Creating Pattern Categories</h2>
<p>Organize patterns with custom categories:</p>
<div class="sourceCode" id="cb2">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true"></a><span class="kw">function</span> register_pattern_categories<span class="ot">()</span> {</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true"></a>    register_block_pattern_category<span class="ot">(</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true"></a>        <span class="st">&#39;business&#39;</span><span class="ot">,</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span> <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Business&#39;</span> <span class="ot">)</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true"></a></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true"></a>    register_block_pattern_category<span class="ot">(</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true"></a>        <span class="st">&#39;marketing&#39;</span><span class="ot">,</span></span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span> <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Marketing&#39;</span> <span class="ot">)</span></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true"></a>}</span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true"></a>add_action<span class="ot">(</span> <span class="st">&#39;init&#39;</span><span class="ot">,</span> <span class="st">&#39;register_pattern_categories&#39;</span> <span class="ot">);</span></span></code></pre>
</div>
<h2 id="advanced-pattern-properties">Advanced Pattern Properties</h2>
<p>Enhance patterns with additional properties:</p>
<div class="sourceCode" id="cb3">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true"></a>register_block_pattern<span class="ot">(</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true"></a>    <span class="st">&#39;myplugin/testimonial&#39;</span><span class="ot">,</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true"></a>    <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true"></a>        <span class="st">&#39;title&#39;</span>       =&gt; <span class="st">&#39;Testimonial Card&#39;</span><span class="ot">,</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true"></a>        <span class="st">&#39;description&#39;</span> =&gt; <span class="st">&#39;Customer testimonial with quote and attribution&#39;</span><span class="ot">,</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true"></a>        <span class="st">&#39;categories&#39;</span>  =&gt; <span class="kw">array</span><span class="ot">(</span> <span class="st">&#39;text&#39;</span><span class="ot">,</span> <span class="st">&#39;business&#39;</span> <span class="ot">),</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true"></a>        <span class="st">&#39;keywords&#39;</span>    =&gt; <span class="kw">array</span><span class="ot">(</span> <span class="st">&#39;review&#39;</span><span class="ot">,</span> <span class="st">&#39;quote&#39;</span><span class="ot">,</span> <span class="st">&#39;customer&#39;</span> <span class="ot">),</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true"></a>        <span class="st">&#39;viewportWidth&#39;</span> =&gt; <span class="dv">800</span><span class="ot">,</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true"></a>        <span class="st">&#39;blockTypes&#39;</span>  =&gt; <span class="kw">array</span><span class="ot">(</span> <span class="st">&#39;core/column&#39;</span> <span class="ot">),</span> <span class="co">// Show pattern only for specific blocks</span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true"></a>        <span class="st">&#39;content&#39;</span>     =&gt; <span class="st">&#39;&lt;!-- pattern markup --&gt;&#39;</span></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true"></a>    <span class="ot">)</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true"></a><span class="ot">);</span></span></code></pre>
</div>
<h2 id="testimonial-pattern-example">Testimonial Pattern Example</h2>
<div class="sourceCode" id="cb4">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true"></a>register_block_pattern<span class="ot">(</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true"></a>    <span class="st">&#39;myplugin/testimonial-card&#39;</span><span class="ot">,</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true"></a>    <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true"></a>        <span class="st">&#39;title&#39;</span> =&gt; <span class="st">&#39;Testimonial Card&#39;</span><span class="ot">,</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true"></a>        <span class="st">&#39;categories&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span> <span class="st">&#39;text&#39;</span> <span class="ot">),</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true"></a>        <span class="st">&#39;content&#39;</span> =&gt; <span class="st">&#39;&lt;!-- wp:group {&quot;style&quot;:{&quot;border&quot;:{&quot;width&quot;:&quot;1px&quot;,&quot;style&quot;:&quot;solid&quot;,&quot;color&quot;:&quot;#e5e5e5&quot;},&quot;spacing&quot;:{&quot;padding&quot;:{&quot;top&quot;:&quot;2rem&quot;,&quot;right&quot;:&quot;2rem&quot;,&quot;bottom&quot;:&quot;2rem&quot;,&quot;left&quot;:&quot;2rem&quot;}}}} --&gt;</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true"></a><span class="st">            &lt;div class=&quot;wp-block-group&quot;&gt;</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true"></a><span class="st">                &lt;!-- wp:paragraph {&quot;fontSize&quot;:&quot;large&quot;} --&gt;</span></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true"></a><span class="st">                &lt;p class=&quot;has-large-font-size&quot;&gt;&quot;This product changed my business completely. Highly recommended!&quot;&lt;/p&gt;</span></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true"></a><span class="st">                &lt;!-- /wp:paragraph --&gt;</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true"></a></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true"></a><span class="st">                &lt;!-- wp:separator --&gt;</span></span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true"></a><span class="st">                &lt;hr class=&quot;wp-block-separator&quot; /&gt;</span></span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true"></a><span class="st">                &lt;!-- /wp:separator --&gt;</span></span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true"></a></span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true"></a><span class="st">                &lt;!-- wp:paragraph --&gt;</span></span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true"></a><span class="st">                &lt;p&gt;&lt;strong&gt;John Doe&lt;/strong&gt;&lt;br&gt;CEO, Example Company&lt;/p&gt;</span></span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true"></a><span class="st">                &lt;!-- /wp:paragraph --&gt;</span></span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true"></a><span class="st">            &lt;/div&gt;</span></span>
<span id="cb4-20"><a href="#cb4-20" aria-hidden="true"></a><span class="st">            &lt;!-- /wp:group --&gt;&#39;</span><span class="ot">,</span></span>
<span id="cb4-21"><a href="#cb4-21" aria-hidden="true"></a>    <span class="ot">)</span></span>
<span id="cb4-22"><a href="#cb4-22" aria-hidden="true"></a><span class="ot">);</span></span></code></pre>
</div>
<h2 id="pricing-table-pattern">Pricing Table Pattern</h2>
<div class="sourceCode" id="cb5">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true"></a>register_block_pattern<span class="ot">(</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true"></a>    <span class="st">&#39;myplugin/pricing-table&#39;</span><span class="ot">,</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true"></a>    <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true"></a>        <span class="st">&#39;title&#39;</span> =&gt; <span class="st">&#39;Pricing Table - Three Column&#39;</span><span class="ot">,</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true"></a>        <span class="st">&#39;categories&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span> <span class="st">&#39;business&#39;</span> <span class="ot">),</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true"></a>        <span class="st">&#39;content&#39;</span> =&gt; <span class="st">&#39;&lt;!-- wp:columns --&gt;</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true"></a><span class="st">            &lt;div class=&quot;wp-block-columns&quot;&gt;</span></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true"></a><span class="st">                &lt;!-- wp:column {&quot;style&quot;:{&quot;border&quot;:{&quot;width&quot;:&quot;2px&quot;}}} --&gt;</span></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true"></a><span class="st">                &lt;div class=&quot;wp-block-column&quot;&gt;</span></span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true"></a><span class="st">                    &lt;!-- wp:heading {&quot;textAlign&quot;:&quot;center&quot;} --&gt;</span></span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true"></a><span class="st">                    &lt;h2 class=&quot;has-text-align-center&quot;&gt;Basic&lt;/h2&gt;</span></span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true"></a><span class="st">                    &lt;!-- /wp:heading --&gt;</span></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true"></a></span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true"></a><span class="st">                    &lt;!-- wp:paragraph {&quot;align&quot;:&quot;center&quot;,&quot;fontSize&quot;:&quot;large&quot;} --&gt;</span></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true"></a><span class="st">                    &lt;p class=&quot;has-text-align-center has-large-font-size&quot;&gt;&lt;strong&gt;$9/month&lt;/strong&gt;&lt;/p&gt;</span></span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true"></a><span class="st">                    &lt;!-- /wp:paragraph --&gt;</span></span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true"></a></span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true"></a><span class="st">                    &lt;!-- wp:list --&gt;</span></span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true"></a><span class="st">                    &lt;ul&gt;&lt;li&gt;Feature 1&lt;/li&gt;&lt;li&gt;Feature 2&lt;/li&gt;&lt;li&gt;Feature 3&lt;/li&gt;&lt;/ul&gt;</span></span>
<span id="cb5-20"><a href="#cb5-20" aria-hidden="true"></a><span class="st">                    &lt;!-- /wp:list --&gt;</span></span>
<span id="cb5-21"><a href="#cb5-21" aria-hidden="true"></a></span>
<span id="cb5-22"><a href="#cb5-22" aria-hidden="true"></a><span class="st">                    &lt;!-- wp:buttons {&quot;layout&quot;:{&quot;type&quot;:&quot;flex&quot;,&quot;justifyContent&quot;:&quot;center&quot;}} --&gt;</span></span>
<span id="cb5-23"><a href="#cb5-23" aria-hidden="true"></a><span class="st">                    &lt;div class=&quot;wp-block-buttons&quot;&gt;</span></span>
<span id="cb5-24"><a href="#cb5-24" aria-hidden="true"></a><span class="st">                        &lt;!-- wp:button --&gt;</span></span>
<span id="cb5-25"><a href="#cb5-25" aria-hidden="true"></a><span class="st">                        &lt;div class=&quot;wp-block-button&quot;&gt;&lt;a class=&quot;wp-block-button__link&quot;&gt;Choose Plan&lt;/a&gt;&lt;/div&gt;</span></span>
<span id="cb5-26"><a href="#cb5-26" aria-hidden="true"></a><span class="st">                        &lt;!-- /wp:button --&gt;</span></span>
<span id="cb5-27"><a href="#cb5-27" aria-hidden="true"></a><span class="st">                    &lt;/div&gt;</span></span>
<span id="cb5-28"><a href="#cb5-28" aria-hidden="true"></a><span class="st">                    &lt;!-- /wp:buttons --&gt;</span></span>
<span id="cb5-29"><a href="#cb5-29" aria-hidden="true"></a><span class="st">                &lt;/div&gt;</span></span>
<span id="cb5-30"><a href="#cb5-30" aria-hidden="true"></a><span class="st">                &lt;!-- /wp:column --&gt;</span></span>
<span id="cb5-31"><a href="#cb5-31" aria-hidden="true"></a></span>
<span id="cb5-32"><a href="#cb5-32" aria-hidden="true"></a><span class="st">                &lt;!-- wp:column {&quot;style&quot;:{&quot;border&quot;:{&quot;width&quot;:&quot;2px&quot;}}} --&gt;</span></span>
<span id="cb5-33"><a href="#cb5-33" aria-hidden="true"></a><span class="st">                &lt;div class=&quot;wp-block-column&quot;&gt;</span></span>
<span id="cb5-34"><a href="#cb5-34" aria-hidden="true"></a><span class="st">                    &lt;!-- wp:heading {&quot;textAlign&quot;:&quot;center&quot;} --&gt;</span></span>
<span id="cb5-35"><a href="#cb5-35" aria-hidden="true"></a><span class="st">                    &lt;h2 class=&quot;has-text-align-center&quot;&gt;Pro&lt;/h2&gt;</span></span>
<span id="cb5-36"><a href="#cb5-36" aria-hidden="true"></a><span class="st">                    &lt;!-- /wp:heading --&gt;</span></span>
<span id="cb5-37"><a href="#cb5-37" aria-hidden="true"></a></span>
<span id="cb5-38"><a href="#cb5-38" aria-hidden="true"></a><span class="st">                    &lt;!-- wp:paragraph {&quot;align&quot;:&quot;center&quot;,&quot;fontSize&quot;:&quot;large&quot;} --&gt;</span></span>
<span id="cb5-39"><a href="#cb5-39" aria-hidden="true"></a><span class="st">                    &lt;p class=&quot;has-text-align-center has-large-font-size&quot;&gt;&lt;strong&gt;$29/month&lt;/strong&gt;&lt;/p&gt;</span></span>
<span id="cb5-40"><a href="#cb5-40" aria-hidden="true"></a><span class="st">                    &lt;!-- /wp:paragraph --&gt;</span></span>
<span id="cb5-41"><a href="#cb5-41" aria-hidden="true"></a></span>
<span id="cb5-42"><a href="#cb5-42" aria-hidden="true"></a><span class="st">                    &lt;!-- wp:list --&gt;</span></span>
<span id="cb5-43"><a href="#cb5-43" aria-hidden="true"></a><span class="st">                    &lt;ul&gt;&lt;li&gt;Everything in Basic&lt;/li&gt;&lt;li&gt;Feature 4&lt;/li&gt;&lt;li&gt;Feature 5&lt;/li&gt;&lt;/ul&gt;</span></span>
<span id="cb5-44"><a href="#cb5-44" aria-hidden="true"></a><span class="st">                    &lt;!-- /wp:list --&gt;</span></span>
<span id="cb5-45"><a href="#cb5-45" aria-hidden="true"></a></span>
<span id="cb5-46"><a href="#cb5-46" aria-hidden="true"></a><span class="st">                    &lt;!-- wp:buttons {&quot;layout&quot;:{&quot;type&quot;:&quot;flex&quot;,&quot;justifyContent&quot;:&quot;center&quot;}} --&gt;</span></span>
<span id="cb5-47"><a href="#cb5-47" aria-hidden="true"></a><span class="st">                    &lt;div class=&quot;wp-block-buttons&quot;&gt;</span></span>
<span id="cb5-48"><a href="#cb5-48" aria-hidden="true"></a><span class="st">                        &lt;!-- wp:button --&gt;</span></span>
<span id="cb5-49"><a href="#cb5-49" aria-hidden="true"></a><span class="st">                        &lt;div class=&quot;wp-block-button&quot;&gt;&lt;a class=&quot;wp-block-button__link&quot;&gt;Choose Plan&lt;/a&gt;&lt;/div&gt;</span></span>
<span id="cb5-50"><a href="#cb5-50" aria-hidden="true"></a><span class="st">                        &lt;!-- /wp:button --&gt;</span></span>
<span id="cb5-51"><a href="#cb5-51" aria-hidden="true"></a><span class="st">                    &lt;/div&gt;</span></span>
<span id="cb5-52"><a href="#cb5-52" aria-hidden="true"></a><span class="st">                    &lt;!-- /wp:buttons --&gt;</span></span>
<span id="cb5-53"><a href="#cb5-53" aria-hidden="true"></a><span class="st">                &lt;/div&gt;</span></span>
<span id="cb5-54"><a href="#cb5-54" aria-hidden="true"></a><span class="st">                &lt;!-- /wp:column --&gt;</span></span>
<span id="cb5-55"><a href="#cb5-55" aria-hidden="true"></a></span>
<span id="cb5-56"><a href="#cb5-56" aria-hidden="true"></a><span class="st">                &lt;!-- wp:column {&quot;style&quot;:{&quot;border&quot;:{&quot;width&quot;:&quot;2px&quot;}}} --&gt;</span></span>
<span id="cb5-57"><a href="#cb5-57" aria-hidden="true"></a><span class="st">                &lt;div class=&quot;wp-block-column&quot;&gt;</span></span>
<span id="cb5-58"><a href="#cb5-58" aria-hidden="true"></a><span class="st">                    &lt;!-- wp:heading {&quot;textAlign&quot;:&quot;center&quot;} --&gt;</span></span>
<span id="cb5-59"><a href="#cb5-59" aria-hidden="true"></a><span class="st">                    &lt;h2 class=&quot;has-text-align-center&quot;&gt;Enterprise&lt;/h2&gt;</span></span>
<span id="cb5-60"><a href="#cb5-60" aria-hidden="true"></a><span class="st">                    &lt;!-- /wp:heading --&gt;</span></span>
<span id="cb5-61"><a href="#cb5-61" aria-hidden="true"></a></span>
<span id="cb5-62"><a href="#cb5-62" aria-hidden="true"></a><span class="st">                    &lt;!-- wp:paragraph {&quot;align&quot;:&quot;center&quot;,&quot;fontSize&quot;:&quot;large&quot;} --&gt;</span></span>
<span id="cb5-63"><a href="#cb5-63" aria-hidden="true"></a><span class="st">                    &lt;p class=&quot;has-text-align-center has-large-font-size&quot;&gt;&lt;strong&gt;Custom&lt;/strong&gt;&lt;/p&gt;</span></span>
<span id="cb5-64"><a href="#cb5-64" aria-hidden="true"></a><span class="st">                    &lt;!-- /wp:paragraph --&gt;</span></span>
<span id="cb5-65"><a href="#cb5-65" aria-hidden="true"></a></span>
<span id="cb5-66"><a href="#cb5-66" aria-hidden="true"></a><span class="st">                    &lt;!-- wp:list --&gt;</span></span>
<span id="cb5-67"><a href="#cb5-67" aria-hidden="true"></a><span class="st">                    &lt;ul&gt;&lt;li&gt;Everything in Pro&lt;/li&gt;&lt;li&gt;Premium Support&lt;/li&gt;&lt;li&gt;Custom Integration&lt;/li&gt;&lt;/ul&gt;</span></span>
<span id="cb5-68"><a href="#cb5-68" aria-hidden="true"></a><span class="st">                    &lt;!-- /wp:list --&gt;</span></span>
<span id="cb5-69"><a href="#cb5-69" aria-hidden="true"></a></span>
<span id="cb5-70"><a href="#cb5-70" aria-hidden="true"></a><span class="st">                    &lt;!-- wp:buttons {&quot;layout&quot;:{&quot;type&quot;:&quot;flex&quot;,&quot;justifyContent&quot;:&quot;center&quot;}} --&gt;</span></span>
<span id="cb5-71"><a href="#cb5-71" aria-hidden="true"></a><span class="st">                    &lt;div class=&quot;wp-block-buttons&quot;&gt;</span></span>
<span id="cb5-72"><a href="#cb5-72" aria-hidden="true"></a><span class="st">                        &lt;!-- wp:button --&gt;</span></span>
<span id="cb5-73"><a href="#cb5-73" aria-hidden="true"></a><span class="st">                        &lt;div class=&quot;wp-block-button&quot;&gt;&lt;a class=&quot;wp-block-button__link&quot;&gt;Contact Us&lt;/a&gt;&lt;/div&gt;</span></span>
<span id="cb5-74"><a href="#cb5-74" aria-hidden="true"></a><span class="st">                        &lt;!-- /wp:button --&gt;</span></span>
<span id="cb5-75"><a href="#cb5-75" aria-hidden="true"></a><span class="st">                    &lt;/div&gt;</span></span>
<span id="cb5-76"><a href="#cb5-76" aria-hidden="true"></a><span class="st">                    &lt;!-- /wp:buttons --&gt;</span></span>
<span id="cb5-77"><a href="#cb5-77" aria-hidden="true"></a><span class="st">                &lt;/div&gt;</span></span>
<span id="cb5-78"><a href="#cb5-78" aria-hidden="true"></a><span class="st">                &lt;!-- /wp:column --&gt;</span></span>
<span id="cb5-79"><a href="#cb5-79" aria-hidden="true"></a><span class="st">            &lt;/div&gt;</span></span>
<span id="cb5-80"><a href="#cb5-80" aria-hidden="true"></a><span class="st">            &lt;!-- /wp:columns --&gt;&#39;</span><span class="ot">,</span></span>
<span id="cb5-81"><a href="#cb5-81" aria-hidden="true"></a>    <span class="ot">)</span></span>
<span id="cb5-82"><a href="#cb5-82" aria-hidden="true"></a><span class="ot">);</span></span></code></pre>
</div>
<h2 id="unregistering-core-patterns">Unregistering Core Patterns</h2>
<p>Remove unwanted patterns:</p>
<div class="sourceCode" id="cb6">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true"></a><span class="kw">function</span> remove_core_patterns<span class="ot">()</span> {</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true"></a>    unregister_block_pattern<span class="ot">(</span> <span class="st">&#39;core/query-standard-posts&#39;</span> <span class="ot">);</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true"></a>    unregister_block_pattern<span class="ot">(</span> <span class="st">&#39;core/query-medium-posts&#39;</span> <span class="ot">);</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true"></a>}</span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true"></a>add_action<span class="ot">(</span> <span class="st">&#39;init&#39;</span><span class="ot">,</span> <span class="st">&#39;remove_core_patterns&#39;</span> <span class="ot">);</span></span></code></pre>
</div>
<h2 id="pattern-best-practices">Pattern Best Practices</h2>
<ol type="1">
<li><strong>Use placeholder images</strong> for visual patterns</li>
<li><strong>Include descriptive keywords</strong> for searchability</li>
<li><strong>Test across themes</strong> to ensure compatibility</li>
<li><strong>Keep patterns focused</strong> &#8211; one purpose per pattern</li>
<li><strong>Add helpful descriptions</strong> explaining pattern use cases</li>
<li><strong>Use semantic HTML</strong> for accessibility</li>
<li><strong>Consider mobile responsiveness</strong> in layouts</li>
</ol>
<h2 id="translatable-patterns">Translatable Patterns</h2>
<p>Make pattern text translatable:</p>
<div class="sourceCode" id="cb7">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true"></a><span class="st">&#39;content&#39;</span> =&gt; <span class="fu">sprintf</span><span class="ot">(</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true"></a>    <span class="st">&#39;&lt;!-- wp:heading --&gt;&lt;h2&gt;%s&lt;/h2&gt;&lt;!-- /wp:heading --&gt;</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true"></a><span class="st">    &lt;!-- wp:paragraph --&gt;&lt;p&gt;%s&lt;/p&gt;&lt;!-- /wp:paragraph --&gt;&#39;</span><span class="ot">,</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true"></a>    esc_html__<span class="ot">(</span> <span class="st">&#39;Welcome&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span> <span class="ot">),</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true"></a>    esc_html__<span class="ot">(</span> <span class="st">&#39;This is sample content.&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span> <span class="ot">)</span></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<h2 id="organizing-patterns-in-plugins">Organizing Patterns in Plugins</h2>
<p>Structure patterns in separate files:</p>
<div class="sourceCode" id="cb8">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true"></a><span class="co">// patterns/hero.php</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true"></a>&lt;<span class="ot">?</span>php</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true"></a><span class="kw">return</span> <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true"></a>    <span class="st">&#39;title&#39;</span> =&gt; <span class="st">&#39;Hero Section&#39;</span><span class="ot">,</span></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true"></a>    <span class="st">&#39;categories&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span> <span class="st">&#39;featured&#39;</span> <span class="ot">),</span></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true"></a>    <span class="st">&#39;content&#39;</span> =&gt; <span class="st">&#39;&lt;!-- pattern content --&gt;&#39;</span></span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true"></a><span class="ot">);</span></span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true"></a></span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true"></a><span class="co">// functions.php</span></span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true"></a><span class="kw">function</span> register_pattern_library<span class="ot">()</span> {</span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true"></a>    <span class="kw">$patterns</span> = <span class="fu">glob</span><span class="ot">(</span> get_template_directory<span class="ot">()</span> . <span class="st">&#39;/patterns/*.php&#39;</span> <span class="ot">);</span></span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true"></a></span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true"></a>    <span class="kw">foreach</span> <span class="ot">(</span> <span class="kw">$patterns</span> <span class="kw">as</span> <span class="kw">$pattern_file</span> <span class="ot">)</span> {</span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true"></a>        <span class="kw">$pattern</span> = <span class="kw">require</span> <span class="kw">$pattern_file</span><span class="ot">;</span></span>
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true"></a>        <span class="kw">$slug</span> = <span class="fu">basename</span><span class="ot">(</span> <span class="kw">$pattern_file</span><span class="ot">,</span> <span class="st">&#39;.php&#39;</span> <span class="ot">);</span></span>
<span id="cb8-16"><a href="#cb8-16" aria-hidden="true"></a></span>
<span id="cb8-17"><a href="#cb8-17" aria-hidden="true"></a>        register_block_pattern<span class="ot">(</span> <span class="st">&#39;mytheme/&#39;</span> . <span class="kw">$slug</span><span class="ot">,</span> <span class="kw">$pattern</span> <span class="ot">);</span></span>
<span id="cb8-18"><a href="#cb8-18" aria-hidden="true"></a>    }</span>
<span id="cb8-19"><a href="#cb8-19" aria-hidden="true"></a>}</span>
<span id="cb8-20"><a href="#cb8-20" aria-hidden="true"></a>add_action<span class="ot">(</span> <span class="st">&#39;init&#39;</span><span class="ot">,</span> <span class="st">&#39;register_pattern_library&#39;</span> <span class="ot">);</span></span></code></pre>
</div>
<h2 id="conclusion">Conclusion</h2>
<p>Block patterns transform WordPress content creation by providing professional design starting points. Start with simple patterns for common layouts, organize them into logical categories, and progressively build a pattern library tailored to your site’s needs. Well-designed patterns empower users to create beautiful pages without design expertise.</p>
<h2 id="external-links">External Links</h2>
<ol type="1">
<li><a href="https://developer.wordpress.org/block-editor/reference-guides/block-api/block-patterns/">Block Pattern Documentation</a></li>
<li><a href="https://wordpress.org/patterns/">WordPress Pattern Directory</a></li>
<li><a href="https://developer.wordpress.org/reference/functions/register_block_pattern/">register_block_pattern() Reference</a></li>
<li><a href="https://github.com/WordPress/block-pattern-builder">Block Pattern Examples</a></li>
<li><a href="https://developer.wordpress.org/reference/functions/register_block_pattern_category/">Pattern Categories Reference</a></li>
</ol>
<h2 id="call-to-action">Call to Action</h2>
<p>Streamline your workflow! <a href="https://blocknavigatorplugin.com/#pricing">Block Editor Navigator Pro</a> provides instant block navigation, search, and organization. Find any block in seconds—try it free!</p>
<p>The post <a href="https://developryplugins.com/how-to-add-custom-block-patterns-to-wordpress-block-editor/">How to Add Custom Block Patterns to WordPress Block Editor</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Add Custom Post Types to WordPress Without Plugins</title>
		<link>https://developryplugins.com/how-to-add-custom-post-types-to-wordpress-without-plugins/</link>
		
		<dc:creator><![CDATA[Krasen Slavov]]></dc:creator>
		<pubDate>Thu, 20 Aug 2026 09:00:00 +0000</pubDate>
				<category><![CDATA[WordPress Tips Tricks & Hacks]]></category>
		<category><![CDATA[content types]]></category>
		<category><![CDATA[cpt]]></category>
		<category><![CDATA[custom post types]]></category>
		<category><![CDATA[post types]]></category>
		<category><![CDATA[wordpress development]]></category>
		<guid isPermaLink="false">https://developryplugins.com/?p=188</guid>

					<description><![CDATA[<p>Custom post types extend WordPress beyond blogs and pages, enabling portfolio items, products, testimonials, and any content structure imaginable. While plugins simplify creation, coding custom post types provides complete control,...</p>
<p>The post <a href="https://developryplugins.com/how-to-add-custom-post-types-to-wordpress-without-plugins/">How to Add Custom Post Types to WordPress Without Plugins</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><!-- @format --></p>
<p>Custom post types extend WordPress beyond blogs and pages, enabling portfolio items, products, testimonials, and any content structure imaginable. While plugins simplify creation, coding custom post types provides complete control, better performance, and deeper WordPress understanding. This comprehensive guide teaches custom post type registration, taxonomy association, template creation, and advanced customization without plugins.</p>
<h2 id="understanding-custom-post-types">Understanding Custom Post Types</h2>
<p>WordPress includes five default post types:</p>
<ul>
<li>post (Blog posts)</li>
<li>page (Static pages)</li>
<li>attachment (Media)</li>
<li>revision (Post revisions)</li>
<li>nav_menu_item (Menu items)</li>
</ul>
<p>Custom post types add structured content beyond these defaults.</p>
<p><strong>Common Use Cases</strong>:</p>
<ul>
<li>Portfolio projects</li>
<li>Products/services</li>
<li>Team members</li>
<li>Testimonials</li>
<li>Events</li>
<li>Case studies</li>
<li>Properties/listings</li>
<li>Courses/lessons</li>
</ul>
<h2 id="basic-custom-post-type-registration">Basic Custom Post Type Registration</h2>
<p><strong>Simple Portfolio CPT</strong>:</p>
<div class="sourceCode" id="cb1">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true"></a><span class="kw">function</span> dprt_register_portfolio<span class="ot">()</span> {</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true"></a>    register_post_type<span class="ot">(</span><span class="st">&#39;portfolio&#39;</span><span class="ot">,</span> <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true"></a>        <span class="st">&#39;labels&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true"></a>            <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;Portfolio&#39;</span><span class="ot">,</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true"></a>            <span class="st">&#39;singular_name&#39;</span> =&gt; <span class="st">&#39;Portfolio Item&#39;</span><span class="ot">,</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true"></a>            <span class="st">&#39;add_new&#39;</span> =&gt; <span class="st">&#39;Add New Project&#39;</span><span class="ot">,</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true"></a>            <span class="st">&#39;add_new_item&#39;</span> =&gt; <span class="st">&#39;Add New Portfolio Item&#39;</span><span class="ot">,</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true"></a>            <span class="st">&#39;edit_item&#39;</span> =&gt; <span class="st">&#39;Edit Portfolio Item&#39;</span><span class="ot">,</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true"></a>            <span class="st">&#39;new_item&#39;</span> =&gt; <span class="st">&#39;New Portfolio Item&#39;</span><span class="ot">,</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true"></a>            <span class="st">&#39;view_item&#39;</span> =&gt; <span class="st">&#39;View Portfolio Item&#39;</span><span class="ot">,</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true"></a>            <span class="st">&#39;search_items&#39;</span> =&gt; <span class="st">&#39;Search Portfolio&#39;</span><span class="ot">,</span></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true"></a>            <span class="st">&#39;not_found&#39;</span> =&gt; <span class="st">&#39;No portfolio items found&#39;</span><span class="ot">,</span></span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true"></a>            <span class="st">&#39;not_found_in_trash&#39;</span> =&gt; <span class="st">&#39;No portfolio items found in trash&#39;</span></span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true"></a>        <span class="st">&#39;public&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true"></a>        <span class="st">&#39;has_archive&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true"></a>        <span class="st">&#39;rewrite&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span><span class="st">&#39;slug&#39;</span> =&gt; <span class="st">&#39;portfolio&#39;</span><span class="ot">),</span></span>
<span id="cb1-18"><a href="#cb1-18" aria-hidden="true"></a>        <span class="st">&#39;supports&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span><span class="st">&#39;title&#39;</span><span class="ot">,</span> <span class="st">&#39;editor&#39;</span><span class="ot">,</span> <span class="st">&#39;thumbnail&#39;</span><span class="ot">,</span> <span class="st">&#39;excerpt&#39;</span><span class="ot">),</span></span>
<span id="cb1-19"><a href="#cb1-19" aria-hidden="true"></a>        <span class="st">&#39;menu_icon&#39;</span> =&gt; <span class="st">&#39;dashicons-portfolio&#39;</span><span class="ot">,</span></span>
<span id="cb1-20"><a href="#cb1-20" aria-hidden="true"></a>        <span class="st">&#39;show_in_rest&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span> <span class="co">// Gutenberg support</span></span>
<span id="cb1-21"><a href="#cb1-21" aria-hidden="true"></a>    <span class="ot">));</span></span>
<span id="cb1-22"><a href="#cb1-22" aria-hidden="true"></a>}</span>
<span id="cb1-23"><a href="#cb1-23" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;init&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_register_portfolio&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<p><strong>Flush Rewrite Rules</strong> (run once after registration):</p>
<div class="sourceCode" id="cb2">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true"></a><span class="co">// Visit Settings → Permalinks to flush, or run this code once:</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true"></a>flush_rewrite_rules<span class="ot">();</span></span></code></pre>
</div>
<h2 id="complete-parameter-reference">Complete Parameter Reference</h2>
<p><strong>Essential Parameters</strong>:</p>
<p><strong>public</strong> (boolean): Makes CPT publicly queryable.</p>
<ul>
<li>true: Visible on front-end and admin</li>
<li>false: Hidden from public</li>
</ul>
<p><strong>publicly_queryable</strong> (boolean): Whether post type can be queried from front-end.</p>
<p><strong>show_ui</strong> (boolean): Generate admin UI.</p>
<p><strong>show_in_menu</strong> (boolean): Show in admin menu.</p>
<ul>
<li>true: Top-level menu</li>
<li>string: ‘tools.php’ makes submenu under Tools</li>
</ul>
<p><strong>menu_position</strong> (integer): Admin menu order.</p>
<ul>
<li>5: Below Posts</li>
<li>10: Below Media</li>
<li>15: Below Links</li>
<li>20: Below Pages</li>
<li>25: Below Comments</li>
</ul>
<p><strong>menu_icon</strong> (string): Dashicon class or image URL.</p>
<ul>
<li>‘dashicons-portfolio’</li>
<li>‘dashicons-products’</li>
<li>‘dashicons-groups’</li>
<li>get_template_directory_uri() . ‘/images/icon.png’</li>
</ul>
<p><strong>supports</strong> (array): Features CPT supports.</p>
<ul>
<li>‘title’: Title field</li>
<li>‘editor’: Content editor</li>
<li>‘thumbnail’: Featured image</li>
<li>‘excerpt’: Excerpt field</li>
<li>‘custom-fields’: Custom fields metabox</li>
<li>‘comments’: Comment discussion</li>
<li>‘revisions’: Revision tracking</li>
<li>‘page-attributes’: Order/parent</li>
<li>‘post-formats’: Post format selection</li>
</ul>
<p><strong>taxonomies</strong> (array): Associated taxonomies.</p>
<ul>
<li>array(‘category’, ‘post_tag’)</li>
</ul>
<p><strong>has_archive</strong> (boolean|string): Archive page support.</p>
<ul>
<li>true: Uses CPT slug</li>
<li>‘projects’: Custom archive slug</li>
</ul>
<p><strong>rewrite</strong> (array|boolean): Permalink structure.</p>
<div class="sourceCode" id="cb3">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true"></a>    <span class="st">&#39;slug&#39;</span> =&gt; <span class="st">&#39;portfolio&#39;</span><span class="ot">,</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true"></a>    <span class="st">&#39;with_front&#39;</span> =&gt; <span class="kw">false</span><span class="ot">,</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true"></a>    <span class="st">&#39;hierarchical&#39;</span> =&gt; <span class="kw">false</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>capability_type</strong> (string): Capability structure.</p>
<ul>
<li>‘post’: Uses post capabilities</li>
<li>‘page’: Uses page capabilities</li>
<li>array(‘book’, ‘books’): Custom capabilities</li>
</ul>
<p><strong>show_in_rest</strong> (boolean): REST API and Gutenberg support.</p>
<ul>
<li>true: Enables block editor</li>
</ul>
<h2 id="advanced-custom-post-type-example">Advanced Custom Post Type Example</h2>
<p><strong>Complete Product CPT</strong>:</p>
<div class="sourceCode" id="cb4">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true"></a><span class="kw">function</span> dprt_register_products<span class="ot">()</span> {</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true"></a>    <span class="kw">$labels</span> = <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true"></a>        <span class="st">&#39;name&#39;</span> =&gt; _x<span class="ot">(</span><span class="st">&#39;Products&#39;</span><span class="ot">,</span> <span class="st">&#39;Post type general name&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true"></a>        <span class="st">&#39;singular_name&#39;</span> =&gt; _x<span class="ot">(</span><span class="st">&#39;Product&#39;</span><span class="ot">,</span> <span class="st">&#39;Post type singular name&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true"></a>        <span class="st">&#39;menu_name&#39;</span> =&gt; _x<span class="ot">(</span><span class="st">&#39;Products&#39;</span><span class="ot">,</span> <span class="st">&#39;Admin Menu text&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true"></a>        <span class="st">&#39;name_admin_bar&#39;</span> =&gt; _x<span class="ot">(</span><span class="st">&#39;Product&#39;</span><span class="ot">,</span> <span class="st">&#39;Add New on Toolbar&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true"></a>        <span class="st">&#39;add_new&#39;</span> =&gt; <span class="kw">__</span><span class="ot">(</span><span class="st">&#39;Add New&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true"></a>        <span class="st">&#39;add_new_item&#39;</span> =&gt; <span class="kw">__</span><span class="ot">(</span><span class="st">&#39;Add New Product&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true"></a>        <span class="st">&#39;new_item&#39;</span> =&gt; <span class="kw">__</span><span class="ot">(</span><span class="st">&#39;New Product&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true"></a>        <span class="st">&#39;edit_item&#39;</span> =&gt; <span class="kw">__</span><span class="ot">(</span><span class="st">&#39;Edit Product&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true"></a>        <span class="st">&#39;view_item&#39;</span> =&gt; <span class="kw">__</span><span class="ot">(</span><span class="st">&#39;View Product&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true"></a>        <span class="st">&#39;all_items&#39;</span> =&gt; <span class="kw">__</span><span class="ot">(</span><span class="st">&#39;All Products&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true"></a>        <span class="st">&#39;search_items&#39;</span> =&gt; <span class="kw">__</span><span class="ot">(</span><span class="st">&#39;Search Products&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true"></a>        <span class="st">&#39;parent_item_colon&#39;</span> =&gt; <span class="kw">__</span><span class="ot">(</span><span class="st">&#39;Parent Products:&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true"></a>        <span class="st">&#39;not_found&#39;</span> =&gt; <span class="kw">__</span><span class="ot">(</span><span class="st">&#39;No products found.&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true"></a>        <span class="st">&#39;not_found_in_trash&#39;</span> =&gt; <span class="kw">__</span><span class="ot">(</span><span class="st">&#39;No products found in Trash.&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true"></a>        <span class="st">&#39;featured_image&#39;</span> =&gt; _x<span class="ot">(</span><span class="st">&#39;Product Image&#39;</span><span class="ot">,</span> <span class="st">&#39;Overrides the &quot;Featured Image&quot; phrase&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true"></a>        <span class="st">&#39;set_featured_image&#39;</span> =&gt; _x<span class="ot">(</span><span class="st">&#39;Set product image&#39;</span><span class="ot">,</span> <span class="st">&#39;Overrides the &quot;Set featured image&quot; phrase&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true"></a>        <span class="st">&#39;remove_featured_image&#39;</span> =&gt; _x<span class="ot">(</span><span class="st">&#39;Remove product image&#39;</span><span class="ot">,</span> <span class="st">&#39;Overrides the &quot;Remove featured image&quot; phrase&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-20"><a href="#cb4-20" aria-hidden="true"></a>        <span class="st">&#39;use_featured_image&#39;</span> =&gt; _x<span class="ot">(</span><span class="st">&#39;Use as product image&#39;</span><span class="ot">,</span> <span class="st">&#39;Overrides the &quot;Use as featured image&quot; phrase&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-21"><a href="#cb4-21" aria-hidden="true"></a>        <span class="st">&#39;archives&#39;</span> =&gt; _x<span class="ot">(</span><span class="st">&#39;Product archives&#39;</span><span class="ot">,</span> <span class="st">&#39;The post type archive label&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-22"><a href="#cb4-22" aria-hidden="true"></a>        <span class="st">&#39;insert_into_item&#39;</span> =&gt; _x<span class="ot">(</span><span class="st">&#39;Insert into product&#39;</span><span class="ot">,</span> <span class="st">&#39;Overrides the &quot;Insert into post&quot; phrase&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-23"><a href="#cb4-23" aria-hidden="true"></a>        <span class="st">&#39;uploaded_to_this_item&#39;</span> =&gt; _x<span class="ot">(</span><span class="st">&#39;Uploaded to this product&#39;</span><span class="ot">,</span> <span class="st">&#39;Overrides the &quot;Uploaded to this post&quot; phrase&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-24"><a href="#cb4-24" aria-hidden="true"></a>        <span class="st">&#39;filter_items_list&#39;</span> =&gt; _x<span class="ot">(</span><span class="st">&#39;Filter products list&#39;</span><span class="ot">,</span> <span class="st">&#39;Screen reader text&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-25"><a href="#cb4-25" aria-hidden="true"></a>        <span class="st">&#39;items_list_navigation&#39;</span> =&gt; _x<span class="ot">(</span><span class="st">&#39;Products list navigation&#39;</span><span class="ot">,</span> <span class="st">&#39;Screen reader text&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-26"><a href="#cb4-26" aria-hidden="true"></a>        <span class="st">&#39;items_list&#39;</span> =&gt; _x<span class="ot">(</span><span class="st">&#39;Products list&#39;</span><span class="ot">,</span> <span class="st">&#39;Screen reader text&#39;</span><span class="ot">,</span> <span class="st">&#39;textdomain&#39;</span><span class="ot">),</span></span>
<span id="cb4-27"><a href="#cb4-27" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb4-28"><a href="#cb4-28" aria-hidden="true"></a></span>
<span id="cb4-29"><a href="#cb4-29" aria-hidden="true"></a>    <span class="kw">$args</span> = <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb4-30"><a href="#cb4-30" aria-hidden="true"></a>        <span class="st">&#39;labels&#39;</span> =&gt; <span class="kw">$labels</span><span class="ot">,</span></span>
<span id="cb4-31"><a href="#cb4-31" aria-hidden="true"></a>        <span class="st">&#39;public&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb4-32"><a href="#cb4-32" aria-hidden="true"></a>        <span class="st">&#39;publicly_queryable&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb4-33"><a href="#cb4-33" aria-hidden="true"></a>        <span class="st">&#39;show_ui&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb4-34"><a href="#cb4-34" aria-hidden="true"></a>        <span class="st">&#39;show_in_menu&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb4-35"><a href="#cb4-35" aria-hidden="true"></a>        <span class="st">&#39;query_var&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb4-36"><a href="#cb4-36" aria-hidden="true"></a>        <span class="st">&#39;rewrite&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span><span class="st">&#39;slug&#39;</span> =&gt; <span class="st">&#39;product&#39;</span><span class="ot">),</span></span>
<span id="cb4-37"><a href="#cb4-37" aria-hidden="true"></a>        <span class="st">&#39;capability_type&#39;</span> =&gt; <span class="st">&#39;post&#39;</span><span class="ot">,</span></span>
<span id="cb4-38"><a href="#cb4-38" aria-hidden="true"></a>        <span class="st">&#39;has_archive&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb4-39"><a href="#cb4-39" aria-hidden="true"></a>        <span class="st">&#39;hierarchical&#39;</span> =&gt; <span class="kw">false</span><span class="ot">,</span></span>
<span id="cb4-40"><a href="#cb4-40" aria-hidden="true"></a>        <span class="st">&#39;menu_position&#39;</span> =&gt; <span class="dv">5</span><span class="ot">,</span></span>
<span id="cb4-41"><a href="#cb4-41" aria-hidden="true"></a>        <span class="st">&#39;menu_icon&#39;</span> =&gt; <span class="st">&#39;dashicons-products&#39;</span><span class="ot">,</span></span>
<span id="cb4-42"><a href="#cb4-42" aria-hidden="true"></a>        <span class="st">&#39;supports&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span><span class="st">&#39;title&#39;</span><span class="ot">,</span> <span class="st">&#39;editor&#39;</span><span class="ot">,</span> <span class="st">&#39;thumbnail&#39;</span><span class="ot">,</span> <span class="st">&#39;excerpt&#39;</span><span class="ot">,</span> <span class="st">&#39;custom-fields&#39;</span><span class="ot">),</span></span>
<span id="cb4-43"><a href="#cb4-43" aria-hidden="true"></a>        <span class="st">&#39;show_in_rest&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb4-44"><a href="#cb4-44" aria-hidden="true"></a>        <span class="st">&#39;rest_base&#39;</span> =&gt; <span class="st">&#39;products&#39;</span><span class="ot">,</span></span>
<span id="cb4-45"><a href="#cb4-45" aria-hidden="true"></a>        <span class="st">&#39;rest_controller_class&#39;</span> =&gt; <span class="st">&#39;WP_REST_Posts_Controller&#39;</span><span class="ot">,</span></span>
<span id="cb4-46"><a href="#cb4-46" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb4-47"><a href="#cb4-47" aria-hidden="true"></a></span>
<span id="cb4-48"><a href="#cb4-48" aria-hidden="true"></a>    register_post_type<span class="ot">(</span><span class="st">&#39;product&#39;</span><span class="ot">,</span> <span class="kw">$args</span><span class="ot">);</span></span>
<span id="cb4-49"><a href="#cb4-49" aria-hidden="true"></a>}</span>
<span id="cb4-50"><a href="#cb4-50" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;init&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_register_products&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="custom-taxonomies-for-cpt">Custom Taxonomies for CPT</h2>
<p><strong>Category-Style Taxonomy (Hierarchical)</strong>:</p>
<div class="sourceCode" id="cb5">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true"></a><span class="kw">function</span> dprt_register_product_category<span class="ot">()</span> {</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true"></a>    register_taxonomy<span class="ot">(</span><span class="st">&#39;product_category&#39;</span><span class="ot">,</span> <span class="st">&#39;product&#39;</span><span class="ot">,</span> <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true"></a>        <span class="st">&#39;labels&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true"></a>            <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;Product Categories&#39;</span><span class="ot">,</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true"></a>            <span class="st">&#39;singular_name&#39;</span> =&gt; <span class="st">&#39;Product Category&#39;</span><span class="ot">,</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true"></a>            <span class="st">&#39;search_items&#39;</span> =&gt; <span class="st">&#39;Search Categories&#39;</span><span class="ot">,</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true"></a>            <span class="st">&#39;all_items&#39;</span> =&gt; <span class="st">&#39;All Categories&#39;</span><span class="ot">,</span></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true"></a>            <span class="st">&#39;parent_item&#39;</span> =&gt; <span class="st">&#39;Parent Category&#39;</span><span class="ot">,</span></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true"></a>            <span class="st">&#39;parent_item_colon&#39;</span> =&gt; <span class="st">&#39;Parent Category:&#39;</span><span class="ot">,</span></span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true"></a>            <span class="st">&#39;edit_item&#39;</span> =&gt; <span class="st">&#39;Edit Category&#39;</span><span class="ot">,</span></span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true"></a>            <span class="st">&#39;update_item&#39;</span> =&gt; <span class="st">&#39;Update Category&#39;</span><span class="ot">,</span></span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true"></a>            <span class="st">&#39;add_new_item&#39;</span> =&gt; <span class="st">&#39;Add New Category&#39;</span><span class="ot">,</span></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true"></a>            <span class="st">&#39;new_item_name&#39;</span> =&gt; <span class="st">&#39;New Category Name&#39;</span><span class="ot">,</span></span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true"></a>            <span class="st">&#39;menu_name&#39;</span> =&gt; <span class="st">&#39;Categories&#39;</span><span class="ot">,</span></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true"></a>        <span class="st">&#39;hierarchical&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span> <span class="co">// Like categories</span></span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true"></a>        <span class="st">&#39;show_ui&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true"></a>        <span class="st">&#39;show_admin_column&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span> <span class="co">// Show in admin post list</span></span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true"></a>        <span class="st">&#39;query_var&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb5-20"><a href="#cb5-20" aria-hidden="true"></a>        <span class="st">&#39;rewrite&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span><span class="st">&#39;slug&#39;</span> =&gt; <span class="st">&#39;product-category&#39;</span><span class="ot">),</span></span>
<span id="cb5-21"><a href="#cb5-21" aria-hidden="true"></a>        <span class="st">&#39;show_in_rest&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb5-22"><a href="#cb5-22" aria-hidden="true"></a>    <span class="ot">));</span></span>
<span id="cb5-23"><a href="#cb5-23" aria-hidden="true"></a>}</span>
<span id="cb5-24"><a href="#cb5-24" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;init&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_register_product_category&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<p><strong>Tag-Style Taxonomy (Non-Hierarchical)</strong>:</p>
<div class="sourceCode" id="cb6">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true"></a><span class="kw">function</span> dprt_register_product_tag<span class="ot">()</span> {</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true"></a>    register_taxonomy<span class="ot">(</span><span class="st">&#39;product_tag&#39;</span><span class="ot">,</span> <span class="st">&#39;product&#39;</span><span class="ot">,</span> <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true"></a>        <span class="st">&#39;labels&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true"></a>            <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;Product Tags&#39;</span><span class="ot">,</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true"></a>            <span class="st">&#39;singular_name&#39;</span> =&gt; <span class="st">&#39;Product Tag&#39;</span><span class="ot">,</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true"></a>            <span class="st">&#39;search_items&#39;</span> =&gt; <span class="st">&#39;Search Tags&#39;</span><span class="ot">,</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true"></a>            <span class="st">&#39;all_items&#39;</span> =&gt; <span class="st">&#39;All Tags&#39;</span><span class="ot">,</span></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true"></a>            <span class="st">&#39;edit_item&#39;</span> =&gt; <span class="st">&#39;Edit Tag&#39;</span><span class="ot">,</span></span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true"></a>            <span class="st">&#39;update_item&#39;</span> =&gt; <span class="st">&#39;Update Tag&#39;</span><span class="ot">,</span></span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true"></a>            <span class="st">&#39;add_new_item&#39;</span> =&gt; <span class="st">&#39;Add New Tag&#39;</span><span class="ot">,</span></span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true"></a>            <span class="st">&#39;new_item_name&#39;</span> =&gt; <span class="st">&#39;New Tag Name&#39;</span><span class="ot">,</span></span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true"></a>            <span class="st">&#39;menu_name&#39;</span> =&gt; <span class="st">&#39;Tags&#39;</span><span class="ot">,</span></span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true"></a>        <span class="st">&#39;hierarchical&#39;</span> =&gt; <span class="kw">false</span><span class="ot">,</span> <span class="co">// Like tags</span></span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true"></a>        <span class="st">&#39;show_ui&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb6-16"><a href="#cb6-16" aria-hidden="true"></a>        <span class="st">&#39;show_admin_column&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb6-17"><a href="#cb6-17" aria-hidden="true"></a>        <span class="st">&#39;query_var&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb6-18"><a href="#cb6-18" aria-hidden="true"></a>        <span class="st">&#39;rewrite&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span><span class="st">&#39;slug&#39;</span> =&gt; <span class="st">&#39;product-tag&#39;</span><span class="ot">),</span></span>
<span id="cb6-19"><a href="#cb6-19" aria-hidden="true"></a>        <span class="st">&#39;show_in_rest&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb6-20"><a href="#cb6-20" aria-hidden="true"></a>    <span class="ot">));</span></span>
<span id="cb6-21"><a href="#cb6-21" aria-hidden="true"></a>}</span>
<span id="cb6-22"><a href="#cb6-22" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;init&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_register_product_tag&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="template-files-for-custom-post-types">Template Files for Custom Post Types</h2>
<p>WordPress looks for these template files (in order):</p>
<p><strong>Single Post</strong>:</p>
<ol type="1">
<li>single-{post-type}.php (single-portfolio.php)</li>
<li>single.php</li>
<li>singular.php</li>
<li>index.php</li>
</ol>
<p><strong>Archive</strong>:</p>
<ol type="1">
<li>archive-{post-type}.php (archive-portfolio.php)</li>
<li>archive.php</li>
<li>index.php</li>
</ol>
<p><strong>Taxonomy</strong>:</p>
<ol type="1">
<li>taxonomy-{taxonomy}-{term}.php</li>
<li>taxonomy-{taxonomy}.php</li>
<li>taxonomy.php</li>
<li>archive.php</li>
</ol>
<p><strong>Single Portfolio Template</strong> (single-portfolio.php):</p>
<div class="sourceCode" id="cb7">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true"></a><span class="kw">&lt;?php</span> get_header<span class="ot">();</span> <span class="kw">?&gt;</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true"></a></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true"></a>&lt;main id=<span class="st">&quot;primary&quot;</span> <span class="kw">class</span>=<span class="st">&quot;site-main&quot;</span>&gt;</span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php</span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true"></a>    <span class="kw">while</span> <span class="ot">(</span>have_posts<span class="ot">())</span> <span class="ot">:</span></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true"></a>        the_post<span class="ot">();</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true"></a>        <span class="kw">?&gt;</span></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true"></a>        &lt;article id=<span class="st">&quot;post-&lt;?php the_ID(); ?&gt;&quot;</span> &lt;<span class="ot">?</span>php post_class<span class="ot">();</span> <span class="kw">?&gt;</span>&gt;</span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true"></a>            &lt;<span class="fu">header</span> <span class="kw">class</span>=<span class="st">&quot;entry-header&quot;</span>&gt;</span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true"></a>                &lt;h1 <span class="kw">class</span>=<span class="st">&quot;entry-title&quot;</span>&gt;&lt;<span class="ot">?</span>php the_title<span class="ot">();</span> <span class="kw">?&gt;</span>&lt;/h1&gt;</span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true"></a>            &lt;/<span class="fu">header</span>&gt;</span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true"></a></span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true"></a>            &lt;<span class="ot">?</span>php <span class="kw">if</span> <span class="ot">(</span>has_post_thumbnail<span class="ot">())</span> <span class="ot">:</span> <span class="kw">?&gt;</span></span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true"></a>                &lt;div <span class="kw">class</span>=<span class="st">&quot;post-thumbnail&quot;</span>&gt;</span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true"></a>                    &lt;<span class="ot">?</span>php the_post_thumbnail<span class="ot">(</span><span class="st">&#39;large&#39;</span><span class="ot">);</span> <span class="kw">?&gt;</span></span>
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true"></a>                &lt;/div&gt;</span>
<span id="cb7-17"><a href="#cb7-17" aria-hidden="true"></a>            &lt;<span class="ot">?</span>php <span class="kw">endif</span><span class="ot">;</span> <span class="kw">?&gt;</span></span>
<span id="cb7-18"><a href="#cb7-18" aria-hidden="true"></a></span>
<span id="cb7-19"><a href="#cb7-19" aria-hidden="true"></a>            &lt;div <span class="kw">class</span>=<span class="st">&quot;entry-content&quot;</span>&gt;</span>
<span id="cb7-20"><a href="#cb7-20" aria-hidden="true"></a>                &lt;<span class="ot">?</span>php the_content<span class="ot">();</span> <span class="kw">?&gt;</span></span>
<span id="cb7-21"><a href="#cb7-21" aria-hidden="true"></a>            &lt;/div&gt;</span>
<span id="cb7-22"><a href="#cb7-22" aria-hidden="true"></a></span>
<span id="cb7-23"><a href="#cb7-23" aria-hidden="true"></a>            &lt;<span class="ot">?</span>php</span>
<span id="cb7-24"><a href="#cb7-24" aria-hidden="true"></a>            <span class="co">// Display custom taxonomy terms</span></span>
<span id="cb7-25"><a href="#cb7-25" aria-hidden="true"></a>            <span class="kw">$categories</span> = get_the_terms<span class="ot">(</span>get_the_ID<span class="ot">(),</span> <span class="st">&#39;portfolio_category&#39;</span><span class="ot">);</span></span>
<span id="cb7-26"><a href="#cb7-26" aria-hidden="true"></a>            <span class="kw">if</span> <span class="ot">(</span><span class="kw">$categories</span> &amp;&amp; !is_wp_error<span class="ot">(</span><span class="kw">$categories</span><span class="ot">))</span> <span class="ot">:</span></span>
<span id="cb7-27"><a href="#cb7-27" aria-hidden="true"></a>                <span class="kw">?&gt;</span></span>
<span id="cb7-28"><a href="#cb7-28" aria-hidden="true"></a>                &lt;div <span class="kw">class</span>=<span class="st">&quot;portfolio-categories&quot;</span>&gt;</span>
<span id="cb7-29"><a href="#cb7-29" aria-hidden="true"></a>                    &lt;strong&gt;Categories:&lt;/strong&gt;</span>
<span id="cb7-30"><a href="#cb7-30" aria-hidden="true"></a>                    &lt;<span class="ot">?</span>php</span>
<span id="cb7-31"><a href="#cb7-31" aria-hidden="true"></a>                    <span class="kw">foreach</span> <span class="ot">(</span><span class="kw">$categories</span> <span class="kw">as</span> <span class="kw">$category</span><span class="ot">)</span> {</span>
<span id="cb7-32"><a href="#cb7-32" aria-hidden="true"></a>                        <span class="kw">echo</span> <span class="st">&#39;&lt;span&gt;&#39;</span> . esc_html<span class="ot">(</span><span class="kw">$category</span>-&gt;name<span class="ot">)</span> . <span class="st">&#39;&lt;/span&gt; &#39;</span><span class="ot">;</span></span>
<span id="cb7-33"><a href="#cb7-33" aria-hidden="true"></a>                    }</span>
<span id="cb7-34"><a href="#cb7-34" aria-hidden="true"></a>                    <span class="kw">?&gt;</span></span>
<span id="cb7-35"><a href="#cb7-35" aria-hidden="true"></a>                &lt;/div&gt;</span>
<span id="cb7-36"><a href="#cb7-36" aria-hidden="true"></a>            &lt;<span class="ot">?</span>php <span class="kw">endif</span><span class="ot">;</span> <span class="kw">?&gt;</span></span>
<span id="cb7-37"><a href="#cb7-37" aria-hidden="true"></a>        &lt;/article&gt;</span>
<span id="cb7-38"><a href="#cb7-38" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php <span class="kw">endwhile</span><span class="ot">;</span> <span class="kw">?&gt;</span></span>
<span id="cb7-39"><a href="#cb7-39" aria-hidden="true"></a>&lt;/main&gt;</span>
<span id="cb7-40"><a href="#cb7-40" aria-hidden="true"></a></span>
<span id="cb7-41"><a href="#cb7-41" aria-hidden="true"></a>&lt;<span class="ot">?</span>php get_footer<span class="ot">();</span> <span class="kw">?&gt;</span></span></code></pre>
</div>
<p><strong>Portfolio Archive Template</strong> (archive-portfolio.php):</p>
<div class="sourceCode" id="cb8">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true"></a><span class="kw">&lt;?php</span> get_header<span class="ot">();</span> <span class="kw">?&gt;</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true"></a></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true"></a>&lt;main id=<span class="st">&quot;primary&quot;</span> <span class="kw">class</span>=<span class="st">&quot;site-main&quot;</span>&gt;</span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true"></a>    &lt;<span class="fu">header</span> <span class="kw">class</span>=<span class="st">&quot;page-header&quot;</span>&gt;</span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true"></a>        &lt;h1 <span class="kw">class</span>=<span class="st">&quot;page-title&quot;</span>&gt;Portfolio&lt;/h1&gt;</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true"></a>    &lt;/<span class="fu">header</span>&gt;</span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true"></a></span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php <span class="kw">if</span> <span class="ot">(</span>have_posts<span class="ot">())</span> <span class="ot">:</span> <span class="kw">?&gt;</span></span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true"></a>        &lt;div <span class="kw">class</span>=<span class="st">&quot;portfolio-grid&quot;</span>&gt;</span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true"></a>            &lt;<span class="ot">?</span>php</span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true"></a>            <span class="kw">while</span> <span class="ot">(</span>have_posts<span class="ot">())</span> <span class="ot">:</span></span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true"></a>                the_post<span class="ot">();</span></span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true"></a>                <span class="kw">?&gt;</span></span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true"></a>                &lt;article id=<span class="st">&quot;post-&lt;?php the_ID(); ?&gt;&quot;</span> &lt;<span class="ot">?</span>php post_class<span class="ot">(</span><span class="st">&#39;portfolio-item&#39;</span><span class="ot">);</span> <span class="kw">?&gt;</span>&gt;</span>
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true"></a>                    &lt;<span class="ot">?</span>php <span class="kw">if</span> <span class="ot">(</span>has_post_thumbnail<span class="ot">())</span> <span class="ot">:</span> <span class="kw">?&gt;</span></span>
<span id="cb8-16"><a href="#cb8-16" aria-hidden="true"></a>                        &lt;a href=<span class="st">&quot;&lt;?php the_permalink(); ?&gt;&quot;</span>&gt;</span>
<span id="cb8-17"><a href="#cb8-17" aria-hidden="true"></a>                            &lt;<span class="ot">?</span>php the_post_thumbnail<span class="ot">(</span><span class="st">&#39;medium&#39;</span><span class="ot">);</span> <span class="kw">?&gt;</span></span>
<span id="cb8-18"><a href="#cb8-18" aria-hidden="true"></a>                        &lt;/a&gt;</span>
<span id="cb8-19"><a href="#cb8-19" aria-hidden="true"></a>                    &lt;<span class="ot">?</span>php <span class="kw">endif</span><span class="ot">;</span> <span class="kw">?&gt;</span></span>
<span id="cb8-20"><a href="#cb8-20" aria-hidden="true"></a></span>
<span id="cb8-21"><a href="#cb8-21" aria-hidden="true"></a>                    &lt;h2 <span class="kw">class</span>=<span class="st">&quot;entry-title&quot;</span>&gt;</span>
<span id="cb8-22"><a href="#cb8-22" aria-hidden="true"></a>                        &lt;a href=<span class="st">&quot;&lt;?php the_permalink(); ?&gt;&quot;</span>&gt;&lt;<span class="ot">?</span>php the_title<span class="ot">();</span> <span class="kw">?&gt;</span>&lt;/a&gt;</span>
<span id="cb8-23"><a href="#cb8-23" aria-hidden="true"></a>                    &lt;/h2&gt;</span>
<span id="cb8-24"><a href="#cb8-24" aria-hidden="true"></a></span>
<span id="cb8-25"><a href="#cb8-25" aria-hidden="true"></a>                    &lt;div <span class="kw">class</span>=<span class="st">&quot;entry-excerpt&quot;</span>&gt;</span>
<span id="cb8-26"><a href="#cb8-26" aria-hidden="true"></a>                        &lt;<span class="ot">?</span>php the_excerpt<span class="ot">();</span> <span class="kw">?&gt;</span></span>
<span id="cb8-27"><a href="#cb8-27" aria-hidden="true"></a>                    &lt;/div&gt;</span>
<span id="cb8-28"><a href="#cb8-28" aria-hidden="true"></a>                &lt;/article&gt;</span>
<span id="cb8-29"><a href="#cb8-29" aria-hidden="true"></a>            &lt;<span class="ot">?</span>php <span class="kw">endwhile</span><span class="ot">;</span> <span class="kw">?&gt;</span></span>
<span id="cb8-30"><a href="#cb8-30" aria-hidden="true"></a>        &lt;/div&gt;</span>
<span id="cb8-31"><a href="#cb8-31" aria-hidden="true"></a></span>
<span id="cb8-32"><a href="#cb8-32" aria-hidden="true"></a>        &lt;<span class="ot">?</span>php the_posts_pagination<span class="ot">();</span> <span class="kw">?&gt;</span></span>
<span id="cb8-33"><a href="#cb8-33" aria-hidden="true"></a></span>
<span id="cb8-34"><a href="#cb8-34" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php <span class="kw">else</span> <span class="ot">:</span> <span class="kw">?&gt;</span></span>
<span id="cb8-35"><a href="#cb8-35" aria-hidden="true"></a>        &lt;p&gt;No portfolio items found.&lt;/p&gt;</span>
<span id="cb8-36"><a href="#cb8-36" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php <span class="kw">endif</span><span class="ot">;</span> <span class="kw">?&gt;</span></span>
<span id="cb8-37"><a href="#cb8-37" aria-hidden="true"></a>&lt;/main&gt;</span>
<span id="cb8-38"><a href="#cb8-38" aria-hidden="true"></a></span>
<span id="cb8-39"><a href="#cb8-39" aria-hidden="true"></a>&lt;<span class="ot">?</span>php get_footer<span class="ot">();</span> <span class="kw">?&gt;</span></span></code></pre>
</div>
<h2 id="querying-custom-post-types">Querying Custom Post Types</h2>
<p><strong>WP_Query Examples</strong>:</p>
<div class="sourceCode" id="cb9">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true"></a><span class="co">// Get all portfolio items</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true"></a><span class="kw">$portfolio</span> = <span class="kw">new</span> WP_Query<span class="ot">(</span><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true"></a>    <span class="st">&#39;post_type&#39;</span> =&gt; <span class="st">&#39;portfolio&#39;</span><span class="ot">,</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true"></a>    <span class="st">&#39;posts_per_page&#39;</span> =&gt; <span class="dv">10</span><span class="ot">,</span></span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true"></a><span class="ot">));</span></span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true"></a></span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true"></a><span class="co">// Get portfolio by category</span></span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true"></a><span class="kw">$featured_portfolio</span> = <span class="kw">new</span> WP_Query<span class="ot">(</span><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb9-9"><a href="#cb9-9" aria-hidden="true"></a>    <span class="st">&#39;post_type&#39;</span> =&gt; <span class="st">&#39;portfolio&#39;</span><span class="ot">,</span></span>
<span id="cb9-10"><a href="#cb9-10" aria-hidden="true"></a>    <span class="st">&#39;posts_per_page&#39;</span> =&gt; <span class="dv">6</span><span class="ot">,</span></span>
<span id="cb9-11"><a href="#cb9-11" aria-hidden="true"></a>    <span class="st">&#39;tax_query&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb9-12"><a href="#cb9-12" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb9-13"><a href="#cb9-13" aria-hidden="true"></a>            <span class="st">&#39;taxonomy&#39;</span> =&gt; <span class="st">&#39;portfolio_category&#39;</span><span class="ot">,</span></span>
<span id="cb9-14"><a href="#cb9-14" aria-hidden="true"></a>            <span class="st">&#39;field&#39;</span> =&gt; <span class="st">&#39;slug&#39;</span><span class="ot">,</span></span>
<span id="cb9-15"><a href="#cb9-15" aria-hidden="true"></a>            <span class="st">&#39;terms&#39;</span> =&gt; <span class="st">&#39;featured&#39;</span><span class="ot">,</span></span>
<span id="cb9-16"><a href="#cb9-16" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb9-17"><a href="#cb9-17" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb9-18"><a href="#cb9-18" aria-hidden="true"></a><span class="ot">));</span></span>
<span id="cb9-19"><a href="#cb9-19" aria-hidden="true"></a></span>
<span id="cb9-20"><a href="#cb9-20" aria-hidden="true"></a><span class="co">// Multiple post types</span></span>
<span id="cb9-21"><a href="#cb9-21" aria-hidden="true"></a><span class="kw">$mixed</span> = <span class="kw">new</span> WP_Query<span class="ot">(</span><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb9-22"><a href="#cb9-22" aria-hidden="true"></a>    <span class="st">&#39;post_type&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span><span class="st">&#39;post&#39;</span><span class="ot">,</span> <span class="st">&#39;portfolio&#39;</span><span class="ot">,</span> <span class="st">&#39;product&#39;</span><span class="ot">),</span></span>
<span id="cb9-23"><a href="#cb9-23" aria-hidden="true"></a>    <span class="st">&#39;posts_per_page&#39;</span> =&gt; <span class="dv">10</span><span class="ot">,</span></span>
<span id="cb9-24"><a href="#cb9-24" aria-hidden="true"></a><span class="ot">));</span></span>
<span id="cb9-25"><a href="#cb9-25" aria-hidden="true"></a></span>
<span id="cb9-26"><a href="#cb9-26" aria-hidden="true"></a><span class="co">// Custom field query</span></span>
<span id="cb9-27"><a href="#cb9-27" aria-hidden="true"></a><span class="kw">$expensive_products</span> = <span class="kw">new</span> WP_Query<span class="ot">(</span><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb9-28"><a href="#cb9-28" aria-hidden="true"></a>    <span class="st">&#39;post_type&#39;</span> =&gt; <span class="st">&#39;product&#39;</span><span class="ot">,</span></span>
<span id="cb9-29"><a href="#cb9-29" aria-hidden="true"></a>    <span class="st">&#39;meta_query&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb9-30"><a href="#cb9-30" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb9-31"><a href="#cb9-31" aria-hidden="true"></a>            <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;price&#39;</span><span class="ot">,</span></span>
<span id="cb9-32"><a href="#cb9-32" aria-hidden="true"></a>            <span class="st">&#39;value&#39;</span> =&gt; <span class="dv">100</span><span class="ot">,</span></span>
<span id="cb9-33"><a href="#cb9-33" aria-hidden="true"></a>            <span class="st">&#39;compare&#39;</span> =&gt; <span class="st">&#39;&gt;&#39;</span><span class="ot">,</span></span>
<span id="cb9-34"><a href="#cb9-34" aria-hidden="true"></a>            <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;NUMERIC&#39;</span><span class="ot">,</span></span>
<span id="cb9-35"><a href="#cb9-35" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb9-36"><a href="#cb9-36" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb9-37"><a href="#cb9-37" aria-hidden="true"></a><span class="ot">));</span></span></code></pre>
</div>
<h2 id="adding-custom-columns-to-admin-list">Adding Custom Columns to Admin List</h2>
<div class="sourceCode" id="cb10">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true"></a><span class="co">// Add custom columns</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true"></a><span class="kw">function</span> dprt_portfolio_columns<span class="ot">(</span><span class="kw">$columns</span><span class="ot">)</span> {</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true"></a>    <span class="kw">$new_columns</span> = <span class="kw">array</span><span class="ot">();</span></span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true"></a>    <span class="kw">$new_columns</span><span class="ot">[</span><span class="st">&#39;cb&#39;</span><span class="ot">]</span> = <span class="kw">$columns</span><span class="ot">[</span><span class="st">&#39;cb&#39;</span><span class="ot">];</span></span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true"></a>    <span class="kw">$new_columns</span><span class="ot">[</span><span class="st">&#39;thumbnail&#39;</span><span class="ot">]</span> = <span class="st">&#39;Image&#39;</span><span class="ot">;</span></span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true"></a>    <span class="kw">$new_columns</span><span class="ot">[</span><span class="st">&#39;title&#39;</span><span class="ot">]</span> = <span class="kw">$columns</span><span class="ot">[</span><span class="st">&#39;title&#39;</span><span class="ot">];</span></span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true"></a>    <span class="kw">$new_columns</span><span class="ot">[</span><span class="st">&#39;portfolio_category&#39;</span><span class="ot">]</span> = <span class="st">&#39;Category&#39;</span><span class="ot">;</span></span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true"></a>    <span class="kw">$new_columns</span><span class="ot">[</span><span class="st">&#39;date&#39;</span><span class="ot">]</span> = <span class="kw">$columns</span><span class="ot">[</span><span class="st">&#39;date&#39;</span><span class="ot">];</span></span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$new_columns</span><span class="ot">;</span></span>
<span id="cb10-10"><a href="#cb10-10" aria-hidden="true"></a>}</span>
<span id="cb10-11"><a href="#cb10-11" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;manage_portfolio_posts_columns&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_portfolio_columns&#39;</span><span class="ot">);</span></span>
<span id="cb10-12"><a href="#cb10-12" aria-hidden="true"></a></span>
<span id="cb10-13"><a href="#cb10-13" aria-hidden="true"></a><span class="co">// Populate custom columns</span></span>
<span id="cb10-14"><a href="#cb10-14" aria-hidden="true"></a><span class="kw">function</span> dprt_portfolio_column_content<span class="ot">(</span><span class="kw">$column</span><span class="ot">,</span> <span class="kw">$post_id</span><span class="ot">)</span> {</span>
<span id="cb10-15"><a href="#cb10-15" aria-hidden="true"></a>    <span class="kw">switch</span> <span class="ot">(</span><span class="kw">$column</span><span class="ot">)</span> {</span>
<span id="cb10-16"><a href="#cb10-16" aria-hidden="true"></a>        <span class="kw">case </span><span class="st">&#39;thumbnail&#39;</span><span class="ot">:</span></span>
<span id="cb10-17"><a href="#cb10-17" aria-hidden="true"></a>            <span class="kw">echo</span> get_the_post_thumbnail<span class="ot">(</span><span class="kw">$post_id</span><span class="ot">,</span> <span class="kw">array</span><span class="ot">(</span><span class="dv">60</span><span class="ot">,</span> <span class="dv">60</span><span class="ot">));</span></span>
<span id="cb10-18"><a href="#cb10-18" aria-hidden="true"></a>            <span class="kw">break</span><span class="ot">;</span></span>
<span id="cb10-19"><a href="#cb10-19" aria-hidden="true"></a></span>
<span id="cb10-20"><a href="#cb10-20" aria-hidden="true"></a>        <span class="kw">case </span><span class="st">&#39;portfolio_category&#39;</span><span class="ot">:</span></span>
<span id="cb10-21"><a href="#cb10-21" aria-hidden="true"></a>            <span class="kw">$terms</span> = get_the_terms<span class="ot">(</span><span class="kw">$post_id</span><span class="ot">,</span> <span class="st">&#39;portfolio_category&#39;</span><span class="ot">);</span></span>
<span id="cb10-22"><a href="#cb10-22" aria-hidden="true"></a>            <span class="kw">if</span> <span class="ot">(</span><span class="kw">$terms</span> &amp;&amp; !is_wp_error<span class="ot">(</span><span class="kw">$terms</span><span class="ot">))</span> {</span>
<span id="cb10-23"><a href="#cb10-23" aria-hidden="true"></a>                <span class="kw">$term_names</span> = wp_list_pluck<span class="ot">(</span><span class="kw">$terms</span><span class="ot">,</span> <span class="st">&#39;name&#39;</span><span class="ot">);</span></span>
<span id="cb10-24"><a href="#cb10-24" aria-hidden="true"></a>                <span class="kw">echo</span> <span class="fu">implode</span><span class="ot">(</span><span class="st">&#39;, &#39;</span><span class="ot">,</span> <span class="kw">$term_names</span><span class="ot">);</span></span>
<span id="cb10-25"><a href="#cb10-25" aria-hidden="true"></a>            } <span class="kw">else</span> {</span>
<span id="cb10-26"><a href="#cb10-26" aria-hidden="true"></a>                <span class="kw">echo</span> <span class="st">&#39;—&#39;</span><span class="ot">;</span></span>
<span id="cb10-27"><a href="#cb10-27" aria-hidden="true"></a>            }</span>
<span id="cb10-28"><a href="#cb10-28" aria-hidden="true"></a>            <span class="kw">break</span><span class="ot">;</span></span>
<span id="cb10-29"><a href="#cb10-29" aria-hidden="true"></a>    }</span>
<span id="cb10-30"><a href="#cb10-30" aria-hidden="true"></a>}</span>
<span id="cb10-31"><a href="#cb10-31" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;manage_portfolio_posts_custom_column&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_portfolio_column_content&#39;</span><span class="ot">,</span> <span class="dv">10</span><span class="ot">,</span> <span class="dv">2</span><span class="ot">);</span></span>
<span id="cb10-32"><a href="#cb10-32" aria-hidden="true"></a></span>
<span id="cb10-33"><a href="#cb10-33" aria-hidden="true"></a><span class="co">// Make columns sortable</span></span>
<span id="cb10-34"><a href="#cb10-34" aria-hidden="true"></a><span class="kw">function</span> dprt_sortable_columns<span class="ot">(</span><span class="kw">$columns</span><span class="ot">)</span> {</span>
<span id="cb10-35"><a href="#cb10-35" aria-hidden="true"></a>    <span class="kw">$columns</span><span class="ot">[</span><span class="st">&#39;portfolio_category&#39;</span><span class="ot">]</span> = <span class="st">&#39;portfolio_category&#39;</span><span class="ot">;</span></span>
<span id="cb10-36"><a href="#cb10-36" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$columns</span><span class="ot">;</span></span>
<span id="cb10-37"><a href="#cb10-37" aria-hidden="true"></a>}</span>
<span id="cb10-38"><a href="#cb10-38" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;manage_edit-portfolio_sortable_columns&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_sortable_columns&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="custom-permalink-structure">Custom Permalink Structure</h2>
<div class="sourceCode" id="cb11">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true"></a><span class="kw">function</span> dprt_custom_permalinks<span class="ot">(</span><span class="kw">$post_link</span><span class="ot">,</span> <span class="kw">$post</span><span class="ot">)</span> {</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span><span class="kw">$post</span>-&gt;post_type === <span class="st">&#39;portfolio&#39;</span><span class="ot">)</span> {</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true"></a>        <span class="kw">$terms</span> = get_the_terms<span class="ot">(</span><span class="kw">$post</span>-&gt;<span class="kw">ID</span><span class="ot">,</span> <span class="st">&#39;portfolio_category&#39;</span><span class="ot">);</span></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true"></a>        <span class="kw">if</span> <span class="ot">(</span><span class="kw">$terms</span> &amp;&amp; !is_wp_error<span class="ot">(</span><span class="kw">$terms</span><span class="ot">))</span> {</span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true"></a>            <span class="kw">$category</span> = <span class="fu">array_shift</span><span class="ot">(</span><span class="kw">$terms</span><span class="ot">);</span></span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true"></a>            <span class="kw">return</span> <span class="fu">str_replace</span><span class="ot">(</span><span class="st">&#39;%portfolio_category%&#39;</span><span class="ot">,</span> <span class="kw">$category</span>-&gt;slug<span class="ot">,</span> <span class="kw">$post_link</span><span class="ot">);</span></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true"></a>        }</span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true"></a>    }</span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$post_link</span><span class="ot">;</span></span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true"></a>}</span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;post_type_link&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_custom_permalinks&#39;</span><span class="ot">,</span> <span class="dv">10</span><span class="ot">,</span> <span class="dv">2</span><span class="ot">);</span></span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true"></a></span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true"></a><span class="co">// Register rewrite with taxonomy</span></span>
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true"></a>register_post_type<span class="ot">(</span><span class="st">&#39;portfolio&#39;</span><span class="ot">,</span> <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb11-15"><a href="#cb11-15" aria-hidden="true"></a>    <span class="st">&#39;rewrite&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb11-16"><a href="#cb11-16" aria-hidden="true"></a>        <span class="st">&#39;slug&#39;</span> =&gt; <span class="st">&#39;portfolio/%portfolio_category%&#39;</span><span class="ot">,</span></span>
<span id="cb11-17"><a href="#cb11-17" aria-hidden="true"></a>        <span class="st">&#39;with_front&#39;</span> =&gt; <span class="kw">false</span></span>
<span id="cb11-18"><a href="#cb11-18" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb11-19"><a href="#cb11-19" aria-hidden="true"></a>    <span class="co">// ... other args</span></span>
<span id="cb11-20"><a href="#cb11-20" aria-hidden="true"></a><span class="ot">));</span></span></code></pre>
</div>
<h2 id="best-practices">Best Practices</h2>
<p><strong>Use Descriptive Slugs</strong>: ‘portfolio’ better than ‘pf’.</p>
<p><strong>Translation Ready</strong>: Use _x() and __() for labels.</p>
<p><strong>Namespace Functions</strong>: Prefix functions to avoid conflicts.</p>
<p><strong>Flush Permalinks</strong>: After registration changes, visit Settings → Permalinks.</p>
<p><strong>show_in_rest</strong>: Always true for Gutenberg support.</p>
<p><strong>Separate Files</strong>: Keep CPT registration in dedicated file (inc/post-types.php).</p>
<p><strong>Documentation</strong>: Comment complex registrations explaining purpose.</p>
<h2 id="conclusion">Conclusion</h2>
<p>WordPress custom post types extend content structure beyond posts and pages without plugins. Register CPTs using register_post_type(), create custom taxonomies with register_taxonomy(), build template files following WordPress hierarchy, and query content with WP_Query. Manual CPT registration provides complete control, better performance, and deeper platform understanding compared to plugin-based approaches.</p>
<h2 id="external-links">External Links</h2>
<ol type="1">
<li><a href="https://developer.wordpress.org/reference/functions/register_post_type/">WordPress register_post_type() Reference</a></li>
<li><a href="https://developer.wordpress.org/reference/functions/register_taxonomy/">WordPress register_taxonomy() Reference</a></li>
<li><a href="https://developer.wordpress.org/themes/basics/template-hierarchy/">Template Hierarchy</a></li>
<li><a href="https://generatewp.com/post-type/">GenerateWP Post Type Generator</a></li>
<li><a href="https://developer.wordpress.org/plugins/post-types/">WordPress CPT Documentation</a></li>
</ol>
<h2 id="call-to-action">Call to Action</h2>
<p>Custom post types need protection. <a href="https://backupcopilotplugin.com/">Backup Copilot Pro</a> safeguards your WordPress custom configurations and content. Protect your CPT implementations—start your free 30-day trial today!</p>
<p>The post <a href="https://developryplugins.com/how-to-add-custom-post-types-to-wordpress-without-plugins/">How to Add Custom Post Types to WordPress Without Plugins</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Add Custom User Roles and Capabilities in WordPress</title>
		<link>https://developryplugins.com/how-to-add-custom-user-roles-and-capabilities-in-wordpress/</link>
		
		<dc:creator><![CDATA[Krasen Slavov]]></dc:creator>
		<pubDate>Sat, 15 Aug 2026 09:00:00 +0000</pubDate>
				<category><![CDATA[WordPress Tips Tricks & Hacks]]></category>
		<category><![CDATA[access control]]></category>
		<category><![CDATA[capabilities]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[user management]]></category>
		<category><![CDATA[user roles]]></category>
		<guid isPermaLink="false">https://developryplugins.com/?p=189</guid>

					<description><![CDATA[<p>WordPress user roles and capabilities system controls who accesses what functionality. Beyond default roles (Administrator, Editor, Author), custom roles enable precise permission management for clients, contributors, and specialized users. This...</p>
<p>The post <a href="https://developryplugins.com/how-to-add-custom-user-roles-and-capabilities-in-wordpress/">How to Add Custom User Roles and Capabilities in WordPress</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><!-- @format --></p>
<p>WordPress user roles and capabilities system controls who accesses what functionality. Beyond default roles (Administrator, Editor, Author), custom roles enable precise permission management for clients, contributors, and specialized users. This comprehensive guide teaches role creation, capability assignment, conditional content display, and advanced permission management for granular WordPress access control.</p>
<h2 id="understanding-roles-vs-capabilities">Understanding Roles vs Capabilities</h2>
<p><strong>Roles</strong>: Predefined permission sets assigned to users.</p>
<p><strong>Capabilities</strong>: Specific permissions (edit_posts, publish_pages, manage_options).</p>
<p><strong>Relationship</strong>: Roles contain multiple capabilities. Users assigned roles inherit those capabilities.</p>
<p>Example: Editor role includes edit_posts, publish_posts, edit_pages, but excludes manage_options.</p>
<h2 id="default-wordpress-roles">Default WordPress Roles</h2>
<p><strong>Super Admin</strong> (Multisite only):</p>
<ul>
<li>Network-level control</li>
<li>All capabilities across all sites</li>
</ul>
<p><strong>Administrator</strong>:</p>
<ul>
<li>Complete site control</li>
<li>User management</li>
<li>Plugin/theme installation</li>
<li>Settings modification</li>
</ul>
<p><strong>Editor</strong>:</p>
<ul>
<li>Manage and publish all posts</li>
<li>Moderate comments</li>
<li>Manage categories/tags</li>
</ul>
<p><strong>Author</strong>:</p>
<ul>
<li>Write and publish own posts</li>
<li>Upload files</li>
<li>Cannot edit others’ posts</li>
</ul>
<p><strong>Contributor</strong>:</p>
<ul>
<li>Write posts (cannot publish)</li>
<li>Edit own unpublished posts</li>
<li>No media upload</li>
</ul>
<p><strong>Subscriber</strong>:</p>
<ul>
<li>Read content</li>
<li>Manage own profile</li>
<li>No posting capabilities</li>
</ul>
<h2 id="creating-custom-user-roles">Creating Custom User Roles</h2>
<p><strong>Basic Role Creation</strong>:</p>
<div class="sourceCode" id="cb1">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true"></a><span class="kw">function</span> dprt_add_custom_role<span class="ot">()</span> {</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true"></a>    add_role<span class="ot">(</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true"></a>        <span class="st">&#39;client&#39;</span><span class="ot">,</span>                    <span class="co">// Role slug</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true"></a>        <span class="st">&#39;Client&#39;</span><span class="ot">,</span>                    <span class="co">// Display name</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true"></a>            <span class="st">&#39;read&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span>          <span class="co">// Capability</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true"></a>            <span class="st">&#39;edit_posts&#39;</span> =&gt; <span class="kw">false</span><span class="ot">,</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true"></a>            <span class="st">&#39;delete_posts&#39;</span> =&gt; <span class="kw">false</span><span class="ot">,</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true"></a>        <span class="ot">)</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true"></a>}</span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;init&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_add_custom_role&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<p><strong>Run once</strong>: Use plugin activation hook or run manually then remove code.</p>
<p><strong>Plugin Activation Hook</strong>:</p>
<div class="sourceCode" id="cb2">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true"></a>register_activation_hook<span class="ot">(</span><span class="kw">__FILE__</span><span class="ot">,</span> <span class="st">&#39;dprt_add_custom_role&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="custom-role-with-specific-capabilities">Custom Role with Specific Capabilities</h2>
<p><strong>Content Manager Role</strong>:</p>
<div class="sourceCode" id="cb3">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true"></a><span class="kw">function</span> dprt_add_content_manager_role<span class="ot">()</span> {</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true"></a>    add_role<span class="ot">(</span><span class="st">&#39;content_manager&#39;</span><span class="ot">,</span> <span class="st">&#39;Content Manager&#39;</span><span class="ot">,</span> <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true"></a>        <span class="co">// Basic capabilities</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true"></a>        <span class="st">&#39;read&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true"></a></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true"></a>        <span class="co">// Post capabilities</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true"></a>        <span class="st">&#39;edit_posts&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true"></a>        <span class="st">&#39;edit_published_posts&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true"></a>        <span class="st">&#39;publish_posts&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true"></a>        <span class="st">&#39;delete_posts&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true"></a>        <span class="st">&#39;delete_published_posts&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true"></a></span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true"></a>        <span class="co">// Page capabilities</span></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true"></a>        <span class="st">&#39;edit_pages&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true"></a>        <span class="st">&#39;edit_published_pages&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true"></a>        <span class="st">&#39;publish_pages&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true"></a>        <span class="st">&#39;delete_pages&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true"></a></span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true"></a>        <span class="co">// Media</span></span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true"></a>        <span class="st">&#39;upload_files&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true"></a></span>
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true"></a>        <span class="co">// Comments</span></span>
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true"></a>        <span class="st">&#39;moderate_comments&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true"></a></span>
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true"></a>        <span class="co">// Categories/Tags</span></span>
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true"></a>        <span class="st">&#39;manage_categories&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb3-27"><a href="#cb3-27" aria-hidden="true"></a></span>
<span id="cb3-28"><a href="#cb3-28" aria-hidden="true"></a>        <span class="co">// Excluded capabilities</span></span>
<span id="cb3-29"><a href="#cb3-29" aria-hidden="true"></a>        <span class="st">&#39;manage_options&#39;</span> =&gt; <span class="kw">false</span><span class="ot">,</span></span>
<span id="cb3-30"><a href="#cb3-30" aria-hidden="true"></a>        <span class="st">&#39;edit_theme_options&#39;</span> =&gt; <span class="kw">false</span><span class="ot">,</span></span>
<span id="cb3-31"><a href="#cb3-31" aria-hidden="true"></a>        <span class="st">&#39;install_plugins&#39;</span> =&gt; <span class="kw">false</span><span class="ot">,</span></span>
<span id="cb3-32"><a href="#cb3-32" aria-hidden="true"></a>        <span class="st">&#39;activate_plugins&#39;</span> =&gt; <span class="kw">false</span><span class="ot">,</span></span>
<span id="cb3-33"><a href="#cb3-33" aria-hidden="true"></a>    <span class="ot">));</span></span>
<span id="cb3-34"><a href="#cb3-34" aria-hidden="true"></a>}</span>
<span id="cb3-35"><a href="#cb3-35" aria-hidden="true"></a>register_activation_hook<span class="ot">(</span><span class="kw">__FILE__</span><span class="ot">,</span> <span class="st">&#39;dprt_add_content_manager_role&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="adding-capabilities-to-existing-roles">Adding Capabilities to Existing Roles</h2>
<p><strong>Add Capability to Role</strong>:</p>
<div class="sourceCode" id="cb4">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true"></a><span class="kw">function</span> dprt_add_capabilities_to_editor<span class="ot">()</span> {</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true"></a>    <span class="kw">$role</span> = get_role<span class="ot">(</span><span class="st">&#39;editor&#39;</span><span class="ot">);</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true"></a>    <span class="kw">$role</span>-&gt;add_cap<span class="ot">(</span><span class="st">&#39;edit_theme_options&#39;</span><span class="ot">);</span>  <span class="co">// Access Appearance menu</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true"></a>    <span class="kw">$role</span>-&gt;add_cap<span class="ot">(</span><span class="st">&#39;manage_options&#39;</span><span class="ot">);</span>      <span class="co">// Access Settings</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true"></a>}</span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;admin_init&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_add_capabilities_to_editor&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<p><strong>Run once then remove</strong> to avoid adding capability repeatedly.</p>
<h2 id="removing-capabilities">Removing Capabilities</h2>
<div class="sourceCode" id="cb5">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true"></a><span class="kw">function</span> dprt_remove_capability<span class="ot">()</span> {</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true"></a>    <span class="kw">$role</span> = get_role<span class="ot">(</span><span class="st">&#39;author&#39;</span><span class="ot">);</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true"></a>    <span class="kw">$role</span>-&gt;remove_cap<span class="ot">(</span><span class="st">&#39;publish_posts&#39;</span><span class="ot">);</span>  <span class="co">// Authors can&#39;t publish, only draft</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true"></a>}</span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;admin_init&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_remove_capability&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="custom-post-type-capabilities">Custom Post Type Capabilities</h2>
<p><strong>CPT with Custom Capabilities</strong>:</p>
<div class="sourceCode" id="cb6">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true"></a>register_post_type<span class="ot">(</span><span class="st">&#39;portfolio&#39;</span><span class="ot">,</span> <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true"></a>    <span class="st">&#39;capability_type&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span><span class="st">&#39;portfolio_item&#39;</span><span class="ot">,</span> <span class="st">&#39;portfolio_items&#39;</span><span class="ot">),</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true"></a>    <span class="st">&#39;map_meta_cap&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true"></a>    <span class="co">// ... other args</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true"></a><span class="ot">));</span></span></code></pre>
</div>
<p>Generates capabilities:</p>
<ul>
<li>edit_portfolio_item</li>
<li>edit_portfolio_items</li>
<li>edit_published_portfolio_items</li>
<li>publish_portfolio_items</li>
<li>read_private_portfolio_items</li>
<li>delete_portfolio_items</li>
<li>etc.</li>
</ul>
<p><strong>Assign CPT Capabilities to Role</strong>:</p>
<div class="sourceCode" id="cb7">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true"></a><span class="kw">function</span> dprt_add_portfolio_caps_to_editor<span class="ot">()</span> {</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true"></a>    <span class="kw">$role</span> = get_role<span class="ot">(</span><span class="st">&#39;editor&#39;</span><span class="ot">);</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true"></a></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true"></a>    <span class="kw">$caps</span> = <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true"></a>        <span class="st">&#39;edit_portfolio_item&#39;</span><span class="ot">,</span></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true"></a>        <span class="st">&#39;edit_portfolio_items&#39;</span><span class="ot">,</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true"></a>        <span class="st">&#39;edit_others_portfolio_items&#39;</span><span class="ot">,</span></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true"></a>        <span class="st">&#39;publish_portfolio_items&#39;</span><span class="ot">,</span></span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true"></a>        <span class="st">&#39;read_private_portfolio_items&#39;</span><span class="ot">,</span></span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true"></a>        <span class="st">&#39;delete_portfolio_items&#39;</span><span class="ot">,</span></span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true"></a>        <span class="st">&#39;delete_private_portfolio_items&#39;</span><span class="ot">,</span></span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true"></a>        <span class="st">&#39;delete_published_portfolio_items&#39;</span><span class="ot">,</span></span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true"></a>        <span class="st">&#39;delete_others_portfolio_items&#39;</span><span class="ot">,</span></span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true"></a>        <span class="st">&#39;edit_private_portfolio_items&#39;</span><span class="ot">,</span></span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true"></a>        <span class="st">&#39;edit_published_portfolio_items&#39;</span><span class="ot">,</span></span>
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb7-17"><a href="#cb7-17" aria-hidden="true"></a></span>
<span id="cb7-18"><a href="#cb7-18" aria-hidden="true"></a>    <span class="kw">foreach</span> <span class="ot">(</span><span class="kw">$caps</span> <span class="kw">as</span> <span class="kw">$cap</span><span class="ot">)</span> {</span>
<span id="cb7-19"><a href="#cb7-19" aria-hidden="true"></a>        <span class="kw">$role</span>-&gt;add_cap<span class="ot">(</span><span class="kw">$cap</span><span class="ot">);</span></span>
<span id="cb7-20"><a href="#cb7-20" aria-hidden="true"></a>    }</span>
<span id="cb7-21"><a href="#cb7-21" aria-hidden="true"></a>}</span>
<span id="cb7-22"><a href="#cb7-22" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;admin_init&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_add_portfolio_caps_to_editor&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="removing-custom-roles">Removing Custom Roles</h2>
<div class="sourceCode" id="cb8">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true"></a><span class="kw">function</span> dprt_remove_custom_role<span class="ot">()</span> {</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true"></a>    remove_role<span class="ot">(</span><span class="st">&#39;client&#39;</span><span class="ot">);</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true"></a>}</span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true"></a>register_deactivation_hook<span class="ot">(</span><span class="kw">__FILE__</span><span class="ot">,</span> <span class="st">&#39;dprt_remove_custom_role&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="checking-user-capabilities">Checking User Capabilities</h2>
<p><strong>Check if User Can</strong>:</p>
<div class="sourceCode" id="cb9">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true"></a><span class="kw">if</span> <span class="ot">(</span>current_user_can<span class="ot">(</span><span class="st">&#39;manage_options&#39;</span><span class="ot">))</span> {</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true"></a>    <span class="co">// User is administrator or has manage_options capability</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;You have admin access&#39;</span><span class="ot">;</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true"></a>}</span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true"></a></span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true"></a><span class="kw">if</span> <span class="ot">(</span>current_user_can<span class="ot">(</span><span class="st">&#39;edit_posts&#39;</span><span class="ot">))</span> {</span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;You can edit posts&#39;</span><span class="ot">;</span></span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true"></a>}</span></code></pre>
</div>
<p><strong>Check Specific User</strong>:</p>
<div class="sourceCode" id="cb10">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true"></a><span class="kw">$user</span> = get_userdata<span class="ot">(</span><span class="kw">$user_id</span><span class="ot">);</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true"></a><span class="kw">if</span> <span class="ot">(</span><span class="kw">$user</span> &amp;&amp; <span class="kw">$user</span>-&gt;has_cap<span class="ot">(</span><span class="st">&#39;publish_posts&#39;</span><span class="ot">))</span> {</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true"></a>    <span class="co">// User can publish posts</span></span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="conditional-content-display">Conditional Content Display</h2>
<p><strong>Show Content Based on Role</strong>:</p>
<div class="sourceCode" id="cb11">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true"></a><span class="co">// Show admin-only content</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true"></a><span class="kw">if</span> <span class="ot">(</span>current_user_can<span class="ot">(</span><span class="st">&#39;administrator&#39;</span><span class="ot">))</span> {</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;div class=&quot;admin-notice&quot;&gt;Admin-only message&lt;/div&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true"></a>}</span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true"></a></span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true"></a><span class="co">// Show for multiple roles</span></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true"></a><span class="kw">if</span> <span class="ot">(</span>current_user_can<span class="ot">(</span><span class="st">&#39;edit_posts&#39;</span><span class="ot">)</span> || current_user_can<span class="ot">(</span><span class="st">&#39;edit_pages&#39;</span><span class="ot">))</span> {</span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;p&gt;You can edit content&lt;/p&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true"></a>}</span></code></pre>
</div>
<p><strong>Shortcode for Role-Based Content</strong>:</p>
<div class="sourceCode" id="cb12">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true"></a><span class="kw">function</span> dprt_role_content_shortcode<span class="ot">(</span><span class="kw">$atts</span><span class="ot">,</span> <span class="kw">$content</span> = <span class="kw">null</span><span class="ot">)</span> {</span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true"></a>    <span class="kw">$atts</span> = shortcode_atts<span class="ot">(</span><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true"></a>        <span class="st">&#39;role&#39;</span> =&gt; <span class="st">&#39;administrator&#39;</span><span class="ot">,</span></span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true"></a>    <span class="ot">),</span> <span class="kw">$atts</span><span class="ot">);</span></span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true"></a></span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span>current_user_can<span class="ot">(</span><span class="kw">$atts</span><span class="ot">[</span><span class="st">&#39;role&#39;</span><span class="ot">]))</span> {</span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true"></a>        <span class="kw">return</span> do_shortcode<span class="ot">(</span><span class="kw">$content</span><span class="ot">);</span></span>
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true"></a>    }</span>
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true"></a></span>
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true"></a>    <span class="kw">return</span> <span class="st">&#39;&#39;</span><span class="ot">;</span></span>
<span id="cb12-11"><a href="#cb12-11" aria-hidden="true"></a>}</span>
<span id="cb12-12"><a href="#cb12-12" aria-hidden="true"></a>add_shortcode<span class="ot">(</span><span class="st">&#39;role_content&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_role_content_shortcode&#39;</span><span class="ot">);</span></span>
<span id="cb12-13"><a href="#cb12-13" aria-hidden="true"></a></span>
<span id="cb12-14"><a href="#cb12-14" aria-hidden="true"></a><span class="co">// Usage: [role_content role=&quot;editor&quot;]Content for editors only[/role_content]</span></span></code></pre>
</div>
<h2 id="admin-menu-restrictions">Admin Menu Restrictions</h2>
<p><strong>Hide Menu Items by Role</strong>:</p>
<div class="sourceCode" id="cb13">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true"></a><span class="kw">function</span> dprt_remove_menus<span class="ot">()</span> {</span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true"></a>    <span class="co">// For non-administrators</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span>!current_user_can<span class="ot">(</span><span class="st">&#39;administrator&#39;</span><span class="ot">))</span> {</span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true"></a>        remove_menu_page<span class="ot">(</span><span class="st">&#39;tools.php&#39;</span><span class="ot">);</span>        <span class="co">// Tools</span></span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true"></a>        remove_menu_page<span class="ot">(</span><span class="st">&#39;plugins.php&#39;</span><span class="ot">);</span>      <span class="co">// Plugins</span></span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true"></a>        remove_menu_page<span class="ot">(</span><span class="st">&#39;themes.php&#39;</span><span class="ot">);</span>       <span class="co">// Appearance</span></span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true"></a>        remove_menu_page<span class="ot">(</span><span class="st">&#39;users.php&#39;</span><span class="ot">);</span>        <span class="co">// Users</span></span>
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true"></a>    }</span>
<span id="cb13-9"><a href="#cb13-9" aria-hidden="true"></a></span>
<span id="cb13-10"><a href="#cb13-10" aria-hidden="true"></a>    <span class="co">// For editors (more restrictive)</span></span>
<span id="cb13-11"><a href="#cb13-11" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span>current_user_can<span class="ot">(</span><span class="st">&#39;editor&#39;</span><span class="ot">))</span> {</span>
<span id="cb13-12"><a href="#cb13-12" aria-hidden="true"></a>        remove_menu_page<span class="ot">(</span><span class="st">&#39;options-general.php&#39;</span><span class="ot">);</span> <span class="co">// Settings</span></span>
<span id="cb13-13"><a href="#cb13-13" aria-hidden="true"></a>    }</span>
<span id="cb13-14"><a href="#cb13-14" aria-hidden="true"></a>}</span>
<span id="cb13-15"><a href="#cb13-15" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;admin_menu&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_remove_menus&#39;</span><span class="ot">,</span> <span class="dv">999</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="dashboard-widget-restrictions">Dashboard Widget Restrictions</h2>
<div class="sourceCode" id="cb14">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true"></a><span class="kw">function</span> dprt_remove_dashboard_widgets<span class="ot">()</span> {</span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span>!current_user_can<span class="ot">(</span><span class="st">&#39;administrator&#39;</span><span class="ot">))</span> {</span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true"></a>        remove_meta_box<span class="ot">(</span><span class="st">&#39;dashboard_primary&#39;</span><span class="ot">,</span> <span class="st">&#39;dashboard&#39;</span><span class="ot">,</span> <span class="st">&#39;side&#39;</span><span class="ot">);</span>  <span class="co">// WordPress News</span></span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true"></a>        remove_meta_box<span class="ot">(</span><span class="st">&#39;dashboard_quick_press&#39;</span><span class="ot">,</span> <span class="st">&#39;dashboard&#39;</span><span class="ot">,</span> <span class="st">&#39;side&#39;</span><span class="ot">);</span> <span class="co">// Quick Draft</span></span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true"></a>    }</span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true"></a>}</span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;wp_dashboard_setup&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_remove_dashboard_widgets&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="custom-capabilities-for-plugins">Custom Capabilities for Plugins</h2>
<p><strong>Create Plugin-Specific Capability</strong>:</p>
<div class="sourceCode" id="cb15">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true"></a><span class="kw">function</span> dprt_add_plugin_capability<span class="ot">()</span> {</span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true"></a>    <span class="kw">$admin</span> = get_role<span class="ot">(</span><span class="st">&#39;administrator&#39;</span><span class="ot">);</span></span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true"></a>    <span class="kw">$admin</span>-&gt;add_cap<span class="ot">(</span><span class="st">&#39;manage_custom_plugin&#39;</span><span class="ot">);</span></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true"></a></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true"></a>    <span class="kw">$editor</span> = get_role<span class="ot">(</span><span class="st">&#39;editor&#39;</span><span class="ot">);</span></span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true"></a>    <span class="kw">$editor</span>-&gt;add_cap<span class="ot">(</span><span class="st">&#39;use_custom_plugin&#39;</span><span class="ot">);</span>  <span class="co">// Limited access</span></span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true"></a>}</span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true"></a>register_activation_hook<span class="ot">(</span><span class="kw">__FILE__</span><span class="ot">,</span> <span class="st">&#39;dprt_add_plugin_capability&#39;</span><span class="ot">);</span></span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true"></a></span>
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true"></a><span class="co">// Check capability before showing plugin features</span></span>
<span id="cb15-11"><a href="#cb15-11" aria-hidden="true"></a><span class="kw">if</span> <span class="ot">(</span>current_user_can<span class="ot">(</span><span class="st">&#39;manage_custom_plugin&#39;</span><span class="ot">))</span> {</span>
<span id="cb15-12"><a href="#cb15-12" aria-hidden="true"></a>    <span class="co">// Show advanced plugin settings</span></span>
<span id="cb15-13"><a href="#cb15-13" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="role-management-plugins">Role Management Plugins</h2>
<p><strong>Members Plugin</strong>:</p>
<ul>
<li>GUI for role/capability management</li>
<li>Clone existing roles</li>
<li>Create custom capabilities</li>
<li>User-friendly interface</li>
</ul>
<p><strong>User Role Editor</strong>:</p>
<ul>
<li>Edit role capabilities visually</li>
<li>Assign multiple roles to users</li>
<li>Capability filtering</li>
</ul>
<p><strong>PublishPress Capabilities</strong>:</p>
<ul>
<li>Role duplication</li>
<li>Capability management</li>
<li>Custom post type integration</li>
</ul>
<h2 id="advanced-multiple-roles-per-user">Advanced: Multiple Roles per User</h2>
<p>WordPress doesn’t natively support multiple roles well, but:</p>
<div class="sourceCode" id="cb16">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true"></a><span class="kw">function</span> dprt_add_secondary_role<span class="ot">(</span><span class="kw">$user_id</span><span class="ot">,</span> <span class="kw">$role</span><span class="ot">)</span> {</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true"></a>    <span class="kw">$user</span> = get_userdata<span class="ot">(</span><span class="kw">$user_id</span><span class="ot">);</span></span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true"></a>    <span class="kw">$user</span>-&gt;add_role<span class="ot">(</span><span class="kw">$role</span><span class="ot">);</span>  <span class="co">// Adds role without removing existing</span></span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true"></a>}</span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true"></a></span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true"></a><span class="co">// Usage</span></span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true"></a>dprt_add_secondary_role<span class="ot">(</span><span class="dv">5</span><span class="ot">,</span> <span class="st">&#39;editor&#39;</span><span class="ot">);</span>  <span class="co">// User 5 now has their original role + editor</span></span></code></pre>
</div>
<p><strong>Check Any of Multiple Roles</strong>:</p>
<div class="sourceCode" id="cb17">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true"></a><span class="kw">function</span> dprt_user_has_role<span class="ot">(</span><span class="kw">$user_id</span><span class="ot">,</span> <span class="kw">$roles</span><span class="ot">)</span> {</span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true"></a>    <span class="kw">$user</span> = get_userdata<span class="ot">(</span><span class="kw">$user_id</span><span class="ot">);</span></span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span>!<span class="kw">$user</span><span class="ot">)</span> <span class="kw">return</span> <span class="kw">false</span><span class="ot">;</span></span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true"></a></span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true"></a>    <span class="kw">foreach</span> <span class="ot">(</span><span class="kw">$roles</span> <span class="kw">as</span> <span class="kw">$role</span><span class="ot">)</span> {</span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true"></a>        <span class="kw">if</span> <span class="ot">(</span><span class="fu">in_array</span><span class="ot">(</span><span class="kw">$role</span><span class="ot">,</span> <span class="dt">(array)</span> <span class="kw">$user</span>-&gt;roles<span class="ot">))</span> {</span>
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true"></a>            <span class="kw">return</span> <span class="kw">true</span><span class="ot">;</span></span>
<span id="cb17-8"><a href="#cb17-8" aria-hidden="true"></a>        }</span>
<span id="cb17-9"><a href="#cb17-9" aria-hidden="true"></a>    }</span>
<span id="cb17-10"><a href="#cb17-10" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">false</span><span class="ot">;</span></span>
<span id="cb17-11"><a href="#cb17-11" aria-hidden="true"></a>}</span>
<span id="cb17-12"><a href="#cb17-12" aria-hidden="true"></a></span>
<span id="cb17-13"><a href="#cb17-13" aria-hidden="true"></a><span class="co">// Usage</span></span>
<span id="cb17-14"><a href="#cb17-14" aria-hidden="true"></a><span class="kw">if</span> <span class="ot">(</span>dprt_user_has_role<span class="ot">(</span><span class="kw">$user_id</span><span class="ot">,</span> <span class="kw">array</span><span class="ot">(</span><span class="st">&#39;editor&#39;</span><span class="ot">,</span> <span class="st">&#39;administrator&#39;</span><span class="ot">)))</span> {</span>
<span id="cb17-15"><a href="#cb17-15" aria-hidden="true"></a>    <span class="co">// User is editor OR administrator</span></span>
<span id="cb17-16"><a href="#cb17-16" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="security-best-practices">Security Best Practices</h2>
<p><strong>Principle of Least Privilege</strong>: Grant minimum necessary capabilities.</p>
<p><strong>Avoid Capability Checks by Role Name</strong>:</p>
<div class="sourceCode" id="cb18">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true"></a><span class="co">// BAD</span></span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true"></a><span class="kw">if</span> <span class="ot">(</span><span class="fu">in_array</span><span class="ot">(</span><span class="st">&#39;administrator&#39;</span><span class="ot">,</span> <span class="kw">$user</span>-&gt;roles<span class="ot">))</span> { }</span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true"></a></span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true"></a><span class="co">// GOOD</span></span>
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true"></a><span class="kw">if</span> <span class="ot">(</span>current_user_can<span class="ot">(</span><span class="st">&#39;manage_options&#39;</span><span class="ot">))</span> { }</span></code></pre>
</div>
<p>Capability checks are more flexible and future-proof.</p>
<p><strong>Escape Output</strong>:</p>
<div class="sourceCode" id="cb19">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true"></a><span class="co">// When displaying user-submitted content based on roles</span></span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true"></a><span class="kw">if</span> <span class="ot">(</span>current_user_can<span class="ot">(</span><span class="st">&#39;edit_posts&#39;</span><span class="ot">))</span> {</span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;p&gt;&#39;</span> . esc_html<span class="ot">(</span><span class="kw">$user_content</span><span class="ot">)</span> . <span class="st">&#39;&lt;/p&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="debugging-roles-and-capabilities">Debugging Roles and Capabilities</h2>
<p><strong>View User Capabilities</strong>:</p>
<div class="sourceCode" id="cb20">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true"></a><span class="kw">function</span> dprt_show_user_capabilities<span class="ot">()</span> {</span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true"></a>    <span class="kw">$user</span> = wp_get_current_user<span class="ot">();</span></span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;pre&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true"></a>    <span class="fu">print_r</span><span class="ot">(</span><span class="kw">$user</span>-&gt;allcaps<span class="ot">);</span>  <span class="co">// All capabilities</span></span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true"></a>    <span class="fu">print_r</span><span class="ot">(</span><span class="kw">$user</span>-&gt;roles<span class="ot">);</span>     <span class="co">// Assigned roles</span></span>
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;/pre&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb20-7"><a href="#cb20-7" aria-hidden="true"></a>}</span>
<span id="cb20-8"><a href="#cb20-8" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;admin_notices&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_show_user_capabilities&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<p><strong>List All Roles</strong>:</p>
<div class="sourceCode" id="cb21">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true"></a><span class="kw">global</span> <span class="kw">$wp_roles</span><span class="ot">;</span></span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true"></a><span class="kw">$all_roles</span> = <span class="kw">$wp_roles</span>-&gt;roles<span class="ot">;</span></span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true"></a><span class="fu">print_r</span><span class="ot">(</span><span class="kw">$all_roles</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="programmatic-role-assignment">Programmatic Role Assignment</h2>
<p><strong>Assign Role to User on Registration</strong>:</p>
<div class="sourceCode" id="cb22">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true"></a><span class="kw">function</span> dprt_set_default_user_role<span class="ot">(</span><span class="kw">$user_id</span><span class="ot">)</span> {</span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true"></a>    <span class="kw">$user</span> = get_userdata<span class="ot">(</span><span class="kw">$user_id</span><span class="ot">);</span></span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true"></a>    <span class="kw">$user</span>-&gt;set_role<span class="ot">(</span><span class="st">&#39;client&#39;</span><span class="ot">);</span>  <span class="co">// Change from default &#39;subscriber&#39;</span></span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true"></a>}</span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;user_register&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_set_default_user_role&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<p><strong>Change Role Based on Conditions</strong>:</p>
<div class="sourceCode" id="cb23">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true"></a><span class="kw">function</span> dprt_upgrade_user_role<span class="ot">(</span><span class="kw">$user_id</span><span class="ot">)</span> {</span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true"></a>    <span class="co">// Example: Upgrade to author after 10 published comments</span></span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true"></a>    <span class="kw">$comment_count</span> = get_comments<span class="ot">(</span><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true"></a>        <span class="st">&#39;user_id&#39;</span> =&gt; <span class="kw">$user_id</span><span class="ot">,</span></span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true"></a>        <span class="st">&#39;status&#39;</span> =&gt; <span class="st">&#39;approve&#39;</span><span class="ot">,</span></span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true"></a>        <span class="st">&#39;count&#39;</span> =&gt; <span class="kw">true</span></span>
<span id="cb23-7"><a href="#cb23-7" aria-hidden="true"></a>    <span class="ot">));</span></span>
<span id="cb23-8"><a href="#cb23-8" aria-hidden="true"></a></span>
<span id="cb23-9"><a href="#cb23-9" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span><span class="kw">$comment_count</span> &gt;= <span class="dv">10</span><span class="ot">)</span> {</span>
<span id="cb23-10"><a href="#cb23-10" aria-hidden="true"></a>        <span class="kw">$user</span> = get_userdata<span class="ot">(</span><span class="kw">$user_id</span><span class="ot">);</span></span>
<span id="cb23-11"><a href="#cb23-11" aria-hidden="true"></a>        <span class="kw">$user</span>-&gt;set_role<span class="ot">(</span><span class="st">&#39;author&#39;</span><span class="ot">);</span></span>
<span id="cb23-12"><a href="#cb23-12" aria-hidden="true"></a>    }</span>
<span id="cb23-13"><a href="#cb23-13" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="woocommerce-custom-roles">WooCommerce Custom Roles</h2>
<p><strong>Customer Role Modifications</strong>:</p>
<div class="sourceCode" id="cb24">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true"></a><span class="kw">function</span> dprt_modify_customer_role<span class="ot">()</span> {</span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true"></a>    <span class="kw">$customer</span> = get_role<span class="ot">(</span><span class="st">&#39;customer&#39;</span><span class="ot">);</span></span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true"></a>    <span class="kw">$customer</span>-&gt;add_cap<span class="ot">(</span><span class="st">&#39;read&#39;</span><span class="ot">);</span></span>
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true"></a>    <span class="kw">$customer</span>-&gt;add_cap<span class="ot">(</span><span class="st">&#39;view_order_history&#39;</span><span class="ot">);</span>  <span class="co">// Custom capability</span></span>
<span id="cb24-5"><a href="#cb24-5" aria-hidden="true"></a>}</span>
<span id="cb24-6"><a href="#cb24-6" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;init&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_modify_customer_role&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="conclusion">Conclusion</h2>
<p>WordPress custom user roles and capabilities enable precise permission management beyond default role limitations. Create custom roles with add_role(), assign specific capabilities via add_cap(), check permissions using current_user_can(), and implement role-based content visibility. Programmatic role management provides granular access control for clients, contributors, and specialized users, ensuring security through least-privilege principles while maintaining workflow flexibility.</p>
<h2 id="external-links">External Links</h2>
<ol type="1">
<li><a href="https://wordpress.org/support/article/roles-and-capabilities/">WordPress Roles and Capabilities</a></li>
<li><a href="https://developer.wordpress.org/reference/functions/add_role/">add_role() Reference</a></li>
<li><a href="https://developer.wordpress.org/reference/functions/current_user_can/">current_user_can() Reference</a></li>
<li><a href="https://wordpress.org/plugins/members/">Members Plugin</a></li>
<li><a href="https://wordpress.org/plugins/user-role-editor/">User Role Editor</a></li>
</ol>
<h2 id="call-to-action">Call to Action</h2>
<p>User management configurations need protection. <a href="https://backupcopilotplugin.com/">Backup Copilot Pro</a> safeguards your WordPress user roles and permissions. Protect your access control setup—start your free 30-day trial today!</p>
<p>The post <a href="https://developryplugins.com/how-to-add-custom-user-roles-and-capabilities-in-wordpress/">How to Add Custom User Roles and Capabilities in WordPress</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Block Brute Force Attacks on WordPress Login Pages</title>
		<link>https://developryplugins.com/how-to-block-brute-force-attacks-on-wordpress-login-pages/</link>
		
		<dc:creator><![CDATA[Krasen Slavov]]></dc:creator>
		<pubDate>Mon, 10 Aug 2026 09:00:00 +0000</pubDate>
				<category><![CDATA[WordPress Security & Protection]]></category>
		<category><![CDATA[brute force protection]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[limit login attempts]]></category>
		<category><![CDATA[login security]]></category>
		<category><![CDATA[wordpress security]]></category>
		<guid isPermaLink="false">https://developryplugins.com/?p=130</guid>

					<description><![CDATA[<p>Brute force attacks on WordPress login pages are relentless. Bots try thousands of username/password combinations until they gain access. These attacks consume server resources, slow down your site, and eventually...</p>
<p>The post <a href="https://developryplugins.com/how-to-block-brute-force-attacks-on-wordpress-login-pages/">How to Block Brute Force Attacks on WordPress Login Pages</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><!-- @format --></p>
<p>Brute force attacks on WordPress login pages are relentless. Bots try thousands of username/password combinations until they gain access. These attacks consume server resources, slow down your site, and eventually succeed against weak passwords.</p>
<p>This guide provides multiple defensive layers to block brute force attacks, from limiting login attempts to IP whitelisting and CAPTCHA implementation.</p>
<h2 id="understanding-brute-force-attacks">Understanding Brute Force Attacks</h2>
<h3 id="how-they-work">How They Work</h3>
<p>Attackers use automated scripts to try common passwords against wp-login.php:</p>
<pre><code>admin / password
admin / 123456
admin / admin123
administrator / password
...thousands more combinations</code></pre>
<h3 id="signs-of-an-attack">Signs of an Attack</h3>
<ul>
<li>Hundreds of failed login attempts in logs</li>
<li>Increased server CPU/memory usage</li>
<li>Slow admin dashboard</li>
<li>Email flood of failed login notifications</li>
<li>IP addresses from foreign countries</li>
<li>Automated bot patterns (rapid-fire attempts)</li>
</ul>
<h2 id="layer-1-limit-login-attempts">Layer 1: Limit Login Attempts</h2>
<h3 id="using-limit-login-attempts-reloaded">Using Limit Login Attempts Reloaded</h3>
<div class="sourceCode" id="cb2">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true"></a><span class="co"># Install via WP-CLI</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true"></a><span class="ex">wp</span> plugin install limit-login-attempts-reloaded --activate</span></code></pre>
</div>
<p><strong>Recommended Settings:</strong></p>
<ul>
<li><strong>Allowed attempts:</strong> 4</li>
<li><strong>Lockout duration:</strong> 20 minutes</li>
<li><strong>Reset after:</strong> 12 hours</li>
<li><strong>Long lockout:</strong> 24 hours after 4 lockouts</li>
</ul>
<p><strong>Manual Implementation:</strong></p>
<div class="sourceCode" id="cb3">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true"></a><span class="co">// In functions.php or custom plugin</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;wp_login_failed&#39;</span><span class="ot">,</span> <span class="st">&#39;track_failed_login&#39;</span><span class="ot">);</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true"></a></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true"></a><span class="kw">function</span> track_failed_login<span class="ot">(</span><span class="kw">$username</span><span class="ot">)</span> {</span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true"></a>    <span class="kw">$ip</span> = <span class="kw">$_SERVER</span><span class="ot">[</span><span class="st">&#39;REMOTE_ADDR&#39;</span><span class="ot">];</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true"></a>    <span class="kw">$attempts</span> = get_transient<span class="ot">(</span><span class="st">&#39;failed_login_&#39;</span> . <span class="kw">$ip</span><span class="ot">)</span> <span class="ot">?:</span> <span class="dv">0</span><span class="ot">;</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true"></a>    <span class="kw">$attempts</span>++<span class="ot">;</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true"></a></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true"></a>    set_transient<span class="ot">(</span><span class="st">&#39;failed_login_&#39;</span> . <span class="kw">$ip</span><span class="ot">,</span> <span class="kw">$attempts</span><span class="ot">,</span> <span class="dv">20</span> * <span class="kw">MINUTE_IN_SECONDS</span><span class="ot">);</span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true"></a></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span><span class="kw">$attempts</span> &gt;= <span class="dv">5</span><span class="ot">)</span> {</span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true"></a>        <span class="co">// Lock out this IP</span></span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true"></a>        set_transient<span class="ot">(</span><span class="st">&#39;lockout_&#39;</span> . <span class="kw">$ip</span><span class="ot">,</span> <span class="kw">true</span><span class="ot">,</span> <span class="kw">HOUR_IN_SECONDS</span><span class="ot">);</span></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true"></a>        wp_die<span class="ot">(</span><span class="st">&#39;Too many failed login attempts. Please try again in 1 hour.&#39;</span><span class="ot">);</span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true"></a>    }</span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true"></a>}</span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true"></a></span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true"></a><span class="co">// Check before allowing login</span></span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;authenticate&#39;</span><span class="ot">,</span> <span class="st">&#39;check_lockout&#39;</span><span class="ot">,</span> <span class="dv">30</span><span class="ot">,</span> <span class="dv">3</span><span class="ot">);</span></span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true"></a></span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true"></a><span class="kw">function</span> check_lockout<span class="ot">(</span><span class="kw">$user</span><span class="ot">,</span> <span class="kw">$username</span><span class="ot">,</span> <span class="kw">$password</span><span class="ot">)</span> {</span>
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true"></a>    <span class="kw">$ip</span> = <span class="kw">$_SERVER</span><span class="ot">[</span><span class="st">&#39;REMOTE_ADDR&#39;</span><span class="ot">];</span></span>
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true"></a></span>
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span>get_transient<span class="ot">(</span><span class="st">&#39;lockout_&#39;</span> . <span class="kw">$ip</span><span class="ot">))</span> {</span>
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true"></a>        <span class="kw">return</span> <span class="kw">new</span> WP_Error<span class="ot">(</span><span class="st">&#39;lockout&#39;</span><span class="ot">,</span> <span class="st">&#39;Account locked due to too many failed attempts.&#39;</span><span class="ot">);</span></span>
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true"></a>    }</span>
<span id="cb3-27"><a href="#cb3-27" aria-hidden="true"></a></span>
<span id="cb3-28"><a href="#cb3-28" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$user</span><span class="ot">;</span></span>
<span id="cb3-29"><a href="#cb3-29" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="layer-2-add-captcha-protection">Layer 2: Add CAPTCHA Protection</h2>
<h3 id="google-recaptcha-v3-integration">Google reCAPTCHA v3 Integration</h3>
<div class="sourceCode" id="cb4">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true"></a><span class="co">// Add to functions.php</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true"></a></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true"></a><span class="co">// Enqueue reCAPTCHA script</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;login_enqueue_scripts&#39;</span><span class="ot">,</span> <span class="st">&#39;add_recaptcha_to_login&#39;</span><span class="ot">);</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true"></a></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true"></a><span class="kw">function</span> add_recaptcha_to_login<span class="ot">()</span> {</span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true"></a>    <span class="kw">?&gt;</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true"></a>    &lt;script src=<span class="st">&quot;https://www.google.com/recaptcha/api.js&quot;</span> async defer&gt;&lt;/script&gt;</span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true"></a>    &lt;script&gt;</span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true"></a>    <span class="kw">function</span> onSubmit<span class="ot">(</span>token<span class="ot">)</span> {</span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true"></a>        document.getElementById<span class="ot">(</span><span class="st">&quot;loginform&quot;</span><span class="ot">)</span>.submit<span class="ot">();</span></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true"></a>    }</span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true"></a>    &lt;/script&gt;</span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php</span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true"></a>}</span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true"></a></span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true"></a><span class="co">// Add reCAPTCHA to login form</span></span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;login_form&#39;</span><span class="ot">,</span> <span class="st">&#39;display_recaptcha&#39;</span><span class="ot">);</span></span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true"></a></span>
<span id="cb4-20"><a href="#cb4-20" aria-hidden="true"></a><span class="kw">function</span> display_recaptcha<span class="ot">()</span> {</span>
<span id="cb4-21"><a href="#cb4-21" aria-hidden="true"></a>    <span class="kw">?&gt;</span></span>
<span id="cb4-22"><a href="#cb4-22" aria-hidden="true"></a>    &lt;div <span class="kw">class</span>=<span class="st">&quot;g-recaptcha&quot;</span> data-sitekey=<span class="st">&quot;YOUR_SITE_KEY&quot;</span> data-callback=<span class="st">&quot;onSubmit&quot;</span>&gt;&lt;/div&gt;</span>
<span id="cb4-23"><a href="#cb4-23" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php</span>
<span id="cb4-24"><a href="#cb4-24" aria-hidden="true"></a>}</span>
<span id="cb4-25"><a href="#cb4-25" aria-hidden="true"></a></span>
<span id="cb4-26"><a href="#cb4-26" aria-hidden="true"></a><span class="co">// Verify reCAPTCHA</span></span>
<span id="cb4-27"><a href="#cb4-27" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;authenticate&#39;</span><span class="ot">,</span> <span class="st">&#39;verify_recaptcha&#39;</span><span class="ot">,</span> <span class="dv">30</span><span class="ot">,</span> <span class="dv">3</span><span class="ot">);</span></span>
<span id="cb4-28"><a href="#cb4-28" aria-hidden="true"></a></span>
<span id="cb4-29"><a href="#cb4-29" aria-hidden="true"></a><span class="kw">function</span> verify_recaptcha<span class="ot">(</span><span class="kw">$user</span><span class="ot">,</span> <span class="kw">$username</span><span class="ot">,</span> <span class="kw">$password</span><span class="ot">)</span> {</span>
<span id="cb4-30"><a href="#cb4-30" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span><span class="kw">empty</span><span class="ot">(</span><span class="kw">$_POST</span><span class="ot">[</span><span class="st">&#39;g-recaptcha-response&#39;</span><span class="ot">]))</span> {</span>
<span id="cb4-31"><a href="#cb4-31" aria-hidden="true"></a>        <span class="kw">return</span> <span class="kw">new</span> WP_Error<span class="ot">(</span><span class="st">&#39;captcha_failed&#39;</span><span class="ot">,</span> <span class="st">&#39;Please complete the reCAPTCHA.&#39;</span><span class="ot">);</span></span>
<span id="cb4-32"><a href="#cb4-32" aria-hidden="true"></a>    }</span>
<span id="cb4-33"><a href="#cb4-33" aria-hidden="true"></a></span>
<span id="cb4-34"><a href="#cb4-34" aria-hidden="true"></a>    <span class="kw">$recaptcha</span> = <span class="kw">$_POST</span><span class="ot">[</span><span class="st">&#39;g-recaptcha-response&#39;</span><span class="ot">];</span></span>
<span id="cb4-35"><a href="#cb4-35" aria-hidden="true"></a>    <span class="kw">$secret_key</span> = <span class="st">&#39;YOUR_SECRET_KEY&#39;</span><span class="ot">;</span></span>
<span id="cb4-36"><a href="#cb4-36" aria-hidden="true"></a></span>
<span id="cb4-37"><a href="#cb4-37" aria-hidden="true"></a>    <span class="kw">$response</span> = wp_remote_post<span class="ot">(</span><span class="st">&#39;https://www.google.com/recaptcha/api/siteverify&#39;</span><span class="ot">,</span> <span class="ot">[</span></span>
<span id="cb4-38"><a href="#cb4-38" aria-hidden="true"></a>        <span class="st">&#39;body&#39;</span> =&gt; <span class="ot">[</span></span>
<span id="cb4-39"><a href="#cb4-39" aria-hidden="true"></a>            <span class="st">&#39;secret&#39;</span> =&gt; <span class="kw">$secret_key</span><span class="ot">,</span></span>
<span id="cb4-40"><a href="#cb4-40" aria-hidden="true"></a>            <span class="st">&#39;response&#39;</span> =&gt; <span class="kw">$recaptcha</span><span class="ot">,</span></span>
<span id="cb4-41"><a href="#cb4-41" aria-hidden="true"></a>            <span class="st">&#39;remoteip&#39;</span> =&gt; <span class="kw">$_SERVER</span><span class="ot">[</span><span class="st">&#39;REMOTE_ADDR&#39;</span><span class="ot">]</span></span>
<span id="cb4-42"><a href="#cb4-42" aria-hidden="true"></a>        <span class="ot">]</span></span>
<span id="cb4-43"><a href="#cb4-43" aria-hidden="true"></a>    <span class="ot">]);</span></span>
<span id="cb4-44"><a href="#cb4-44" aria-hidden="true"></a></span>
<span id="cb4-45"><a href="#cb4-45" aria-hidden="true"></a>    <span class="kw">$response_body</span> = <span class="fu">json_decode</span><span class="ot">(</span>wp_remote_retrieve_body<span class="ot">(</span><span class="kw">$response</span><span class="ot">));</span></span>
<span id="cb4-46"><a href="#cb4-46" aria-hidden="true"></a></span>
<span id="cb4-47"><a href="#cb4-47" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span>!<span class="kw">$response_body</span>-&gt;success || <span class="kw">$response_body</span>-&gt;score &lt; <span class="fl">0.5</span><span class="ot">)</span> {</span>
<span id="cb4-48"><a href="#cb4-48" aria-hidden="true"></a>        <span class="kw">return</span> <span class="kw">new</span> WP_Error<span class="ot">(</span><span class="st">&#39;captcha_failed&#39;</span><span class="ot">,</span> <span class="st">&#39;reCAPTCHA verification failed.&#39;</span><span class="ot">);</span></span>
<span id="cb4-49"><a href="#cb4-49" aria-hidden="true"></a>    }</span>
<span id="cb4-50"><a href="#cb4-50" aria-hidden="true"></a></span>
<span id="cb4-51"><a href="#cb4-51" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$user</span><span class="ot">;</span></span>
<span id="cb4-52"><a href="#cb4-52" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="layer-3-change-login-url">Layer 3: Change Login URL</h2>
<h3 id="using-wps-hide-login-plugin">Using WPS Hide Login Plugin</h3>
<div class="sourceCode" id="cb5">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true"></a><span class="ex">wp</span> plugin install wps-hide-login --activate</span></code></pre>
</div>
<p><strong>Settings:</strong> Change /wp-login.php to /my-secure-login</p>
<p><strong>Manual Method (via .htaccess):</strong></p>
<div class="sourceCode" id="cb6">
<pre class="sourceCode apache"><code class="sourceCode apache"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true"></a><span class="co"># Redirect wp-login.php to custom URL</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true"></a><span class="ex">RewriteEngine</span><span class="ch"> </span><span class="kw">On</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true"></a>RewriteCond<span class="st"> %{REQUEST_URI} ^/wp-login\.php</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true"></a>RewriteCond<span class="st"> %{QUERY_STRING} !^action=logout</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true"></a>RewriteCond<span class="st"> %{QUERY_STRING} !^action=rp</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true"></a>RewriteCond<span class="st"> %{QUERY_STRING} !^action=register</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true"></a>RewriteRule<span class="st"> ^(.*)$ /custom-login-url? [R=301,L]</span></span></code></pre>
</div>
<p><strong>Caution:</strong> Remember your custom URL. Losing it locks you out.</p>
<h2 id="layer-4-ip-whitelisting">Layer 4: IP Whitelisting</h2>
<h3 id="restrict-wp-admin-by-ip">Restrict wp-admin by IP</h3>
<div class="sourceCode" id="cb7">
<pre class="sourceCode apache"><code class="sourceCode apache"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true"></a><span class="co"># In wp-admin/.htaccess</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true"></a><span class="fu">&lt;Files</span><span class="at"> admin-ajax.php</span><span class="fu">&gt;</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true"></a>    <span class="ex">Order</span><span class="ch"> </span><span class="kw">allow,deny</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true"></a>    Allow<span class="st"> from all</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true"></a>    <span class="ex">Satisfy</span><span class="ch"> </span><span class="kw">any</span></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true"></a><span class="fu">&lt;/Files&gt;</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true"></a></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true"></a><span class="co"># Block all other wp-admin access except your IP</span></span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true"></a><span class="ex">Order</span><span class="ch"> </span><span class="kw">deny,allow</span></span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true"></a>Deny<span class="st"> from all</span></span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true"></a>Allow<span class="st"> from 123.456.789.0</span></span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true"></a>Allow<span class="st"> from 987.654.321.0</span></span></code></pre>
</div>
<p><strong>For Nginx:</strong></p>
<pre class="nginx"><code>location ~* /wp-admin/ {
    allow 123.456.789.0;
    deny all;
}</code></pre>
<p><strong>Dynamic IP Solution (for VPN/mobile users):</strong></p>
<div class="sourceCode" id="cb9">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true"></a><span class="co">// In functions.php - Email-based IP whitelisting</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;wp_login_failed&#39;</span><span class="ot">,</span> <span class="st">&#39;email_whitelist_request&#39;</span><span class="ot">);</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true"></a></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true"></a><span class="kw">function</span> email_whitelist_request<span class="ot">(</span><span class="kw">$username</span><span class="ot">)</span> {</span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true"></a>    <span class="kw">$ip</span> = <span class="kw">$_SERVER</span><span class="ot">[</span><span class="st">&#39;REMOTE_ADDR&#39;</span><span class="ot">];</span></span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true"></a>    <span class="kw">$whitelist</span> = get_option<span class="ot">(</span><span class="st">&#39;ip_whitelist&#39;</span><span class="ot">,</span> <span class="ot">[]);</span></span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true"></a></span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span>!<span class="fu">in_array</span><span class="ot">(</span><span class="kw">$ip</span><span class="ot">,</span> <span class="kw">$whitelist</span><span class="ot">))</span> {</span>
<span id="cb9-9"><a href="#cb9-9" aria-hidden="true"></a>        <span class="co">// Send email to admin with &quot;approve&quot; link</span></span>
<span id="cb9-10"><a href="#cb9-10" aria-hidden="true"></a>        <span class="kw">$approve_url</span> = admin_url<span class="ot">(</span><span class="st">&#39;admin.php?action=approve_ip&amp;ip=&#39;</span> . <span class="kw">$ip</span><span class="ot">);</span></span>
<span id="cb9-11"><a href="#cb9-11" aria-hidden="true"></a>        wp_mail<span class="ot">(</span></span>
<span id="cb9-12"><a href="#cb9-12" aria-hidden="true"></a>            get_option<span class="ot">(</span><span class="st">&#39;admin_email&#39;</span><span class="ot">),</span></span>
<span id="cb9-13"><a href="#cb9-13" aria-hidden="true"></a>            <span class="st">&#39;New IP Login Attempt&#39;</span><span class="ot">,</span></span>
<span id="cb9-14"><a href="#cb9-14" aria-hidden="true"></a>            <span class="st">&quot;Approve IP </span><span class="kw">$ip</span><span class="st">: </span><span class="kw">$approve_url</span><span class="st">&quot;</span></span>
<span id="cb9-15"><a href="#cb9-15" aria-hidden="true"></a>        <span class="ot">);</span></span>
<span id="cb9-16"><a href="#cb9-16" aria-hidden="true"></a>    }</span>
<span id="cb9-17"><a href="#cb9-17" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="layer-5-wordpress-firewall">Layer 5: WordPress Firewall</h2>
<h3 id="wordfence-configuration">Wordfence Configuration</h3>
<div class="sourceCode" id="cb10">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true"></a><span class="ex">wp</span> plugin install wordfence --activate</span></code></pre>
</div>
<p><strong>Essential Settings:</strong></p>
<ol type="1">
<li>
<p><strong>Enable Extended Protection</strong> (premium feature)</p>
</li>
<li>
<p><strong>Brute Force Protection:</strong></p>
<ul>
<li>Enable login page CAPTCHA</li>
<li>Immediately block invalid usernames</li>
<li>Lock out after 5 failed logins</li>
</ul>
</li>
<li>
<p><strong>Advanced Blocking:</strong></p>
<ul>
<li>Block attackers from specific countries</li>
<li>Throttle login attempts</li>
<li>Block known malicious IPs</li>
</ul>
</li>
</ol>
<p><strong>Rate Limiting Example:</strong></p>
<div class="sourceCode" id="cb11">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true"></a><span class="co">// Wordfence alternative - manual rate limiting</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;login_form&#39;</span><span class="ot">,</span> <span class="st">&#39;add_login_delay&#39;</span><span class="ot">);</span></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true"></a></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true"></a><span class="kw">function</span> add_login_delay<span class="ot">()</span> {</span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true"></a>    <span class="kw">$ip</span> = <span class="kw">$_SERVER</span><span class="ot">[</span><span class="st">&#39;REMOTE_ADDR&#39;</span><span class="ot">];</span></span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true"></a>    <span class="kw">$last_attempt</span> = get_transient<span class="ot">(</span><span class="st">&#39;last_login_attempt_&#39;</span> . <span class="kw">$ip</span><span class="ot">);</span></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true"></a></span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span><span class="kw">$last_attempt</span> &amp;&amp; <span class="ot">(</span><span class="fu">time</span><span class="ot">()</span> - <span class="kw">$last_attempt</span><span class="ot">)</span> &lt; <span class="dv">3</span><span class="ot">)</span> {</span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true"></a>        <span class="fu">sleep</span><span class="ot">(</span><span class="dv">3</span><span class="ot">);</span> <span class="co">// Force 3-second delay between attempts</span></span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true"></a>    }</span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true"></a></span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true"></a>    set_transient<span class="ot">(</span><span class="st">&#39;last_login_attempt_&#39;</span> . <span class="kw">$ip</span><span class="ot">,</span> <span class="fu">time</span><span class="ot">(),</span> <span class="kw">MINUTE_IN_SECONDS</span><span class="ot">);</span></span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="layer-6-cloudflare-protection">Layer 6: Cloudflare Protection</h2>
<h3 id="enable-cloudflare-firewall-rules">Enable Cloudflare Firewall Rules</h3>
<ol type="1">
<li>Sign up for Cloudflare (free plan works)</li>
<li>Add your domain</li>
<li>Update nameservers</li>
<li>Enable “Under Attack Mode” during active brute force</li>
</ol>
<p><strong>Firewall Rule:</strong></p>
<pre><code>(http.request.uri.path contains &quot;/wp-login.php&quot;) and
(not ip.geoip.country in {&quot;US&quot; &quot;CA&quot; &quot;GB&quot;})</code></pre>
<p><strong>This blocks non-US/CA/GB traffic to login page.</strong></p>
<h2 id="layer-7-two-factor-authentication">Layer 7: Two-Factor Authentication</h2>
<p>Combine 2FA with login limits for ultimate protection:</p>
<div class="sourceCode" id="cb13">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true"></a><span class="ex">wp</span> plugin install two-factor --activate</span></code></pre>
</div>
<p>Even if attackers guess passwords, they can’t login without the second factor.</p>
<h2 id="layer-8-disable-xml-rpc">Layer 8: Disable XML-RPC</h2>
<p>XML-RPC can be used for brute force attacks:</p>
<div class="sourceCode" id="cb14">
<pre class="sourceCode apache"><code class="sourceCode apache"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true"></a><span class="co"># In .htaccess</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true"></a><span class="fu">&lt;Files</span><span class="at"> xmlrpc.php</span><span class="fu">&gt;</span></span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true"></a>    <span class="ex">Order</span><span class="ch"> </span><span class="kw">deny,allow</span></span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true"></a>    Deny<span class="st"> from all</span></span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true"></a><span class="fu">&lt;/Files&gt;</span></span></code></pre>
</div>
<p><strong>Or via plugin code:</strong></p>
<div class="sourceCode" id="cb15">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true"></a><span class="co">// Completely disable XML-RPC</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;xmlrpc_enabled&#39;</span><span class="ot">,</span> <span class="st">&#39;__return_false&#39;</span><span class="ot">);</span></span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true"></a></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true"></a><span class="co">// Or disable only certain methods</span></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;xmlrpc_methods&#39;</span><span class="ot">,</span> <span class="st">&#39;disable_xmlrpc_methods&#39;</span><span class="ot">);</span></span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true"></a></span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true"></a><span class="kw">function</span> disable_xmlrpc_methods<span class="ot">(</span><span class="kw">$methods</span><span class="ot">)</span> {</span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true"></a>    <span class="kw">unset</span><span class="ot">(</span><span class="kw">$methods</span><span class="ot">[</span><span class="st">&#39;wp.getUsersBlogs&#39;</span><span class="ot">]);</span></span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true"></a>    <span class="kw">unset</span><span class="ot">(</span><span class="kw">$methods</span><span class="ot">[</span><span class="st">&#39;system.multicall&#39;</span><span class="ot">]);</span></span>
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true"></a>    <span class="kw">unset</span><span class="ot">(</span><span class="kw">$methods</span><span class="ot">[</span><span class="st">&#39;system.listMethods&#39;</span><span class="ot">]);</span></span>
<span id="cb15-11"><a href="#cb15-11" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$methods</span><span class="ot">;</span></span>
<span id="cb15-12"><a href="#cb15-12" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="layer-9-server-level-protection-fail2ban">Layer 9: Server-Level Protection (Fail2Ban)</h2>
<h3 id="configure-fail2ban-for-wordpress">Configure Fail2Ban for WordPress</h3>
<div class="sourceCode" id="cb16">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true"></a><span class="co"># Install Fail2Ban (Ubuntu/Debian)</span></span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true"></a><span class="fu">sudo</span> apt-get install fail2ban</span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true"></a></span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true"></a><span class="co"># Create WordPress filter</span></span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true"></a><span class="fu">sudo</span> nano /etc/fail2ban/filter.d/wordpress.conf</span></code></pre>
</div>
<p><strong>Filter Content:</strong></p>
<div class="sourceCode" id="cb17">
<pre class="sourceCode ini"><code class="sourceCode ini"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true"></a><span class="kw">[Definition]</span></span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true"></a><span class="dt">failregex </span><span class="ot">=</span><span class="st"> ^&lt;HOST&gt; .* &quot;POST /wp-login.php</span></span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true"></a><span class="dt">            ^&lt;HOST&gt; .* &quot;POST /xmlrpc.php</span></span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true"></a><span class="dt">ignoreregex </span><span class="ot">=</span></span></code></pre>
</div>
<p><strong>Jail Configuration:</strong></p>
<div class="sourceCode" id="cb18">
<pre class="sourceCode ini"><code class="sourceCode ini"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true"></a><span class="co"># In /etc/fail2ban/jail.local</span></span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true"></a><span class="kw">[wordpress]</span></span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true"></a><span class="dt">enabled </span><span class="ot">=</span><span class="st"> </span><span class="kw">true</span></span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true"></a><span class="dt">port </span><span class="ot">=</span><span class="st"> http,https</span></span>
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true"></a><span class="dt">filter </span><span class="ot">=</span><span class="st"> wordpress</span></span>
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true"></a><span class="dt">logpath </span><span class="ot">=</span><span class="st"> /var/log/apache2/access.log</span></span>
<span id="cb18-7"><a href="#cb18-7" aria-hidden="true"></a><span class="dt">maxretry </span><span class="ot">=</span><span class="st"> </span><span class="dv">5</span></span>
<span id="cb18-8"><a href="#cb18-8" aria-hidden="true"></a><span class="dt">bantime </span><span class="ot">=</span><span class="st"> </span><span class="dv">3600</span></span>
<span id="cb18-9"><a href="#cb18-9" aria-hidden="true"></a><span class="dt">findtime </span><span class="ot">=</span><span class="st"> </span><span class="dv">600</span></span></code></pre>
</div>
<p>Restart Fail2Ban:</p>
<div class="sourceCode" id="cb19">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true"></a><span class="fu">sudo</span> systemctl restart fail2ban</span></code></pre>
</div>
<h2 id="monitoring-and-alerts">Monitoring and Alerts</h2>
<h3 id="email-notifications">Email Notifications</h3>
<div class="sourceCode" id="cb20">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true"></a><span class="co">// Email admin on failed logins</span></span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;wp_login_failed&#39;</span><span class="ot">,</span> <span class="st">&#39;notify_failed_login&#39;</span><span class="ot">);</span></span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true"></a></span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true"></a><span class="kw">function</span> notify_failed_login<span class="ot">(</span><span class="kw">$username</span><span class="ot">)</span> {</span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true"></a>    <span class="kw">$ip</span> = <span class="kw">$_SERVER</span><span class="ot">[</span><span class="st">&#39;REMOTE_ADDR&#39;</span><span class="ot">];</span></span>
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true"></a>    <span class="kw">$time</span> = current_time<span class="ot">(</span><span class="st">&#39;mysql&#39;</span><span class="ot">);</span></span>
<span id="cb20-7"><a href="#cb20-7" aria-hidden="true"></a></span>
<span id="cb20-8"><a href="#cb20-8" aria-hidden="true"></a>    wp_mail<span class="ot">(</span></span>
<span id="cb20-9"><a href="#cb20-9" aria-hidden="true"></a>        get_option<span class="ot">(</span><span class="st">&#39;admin_email&#39;</span><span class="ot">),</span></span>
<span id="cb20-10"><a href="#cb20-10" aria-hidden="true"></a>        <span class="st">&#39;Failed Login Attempt&#39;</span><span class="ot">,</span></span>
<span id="cb20-11"><a href="#cb20-11" aria-hidden="true"></a>        <span class="st">&quot;Failed login for username: </span><span class="kw">$username\n</span><span class="st">IP: </span><span class="kw">$ip\n</span><span class="st">Time: </span><span class="kw">$time</span><span class="st">&quot;</span></span>
<span id="cb20-12"><a href="#cb20-12" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb20-13"><a href="#cb20-13" aria-hidden="true"></a>}</span></code></pre>
</div>
<h3 id="log-analysis">Log Analysis</h3>
<div class="sourceCode" id="cb21">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true"></a><span class="co"># View recent failed logins (Apache)</span></span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true"></a><span class="fu">grep</span> <span class="st">&quot;wp-login.php&quot;</span> /var/log/apache2/access.log <span class="kw">|</span> <span class="fu">grep</span> <span class="st">&quot;POST&quot;</span> <span class="kw">|</span> <span class="fu">tail</span> -50</span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true"></a></span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true"></a><span class="co"># Count attempts by IP</span></span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true"></a><span class="fu">awk</span> <span class="st">&#39;{print $1}&#39;</span> /var/log/apache2/access.log <span class="kw">|</span> <span class="fu">grep</span> -v <span class="st">&quot;^$&quot;</span> <span class="kw">|</span> <span class="fu">sort</span> <span class="kw">|</span> <span class="fu">uniq</span> -c <span class="kw">|</span> <span class="fu">sort</span> -rn <span class="kw">|</span> <span class="fu">head</span> -20</span></code></pre>
</div>
<h2 id="testing-your-protection">Testing Your Protection</h2>
<h3 id="safe-simulation">Safe Simulation</h3>
<ol type="1">
<li>Use incognito browser</li>
<li>Attempt 5-6 failed logins</li>
<li>Verify lockout occurs</li>
<li>Check email notifications</li>
<li>Confirm CAPTCHA appears (if configured)</li>
<li>Test IP whitelist (from different IP)</li>
</ol>
<p><strong>Automated Test:</strong></p>
<div class="sourceCode" id="cb22">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true"></a><span class="co"># Test with curl (safely)</span></span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true"></a><span class="kw">for</span> <span class="ex">i</span> in <span class="dt">{1..6}</span><span class="kw">;</span> <span class="kw">do</span></span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true"></a>    <span class="ex">curl</span> -X POST https://yoursite.com/wp-login.php <span class="kw">\</span></span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true"></a>    <span class="ex">-d</span> <span class="st">&quot;log=testuser&amp;pwd=wrongpassword&quot;</span></span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true"></a>    <span class="fu">sleep</span> 2</span>
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true"></a><span class="kw">done</span></span></code></pre>
</div>
<h2 id="best-practices-summary">Best Practices Summary</h2>
<p>✅ <strong>Do:</strong></p>
<ul>
<li>Limit login attempts (4-5 max)</li>
<li>Add CAPTCHA protection</li>
<li>Use strong, unique passwords</li>
<li>Enable 2FA for all admins</li>
<li>Monitor failed login logs</li>
<li>Update security plugins regularly</li>
</ul>
<p>❌ <strong>Don’t:</strong></p>
<ul>
<li>Use “admin” as username</li>
<li>Allow unlimited login attempts</li>
<li>Ignore failed login notifications</li>
<li>Use same password across accounts</li>
<li>Disable security features for convenience</li>
</ul>
<h2 id="complete-protection-stack">Complete Protection Stack</h2>
<p><strong>Recommended combination:</strong></p>
<ol type="1">
<li><strong>Strong passwords</strong> (20+ characters)</li>
<li><strong>Limit Login Attempts Reloaded</strong> (free)</li>
<li><strong>Google reCAPTCHA v3</strong> (free)</li>
<li><strong>Wordfence</strong> or <strong>Sucuri</strong> (free/premium)</li>
<li><strong>Two-Factor Authentication</strong> (free)</li>
<li><strong>Cloudflare</strong> (free tier sufficient)</li>
<li><strong>Fail2Ban</strong> (server-level, free)</li>
</ol>
<p>This multi-layered approach stops 99.9% of brute force attacks while maintaining usability for legitimate users.</p>
<p>Brute force attacks are preventable. By implementing these protective layers, you transform WordPress login from a vulnerable entry point into a hardened fortress. Start with basic login limits and CAPTCHA, then add additional layers based on your threat level and resources.</p>
<h2 id="external-links">External Links</h2>
<ol type="1">
<li><a href="https://wordpress.org/plugins/limit-login-attempts-reloaded/">Limit Login Attempts Reloaded</a></li>
<li><a href="https://www.google.com/recaptcha/">Google reCAPTCHA</a></li>
<li><a href="https://wordpress.org/plugins/wordfence/">Wordfence Security</a></li>
<li><a href="https://www.cloudflare.com/">Cloudflare</a></li>
<li><a href="https://www.fail2ban.org/">Fail2Ban</a></li>
</ol>
<h2 id="call-to-action">Call to Action</h2>
<p>Secure your site with bulletproof backups! <a href="https://backupcopilotplugin.com/">Backup Copilot Pro</a> offers automated security audits, malware scanning before backups, and instant recovery—try it free!</p>
<p>The post <a href="https://developryplugins.com/how-to-block-brute-force-attacks-on-wordpress-login-pages/">How to Block Brute Force Attacks on WordPress Login Pages</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Build Dynamic Blocks with WordPress Block Editor</title>
		<link>https://developryplugins.com/how-to-build-dynamic-blocks-with-wordpress-block-editor/</link>
		
		<dc:creator><![CDATA[Krasen Slavov]]></dc:creator>
		<pubDate>Wed, 05 Aug 2026 09:00:00 +0000</pubDate>
				<category><![CDATA[Block Editor & Gutenberg Tutorials]]></category>
		<category><![CDATA[dynamic blocks]]></category>
		<category><![CDATA[gutenberg development]]></category>
		<category><![CDATA[php rendering]]></category>
		<category><![CDATA[server-side rendering]]></category>
		<category><![CDATA[wordpress blocks]]></category>
		<guid isPermaLink="false">https://developryplugins.com/?p=131</guid>

					<description><![CDATA[<p>Dynamic blocks represent a powerful evolution in WordPress block development, enabling server-side rendering that displays real-time data, database queries, and user-specific content. This guide teaches you to build dynamic blocks...</p>
<p>The post <a href="https://developryplugins.com/how-to-build-dynamic-blocks-with-wordpress-block-editor/">How to Build Dynamic Blocks with WordPress Block Editor</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><!-- @format --></p>
<p>Dynamic blocks represent a powerful evolution in WordPress block development, enabling server-side rendering that displays real-time data, database queries, and user-specific content. This guide teaches you to build dynamic blocks that combine the flexibility of Gutenberg with the power of PHP.</p>
<h2 id="static-vs-dynamic-blocks">Static vs Dynamic Blocks</h2>
<p>Understanding the difference between static and dynamic blocks is fundamental.</p>
<p><strong>Static blocks</strong> save their content directly to the database as HTML. When you create a paragraph block, WordPress stores the exact HTML in post_content. This is efficient for content that doesn’t change.</p>
<p><strong>Dynamic blocks</strong> save only their attributes to the database. Each time the page loads, WordPress executes a PHP render callback that generates the HTML. This enables real-time data like “latest posts,” user-specific content, and database queries.</p>
<p>Use static blocks for fixed content. Use dynamic blocks when content must update automatically based on data changes, user context, or external sources.</p>
<h2 id="when-to-use-dynamic-blocks">When to Use Dynamic Blocks</h2>
<p>Dynamic blocks excel in specific scenarios:</p>
<ul>
<li><strong>Latest content displays</strong> &#8211; Showing recent posts, comments, or custom post types</li>
<li><strong>User-specific content</strong> &#8211; Displaying personalized data based on logged-in users</li>
<li><strong>External data</strong> &#8211; Fetching and displaying API data, weather, stock prices</li>
<li><strong>Database queries</strong> &#8211; Running complex WP_Query operations</li>
<li><strong>Real-time calculations</strong> &#8211; Computing values based on current data</li>
</ul>
<p>Avoid dynamic blocks for purely presentational content that never changes. The server-side rendering adds processing overhead unnecessary for static content.</p>
<h2 id="creating-your-first-dynamic-block">Creating Your First Dynamic Block</h2>
<p>Start with block.json to define your block:</p>
<div class="sourceCode" id="cb1">
<pre class="sourceCode json"><code class="sourceCode json"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true"></a><span class="fu">{</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true"></a>    <span class="dt">&quot;apiVersion&quot;</span><span class="fu">:</span> <span class="dv">3</span><span class="fu">,</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true"></a>    <span class="dt">&quot;name&quot;</span><span class="fu">:</span> <span class="st">&quot;dprt/recent-posts&quot;</span><span class="fu">,</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true"></a>    <span class="dt">&quot;title&quot;</span><span class="fu">:</span> <span class="st">&quot;Recent Posts&quot;</span><span class="fu">,</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true"></a>    <span class="dt">&quot;category&quot;</span><span class="fu">:</span> <span class="st">&quot;widgets&quot;</span><span class="fu">,</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true"></a>    <span class="dt">&quot;icon&quot;</span><span class="fu">:</span> <span class="st">&quot;list-view&quot;</span><span class="fu">,</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true"></a>    <span class="dt">&quot;description&quot;</span><span class="fu">:</span> <span class="st">&quot;Display recent posts dynamically&quot;</span><span class="fu">,</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true"></a>    <span class="dt">&quot;attributes&quot;</span><span class="fu">:</span> <span class="fu">{</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true"></a>        <span class="dt">&quot;numberOfPosts&quot;</span><span class="fu">:</span> <span class="fu">{</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true"></a>            <span class="dt">&quot;type&quot;</span><span class="fu">:</span> <span class="st">&quot;number&quot;</span><span class="fu">,</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true"></a>            <span class="dt">&quot;default&quot;</span><span class="fu">:</span> <span class="dv">5</span></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true"></a>        <span class="fu">},</span></span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true"></a>        <span class="dt">&quot;postType&quot;</span><span class="fu">:</span> <span class="fu">{</span></span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true"></a>            <span class="dt">&quot;type&quot;</span><span class="fu">:</span> <span class="st">&quot;string&quot;</span><span class="fu">,</span></span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true"></a>            <span class="dt">&quot;default&quot;</span><span class="fu">:</span> <span class="st">&quot;post&quot;</span></span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true"></a>        <span class="fu">}</span></span>
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true"></a>    <span class="fu">},</span></span>
<span id="cb1-18"><a href="#cb1-18" aria-hidden="true"></a>    <span class="dt">&quot;editorScript&quot;</span><span class="fu">:</span> <span class="st">&quot;file:./index.js&quot;</span><span class="fu">,</span></span>
<span id="cb1-19"><a href="#cb1-19" aria-hidden="true"></a>    <span class="dt">&quot;editorStyle&quot;</span><span class="fu">:</span> <span class="st">&quot;file:./editor.css&quot;</span><span class="fu">,</span></span>
<span id="cb1-20"><a href="#cb1-20" aria-hidden="true"></a>    <span class="dt">&quot;style&quot;</span><span class="fu">:</span> <span class="st">&quot;file:./style.css&quot;</span></span>
<span id="cb1-21"><a href="#cb1-21" aria-hidden="true"></a><span class="fu">}</span></span></code></pre>
</div>
<p>Register the block with a render callback:</p>
<div class="sourceCode" id="cb2">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true"></a><span class="kw">function</span> dprt_register_recent_posts_block<span class="ot">()</span> {</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true"></a>    register_block_type<span class="ot">(</span> <span class="kw">__DIR__</span> . <span class="st">&#39;/build/blocks/recent-posts&#39;</span><span class="ot">,</span> <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true"></a>        <span class="st">&#39;render_callback&#39;</span> =&gt; <span class="st">&#39;dprt_render_recent_posts_block&#39;</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true"></a>    <span class="ot">)</span> <span class="ot">);</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true"></a>}</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true"></a>add_action<span class="ot">(</span> <span class="st">&#39;init&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_register_recent_posts_block&#39;</span> <span class="ot">);</span></span></code></pre>
</div>
<h2 id="implementing-the-render-callback">Implementing the Render Callback</h2>
<p>The render callback function generates your block’s HTML:</p>
<div class="sourceCode" id="cb3">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true"></a><span class="kw">function</span> dprt_render_recent_posts_block<span class="ot">(</span> <span class="kw">$attributes</span><span class="ot">,</span> <span class="kw">$content</span><span class="ot">,</span> <span class="kw">$block</span> <span class="ot">)</span> {</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true"></a>    <span class="kw">$number_of_posts</span> = <span class="kw">isset</span><span class="ot">(</span> <span class="kw">$attributes</span><span class="ot">[</span><span class="st">&#39;numberOfPosts&#39;</span><span class="ot">]</span> <span class="ot">)</span> <span class="ot">?</span> absint<span class="ot">(</span> <span class="kw">$attributes</span><span class="ot">[</span><span class="st">&#39;numberOfPosts&#39;</span><span class="ot">]</span> <span class="ot">)</span> <span class="ot">:</span> <span class="dv">5</span><span class="ot">;</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true"></a>    <span class="kw">$post_type</span> = <span class="kw">isset</span><span class="ot">(</span> <span class="kw">$attributes</span><span class="ot">[</span><span class="st">&#39;postType&#39;</span><span class="ot">]</span> <span class="ot">)</span> <span class="ot">?</span> sanitize_text_field<span class="ot">(</span> <span class="kw">$attributes</span><span class="ot">[</span><span class="st">&#39;postType&#39;</span><span class="ot">]</span> <span class="ot">)</span> <span class="ot">:</span> <span class="st">&#39;post&#39;</span><span class="ot">;</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true"></a></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true"></a>    <span class="kw">$args</span> = <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true"></a>        <span class="st">&#39;post_type&#39;</span> =&gt; <span class="kw">$post_type</span><span class="ot">,</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true"></a>        <span class="st">&#39;posts_per_page&#39;</span> =&gt; <span class="kw">$number_of_posts</span><span class="ot">,</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true"></a>        <span class="st">&#39;post_status&#39;</span> =&gt; <span class="st">&#39;publish&#39;</span><span class="ot">,</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true"></a>        <span class="st">&#39;orderby&#39;</span> =&gt; <span class="st">&#39;date&#39;</span><span class="ot">,</span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true"></a>        <span class="st">&#39;order&#39;</span> =&gt; <span class="st">&#39;DESC&#39;</span></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true"></a></span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true"></a>    <span class="kw">$query</span> = <span class="kw">new</span> WP_Query<span class="ot">(</span> <span class="kw">$args</span> <span class="ot">);</span></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true"></a></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span> ! <span class="kw">$query</span>-&gt;have_posts<span class="ot">()</span> <span class="ot">)</span> {</span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true"></a>        <span class="kw">return</span> <span class="st">&#39;&lt;p&gt;&#39;</span> . esc_html__<span class="ot">(</span> <span class="st">&#39;No posts found.&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt&#39;</span> <span class="ot">)</span> . <span class="st">&#39;&lt;/p&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true"></a>    }</span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true"></a></span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true"></a>    <span class="kw">$output</span> = <span class="st">&#39;&lt;div class=&quot;wp-block-dprt-recent-posts&quot;&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true"></a>    <span class="kw">$output</span> .= <span class="st">&#39;&lt;ul&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true"></a></span>
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true"></a>    <span class="kw">while</span> <span class="ot">(</span> <span class="kw">$query</span>-&gt;have_posts<span class="ot">()</span> <span class="ot">)</span> {</span>
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true"></a>        <span class="kw">$query</span>-&gt;the_post<span class="ot">();</span></span>
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true"></a>        <span class="kw">$output</span> .= <span class="st">&#39;&lt;li&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true"></a>        <span class="kw">$output</span> .= <span class="st">&#39;&lt;a href=&quot;&#39;</span> . esc_url<span class="ot">(</span> get_permalink<span class="ot">()</span> <span class="ot">)</span> . <span class="st">&#39;&quot;&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true"></a>        <span class="kw">$output</span> .= esc_html<span class="ot">(</span> get_the_title<span class="ot">()</span> <span class="ot">);</span></span>
<span id="cb3-27"><a href="#cb3-27" aria-hidden="true"></a>        <span class="kw">$output</span> .= <span class="st">&#39;&lt;/a&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-28"><a href="#cb3-28" aria-hidden="true"></a>        <span class="kw">$output</span> .= <span class="st">&#39;&lt;span class=&quot;post-date&quot;&gt; - &#39;</span> . esc_html<span class="ot">(</span> get_the_date<span class="ot">()</span> <span class="ot">)</span> . <span class="st">&#39;&lt;/span&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-29"><a href="#cb3-29" aria-hidden="true"></a>        <span class="kw">$output</span> .= <span class="st">&#39;&lt;/li&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-30"><a href="#cb3-30" aria-hidden="true"></a>    }</span>
<span id="cb3-31"><a href="#cb3-31" aria-hidden="true"></a></span>
<span id="cb3-32"><a href="#cb3-32" aria-hidden="true"></a>    <span class="kw">$output</span> .= <span class="st">&#39;&lt;/ul&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-33"><a href="#cb3-33" aria-hidden="true"></a>    <span class="kw">$output</span> .= <span class="st">&#39;&lt;/div&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-34"><a href="#cb3-34" aria-hidden="true"></a></span>
<span id="cb3-35"><a href="#cb3-35" aria-hidden="true"></a>    wp_reset_postdata<span class="ot">();</span></span>
<span id="cb3-36"><a href="#cb3-36" aria-hidden="true"></a></span>
<span id="cb3-37"><a href="#cb3-37" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$output</span><span class="ot">;</span></span>
<span id="cb3-38"><a href="#cb3-38" aria-hidden="true"></a>}</span></code></pre>
</div>
<p>Always sanitize attributes and escape output to prevent security vulnerabilities.</p>
<h2 id="editor-controls-and-preview">Editor Controls and Preview</h2>
<p>Create InspectorControls for block settings:</p>
<div class="sourceCode" id="cb4">
<pre class="sourceCode javascript"><code class="sourceCode javascript"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true"></a><span class="im">import</span> { useBlockProps<span class="op">,</span> InspectorControls } <span class="im">from</span> <span class="st">&quot;@wordpress/block-editor&quot;</span><span class="op">;</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true"></a><span class="im">import</span> { PanelBody<span class="op">,</span> RangeControl<span class="op">,</span> SelectControl } <span class="im">from</span> <span class="st">&quot;@wordpress/components&quot;</span><span class="op">;</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true"></a><span class="im">import</span> ServerSideRender <span class="im">from</span> <span class="st">&quot;@wordpress/server-side-render&quot;</span><span class="op">;</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true"></a></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true"></a><span class="im">export</span> <span class="im">default</span> <span class="kw">function</span> <span class="fu">Edit</span>({ attributes<span class="op">,</span> setAttributes }) {</span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true"></a>    <span class="kw">const</span> { numberOfPosts<span class="op">,</span> postType } <span class="op">=</span> attributes<span class="op">;</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true"></a></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true"></a>    <span class="cf">return</span> (</span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true"></a>        <span class="op">&lt;&gt;</span></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true"></a>            <span class="op">&lt;</span>InspectorControls<span class="op">&gt;</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true"></a>                <span class="op">&lt;</span>PanelBody title<span class="op">=</span><span class="st">&quot;Settings&quot;</span><span class="op">&gt;</span></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true"></a>                    <span class="op">&lt;</span>RangeControl</span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true"></a>                        label<span class="op">=</span><span class="st">&quot;Number of posts&quot;</span></span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true"></a>                        value<span class="op">=</span>{numberOfPosts}</span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true"></a>                        onChange<span class="op">=</span>{(value) <span class="kw">=&gt;</span> <span class="fu">setAttributes</span>({ <span class="dt">numberOfPosts</span><span class="op">:</span> value })}</span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true"></a>                        min<span class="op">=</span>{<span class="dv">1</span>}</span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true"></a>                        max<span class="op">=</span>{<span class="dv">20</span>}</span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true"></a>                    <span class="op">/&gt;</span></span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true"></a>                    <span class="op">&lt;</span>SelectControl</span>
<span id="cb4-20"><a href="#cb4-20" aria-hidden="true"></a>                        label<span class="op">=</span><span class="st">&quot;Post Type&quot;</span></span>
<span id="cb4-21"><a href="#cb4-21" aria-hidden="true"></a>                        value<span class="op">=</span>{postType}</span>
<span id="cb4-22"><a href="#cb4-22" aria-hidden="true"></a>                        options<span class="op">=</span>{[</span>
<span id="cb4-23"><a href="#cb4-23" aria-hidden="true"></a>                            { <span class="dt">label</span><span class="op">:</span> <span class="st">&quot;Posts&quot;</span><span class="op">,</span> <span class="dt">value</span><span class="op">:</span> <span class="st">&quot;post&quot;</span> }<span class="op">,</span></span>
<span id="cb4-24"><a href="#cb4-24" aria-hidden="true"></a>                            { <span class="dt">label</span><span class="op">:</span> <span class="st">&quot;Pages&quot;</span><span class="op">,</span> <span class="dt">value</span><span class="op">:</span> <span class="st">&quot;page&quot;</span> }</span>
<span id="cb4-25"><a href="#cb4-25" aria-hidden="true"></a>                        ]}</span>
<span id="cb4-26"><a href="#cb4-26" aria-hidden="true"></a>                        onChange<span class="op">=</span>{(value) <span class="kw">=&gt;</span> <span class="fu">setAttributes</span>({ <span class="dt">postType</span><span class="op">:</span> value })}</span>
<span id="cb4-27"><a href="#cb4-27" aria-hidden="true"></a>                    <span class="op">/&gt;</span></span>
<span id="cb4-28"><a href="#cb4-28" aria-hidden="true"></a>                <span class="op">&lt;/</span>PanelBody<span class="op">&gt;</span></span>
<span id="cb4-29"><a href="#cb4-29" aria-hidden="true"></a>            <span class="op">&lt;/</span>InspectorControls<span class="op">&gt;</span></span>
<span id="cb4-30"><a href="#cb4-30" aria-hidden="true"></a>            <span class="op">&lt;</span>div {<span class="op">...</span><span class="fu">useBlockProps</span>()}<span class="op">&gt;</span></span>
<span id="cb4-31"><a href="#cb4-31" aria-hidden="true"></a>                <span class="op">&lt;</span>ServerSideRender block<span class="op">=</span><span class="st">&quot;dprt/recent-posts&quot;</span> attributes<span class="op">=</span>{attributes} <span class="op">/&gt;</span></span>
<span id="cb4-32"><a href="#cb4-32" aria-hidden="true"></a>            <span class="op">&lt;/</span>div<span class="op">&gt;</span></span>
<span id="cb4-33"><a href="#cb4-33" aria-hidden="true"></a>        <span class="op">&lt;/&gt;</span></span>
<span id="cb4-34"><a href="#cb4-34" aria-hidden="true"></a>    )<span class="op">;</span></span>
<span id="cb4-35"><a href="#cb4-35" aria-hidden="true"></a>}</span></code></pre>
</div>
<p>ServerSideRender displays a live preview in the editor by calling your render callback via AJAX.</p>
<h2 id="performance-optimization-with-caching">Performance Optimization with Caching</h2>
<p>Dynamic blocks can impact performance. Implement caching for expensive operations:</p>
<div class="sourceCode" id="cb5">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true"></a><span class="kw">function</span> dprt_render_recent_posts_block<span class="ot">(</span> <span class="kw">$attributes</span><span class="ot">,</span> <span class="kw">$content</span><span class="ot">,</span> <span class="kw">$block</span> <span class="ot">)</span> {</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true"></a>    <span class="kw">$number_of_posts</span> = <span class="kw">isset</span><span class="ot">(</span> <span class="kw">$attributes</span><span class="ot">[</span><span class="st">&#39;numberOfPosts&#39;</span><span class="ot">]</span> <span class="ot">)</span> <span class="ot">?</span> absint<span class="ot">(</span> <span class="kw">$attributes</span><span class="ot">[</span><span class="st">&#39;numberOfPosts&#39;</span><span class="ot">]</span> <span class="ot">)</span> <span class="ot">:</span> <span class="dv">5</span><span class="ot">;</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true"></a></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true"></a>    <span class="co">// Create unique cache key based on attributes</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true"></a>    <span class="kw">$cache_key</span> = <span class="st">&#39;dprt_recent_posts_&#39;</span> . <span class="fu">md5</span><span class="ot">(</span> <span class="fu">serialize</span><span class="ot">(</span> <span class="kw">$attributes</span> <span class="ot">)</span> <span class="ot">);</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true"></a></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true"></a>    <span class="co">// Try to get cached result</span></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true"></a>    <span class="kw">$cached</span> = get_transient<span class="ot">(</span> <span class="kw">$cache_key</span> <span class="ot">);</span></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span> <span class="kw">false</span> !== <span class="kw">$cached</span> <span class="ot">)</span> {</span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true"></a>        <span class="kw">return</span> <span class="kw">$cached</span><span class="ot">;</span></span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true"></a>    }</span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true"></a></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true"></a>    <span class="co">// Generate output (expensive operation)</span></span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true"></a>    <span class="kw">$output</span> = dprt_generate_recent_posts_html<span class="ot">(</span> <span class="kw">$number_of_posts</span> <span class="ot">);</span></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true"></a></span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true"></a>    <span class="co">// Cache for 1 hour</span></span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true"></a>    set_transient<span class="ot">(</span> <span class="kw">$cache_key</span><span class="ot">,</span> <span class="kw">$output</span><span class="ot">,</span> <span class="kw">HOUR_IN_SECONDS</span> <span class="ot">);</span></span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true"></a></span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$output</span><span class="ot">;</span></span>
<span id="cb5-20"><a href="#cb5-20" aria-hidden="true"></a>}</span></code></pre>
</div>
<p>Clear the cache when content updates:</p>
<div class="sourceCode" id="cb6">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true"></a><span class="kw">function</span> dprt_clear_recent_posts_cache<span class="ot">(</span> <span class="kw">$post_id</span> <span class="ot">)</span> {</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true"></a>    <span class="co">// Clear all recent posts caches</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true"></a>    <span class="kw">global</span> <span class="kw">$wpdb</span><span class="ot">;</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true"></a>    <span class="kw">$wpdb</span>-&gt;query<span class="ot">(</span> <span class="st">&quot;DELETE FROM </span><span class="kw">{$wpdb-&gt;options}</span><span class="st"> WHERE option_name LIKE &#39;_transient_dprt_recent_posts_%&#39;&quot;</span> <span class="ot">);</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true"></a>}</span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true"></a>add_action<span class="ot">(</span> <span class="st">&#39;save_post&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_clear_recent_posts_cache&#39;</span> <span class="ot">);</span></span></code></pre>
</div>
<h2 id="user-specific-content">User-Specific Content</h2>
<p>Display personalized content based on the logged-in user:</p>
<div class="sourceCode" id="cb7">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true"></a><span class="kw">function</span> dprt_render_user_dashboard_block<span class="ot">(</span> <span class="kw">$attributes</span><span class="ot">,</span> <span class="kw">$content</span><span class="ot">,</span> <span class="kw">$block</span> <span class="ot">)</span> {</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span> ! is_user_logged_in<span class="ot">()</span> <span class="ot">)</span> {</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true"></a>        <span class="kw">return</span> <span class="st">&#39;&lt;p&gt;&#39;</span> . esc_html__<span class="ot">(</span> <span class="st">&#39;Please log in to view your dashboard.&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt&#39;</span> <span class="ot">)</span> . <span class="st">&#39;&lt;/p&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true"></a>    }</span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true"></a></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true"></a>    <span class="kw">$current_user</span> = wp_get_current_user<span class="ot">();</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true"></a>    <span class="kw">$user_posts</span> = count_user_posts<span class="ot">(</span> <span class="kw">$current_user</span>-&gt;<span class="kw">ID</span> <span class="ot">);</span></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true"></a></span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true"></a>    <span class="kw">$output</span> = <span class="st">&#39;&lt;div class=&quot;user-dashboard&quot;&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true"></a>    <span class="kw">$output</span> .= <span class="st">&#39;&lt;h3&gt;&#39;</span> . <span class="fu">sprintf</span><span class="ot">(</span> esc_html__<span class="ot">(</span> <span class="st">&#39;Welcome, %s&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt&#39;</span> <span class="ot">),</span> esc_html<span class="ot">(</span> <span class="kw">$current_user</span>-&gt;display_name <span class="ot">)</span> <span class="ot">)</span> . <span class="st">&#39;&lt;/h3&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true"></a>    <span class="kw">$output</span> .= <span class="st">&#39;&lt;p&gt;&#39;</span> . <span class="fu">sprintf</span><span class="ot">(</span> esc_html__<span class="ot">(</span> <span class="st">&#39;You have published %d posts.&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt&#39;</span> <span class="ot">),</span> <span class="kw">$user_posts</span> <span class="ot">)</span> . <span class="st">&#39;&lt;/p&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true"></a>    <span class="kw">$output</span> .= <span class="st">&#39;&lt;/div&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true"></a></span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$output</span><span class="ot">;</span></span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="external-api-integration">External API Integration</h2>
<p>Fetch and display external data:</p>
<div class="sourceCode" id="cb8">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true"></a><span class="kw">function</span> dprt_render_weather_block<span class="ot">(</span> <span class="kw">$attributes</span><span class="ot">,</span> <span class="kw">$content</span><span class="ot">,</span> <span class="kw">$block</span> <span class="ot">)</span> {</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true"></a>    <span class="kw">$city</span> = <span class="kw">isset</span><span class="ot">(</span> <span class="kw">$attributes</span><span class="ot">[</span><span class="st">&#39;city&#39;</span><span class="ot">]</span> <span class="ot">)</span> <span class="ot">?</span> sanitize_text_field<span class="ot">(</span> <span class="kw">$attributes</span><span class="ot">[</span><span class="st">&#39;city&#39;</span><span class="ot">]</span> <span class="ot">)</span> <span class="ot">:</span> <span class="st">&#39;London&#39;</span><span class="ot">;</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true"></a>    <span class="kw">$cache_key</span> = <span class="st">&#39;dprt_weather_&#39;</span> . sanitize_title<span class="ot">(</span> <span class="kw">$city</span> <span class="ot">);</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true"></a></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true"></a>    <span class="kw">$weather_data</span> = get_transient<span class="ot">(</span> <span class="kw">$cache_key</span> <span class="ot">);</span></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true"></a></span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span> <span class="kw">false</span> === <span class="kw">$weather_data</span> <span class="ot">)</span> {</span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true"></a>        <span class="kw">$api_url</span> = <span class="st">&#39;https://api.weatherapi.com/v1/current.json?key=YOUR_KEY&amp;q=&#39;</span> . <span class="fu">urlencode</span><span class="ot">(</span> <span class="kw">$city</span> <span class="ot">);</span></span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true"></a>        <span class="kw">$response</span> = wp_remote_get<span class="ot">(</span> <span class="kw">$api_url</span> <span class="ot">);</span></span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true"></a></span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true"></a>        <span class="kw">if</span> <span class="ot">(</span> is_wp_error<span class="ot">(</span> <span class="kw">$response</span> <span class="ot">)</span> <span class="ot">)</span> {</span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true"></a>            <span class="kw">return</span> <span class="st">&#39;&lt;p&gt;&#39;</span> . esc_html__<span class="ot">(</span> <span class="st">&#39;Unable to fetch weather data.&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt&#39;</span> <span class="ot">)</span> . <span class="st">&#39;&lt;/p&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true"></a>        }</span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true"></a></span>
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true"></a>        <span class="kw">$weather_data</span> = <span class="fu">json_decode</span><span class="ot">(</span> wp_remote_retrieve_body<span class="ot">(</span> <span class="kw">$response</span> <span class="ot">),</span> <span class="kw">true</span> <span class="ot">);</span></span>
<span id="cb8-16"><a href="#cb8-16" aria-hidden="true"></a>        set_transient<span class="ot">(</span> <span class="kw">$cache_key</span><span class="ot">,</span> <span class="kw">$weather_data</span><span class="ot">,</span> <span class="dv">30</span> * <span class="kw">MINUTE_IN_SECONDS</span> <span class="ot">);</span></span>
<span id="cb8-17"><a href="#cb8-17" aria-hidden="true"></a>    }</span>
<span id="cb8-18"><a href="#cb8-18" aria-hidden="true"></a></span>
<span id="cb8-19"><a href="#cb8-19" aria-hidden="true"></a>    <span class="kw">$temp</span> = <span class="kw">isset</span><span class="ot">(</span> <span class="kw">$weather_data</span><span class="ot">[</span><span class="st">&#39;current&#39;</span><span class="ot">][</span><span class="st">&#39;temp_c&#39;</span><span class="ot">]</span> <span class="ot">)</span> <span class="ot">?</span> <span class="kw">$weather_data</span><span class="ot">[</span><span class="st">&#39;current&#39;</span><span class="ot">][</span><span class="st">&#39;temp_c&#39;</span><span class="ot">]</span> <span class="ot">:</span> <span class="st">&#39;N/A&#39;</span><span class="ot">;</span></span>
<span id="cb8-20"><a href="#cb8-20" aria-hidden="true"></a></span>
<span id="cb8-21"><a href="#cb8-21" aria-hidden="true"></a>    <span class="kw">return</span> <span class="st">&#39;&lt;div class=&quot;weather-block&quot;&gt;&#39;</span> .</span>
<span id="cb8-22"><a href="#cb8-22" aria-hidden="true"></a>           <span class="st">&#39;&lt;p&gt;&#39;</span> . esc_html<span class="ot">(</span> <span class="kw">$city</span> <span class="ot">)</span> . <span class="st">&#39;: &#39;</span> . esc_html<span class="ot">(</span> <span class="kw">$temp</span> <span class="ot">)</span> . <span class="st">&#39;°C&lt;/p&gt;&#39;</span> .</span>
<span id="cb8-23"><a href="#cb8-23" aria-hidden="true"></a>           <span class="st">&#39;&lt;/div&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb8-24"><a href="#cb8-24" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="error-handling">Error Handling</h2>
<p>Implement robust error handling:</p>
<div class="sourceCode" id="cb9">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true"></a><span class="kw">function</span> dprt_render_dynamic_block<span class="ot">(</span> <span class="kw">$attributes</span><span class="ot">,</span> <span class="kw">$content</span><span class="ot">,</span> <span class="kw">$block</span> <span class="ot">)</span> {</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true"></a>    <span class="kw">try</span> {</span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true"></a>        <span class="co">// Validate attributes</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true"></a>        <span class="kw">if</span> <span class="ot">(</span> ! <span class="kw">isset</span><span class="ot">(</span> <span class="kw">$attributes</span><span class="ot">[</span><span class="st">&#39;requiredField&#39;</span><span class="ot">]</span> <span class="ot">)</span> <span class="ot">)</span> {</span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true"></a>            <span class="kw">throw</span> <span class="kw">new</span> <span class="kw">Exception</span><span class="ot">(</span> <span class="st">&#39;Required field missing&#39;</span> <span class="ot">);</span></span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true"></a>        }</span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true"></a></span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true"></a>        <span class="co">// Attempt operation</span></span>
<span id="cb9-9"><a href="#cb9-9" aria-hidden="true"></a>        <span class="kw">$result</span> = dprt_perform_operation<span class="ot">(</span> <span class="kw">$attributes</span> <span class="ot">);</span></span>
<span id="cb9-10"><a href="#cb9-10" aria-hidden="true"></a></span>
<span id="cb9-11"><a href="#cb9-11" aria-hidden="true"></a>        <span class="kw">if</span> <span class="ot">(</span> <span class="kw">false</span> === <span class="kw">$result</span> <span class="ot">)</span> {</span>
<span id="cb9-12"><a href="#cb9-12" aria-hidden="true"></a>            <span class="kw">throw</span> <span class="kw">new</span> <span class="kw">Exception</span><span class="ot">(</span> <span class="st">&#39;Operation failed&#39;</span> <span class="ot">);</span></span>
<span id="cb9-13"><a href="#cb9-13" aria-hidden="true"></a>        }</span>
<span id="cb9-14"><a href="#cb9-14" aria-hidden="true"></a></span>
<span id="cb9-15"><a href="#cb9-15" aria-hidden="true"></a>        <span class="kw">return</span> <span class="kw">$result</span><span class="ot">;</span></span>
<span id="cb9-16"><a href="#cb9-16" aria-hidden="true"></a>    } <span class="kw">catch</span> <span class="ot">(</span> <span class="kw">Exception</span> <span class="kw">$e</span> <span class="ot">)</span> {</span>
<span id="cb9-17"><a href="#cb9-17" aria-hidden="true"></a>        <span class="co">// Log error</span></span>
<span id="cb9-18"><a href="#cb9-18" aria-hidden="true"></a>        <span class="fu">error_log</span><span class="ot">(</span> <span class="st">&#39;Dynamic block error: &#39;</span> . <span class="kw">$e</span>-&gt;getMessage<span class="ot">()</span> <span class="ot">);</span></span>
<span id="cb9-19"><a href="#cb9-19" aria-hidden="true"></a></span>
<span id="cb9-20"><a href="#cb9-20" aria-hidden="true"></a>        <span class="co">// Return user-friendly message</span></span>
<span id="cb9-21"><a href="#cb9-21" aria-hidden="true"></a>        <span class="kw">return</span> <span class="st">&#39;&lt;p class=&quot;block-error&quot;&gt;&#39;</span> . esc_html__<span class="ot">(</span> <span class="st">&#39;Content temporarily unavailable.&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt&#39;</span> <span class="ot">)</span> . <span class="st">&#39;&lt;/p&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb9-22"><a href="#cb9-22" aria-hidden="true"></a>    }</span>
<span id="cb9-23"><a href="#cb9-23" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="conclusion">Conclusion</h2>
<p>Dynamic blocks combine Gutenberg’s user-friendly interface with PHP’s server-side power. Use them for real-time data, personalization, and database queries. Implement caching for performance, validate all inputs, escape all outputs, and handle errors gracefully. Start with simple dynamic blocks and gradually build more complex functionality as you master the concepts.</p>
<h2 id="external-links">External Links</h2>
<ol type="1">
<li><a href="https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/creating-dynamic-blocks/">Dynamic Blocks Documentation</a></li>
<li><a href="https://developer.wordpress.org/reference/functions/register_block_type/">register_block_type() Reference</a></li>
<li><a href="https://developer.wordpress.org/block-editor/reference-guides/components/server-side-render/">ServerSideRender Component</a></li>
<li><a href="https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/">Block Metadata (block.json)</a></li>
<li><a href="https://developer.wordpress.org/reference/classes/wp_query/">WordPress Query Functions</a></li>
</ol>
<h2 id="call-to-action">Call to Action</h2>
<p>Streamline your workflow! <a href="https://blocknavigatorplugin.com/#pricing">Block Editor Navigator Pro</a> provides instant block navigation, search, and organization. Find any block in seconds—try it free!</p>
<p>The post <a href="https://developryplugins.com/how-to-build-dynamic-blocks-with-wordpress-block-editor/">How to Build Dynamic Blocks with WordPress Block Editor</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Create a WordPress Plugin Settings Page (Step-by-Step)</title>
		<link>https://developryplugins.com/how-to-create-a-wordpress-plugin-settings-page-step-by-step/</link>
		
		<dc:creator><![CDATA[Krasen Slavov]]></dc:creator>
		<pubDate>Thu, 30 Jul 2026 09:00:00 +0000</pubDate>
				<category><![CDATA[WordPress Plugin Development Guide]]></category>
		<category><![CDATA[options page]]></category>
		<category><![CDATA[plugin settings]]></category>
		<category><![CDATA[settings api]]></category>
		<category><![CDATA[settings page]]></category>
		<category><![CDATA[wordpress admin]]></category>
		<guid isPermaLink="false">https://developryplugins.com/?p=133</guid>

					<description><![CDATA[<p>Plugin settings pages allow users to configure your plugin without touching code. The WordPress Settings API provides a standardized, secure way to create settings pages that follow WordPress UI conventions...</p>
<p>The post <a href="https://developryplugins.com/how-to-create-a-wordpress-plugin-settings-page-step-by-step/">How to Create a WordPress Plugin Settings Page (Step-by-Step)</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><!-- @format --></p>
<p>Plugin settings pages allow users to configure your plugin without touching code. The WordPress Settings API provides a standardized, secure way to create settings pages that follow WordPress UI conventions and handle data properly.</p>
<h2 id="why-use-the-settings-api">Why Use the Settings API</h2>
<p>The Settings API offers significant advantages over custom form handling:</p>
<p><strong>Automatic security</strong> &#8211; Nonces and capability checks are built-in <strong>Consistent UI</strong> &#8211; Pages match WordPress admin styling automatically <strong>Data handling</strong> &#8211; WordPress manages saving, sanitization, and validation <strong>Best practices</strong> &#8211; Follows WordPress standards automatically</p>
<p>Avoid building custom form handlers. The Settings API is tested, secure, and maintained by WordPress core.</p>
<h2 id="creating-the-admin-menu">Creating the Admin Menu</h2>
<p>First, add a menu page to WordPress admin:</p>
<div class="sourceCode" id="cb1">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true"></a><span class="kw">function</span> dprt_add_settings_page<span class="ot">()</span> {</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true"></a>    add_options_page<span class="ot">(</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true"></a>        <span class="st">&#39;My Plugin Settings&#39;</span><span class="ot">,</span>          <span class="co">// Page title</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true"></a>        <span class="st">&#39;My Plugin&#39;</span><span class="ot">,</span>                   <span class="co">// Menu title</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true"></a>        <span class="st">&#39;manage_options&#39;</span><span class="ot">,</span>              <span class="co">// Capability</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true"></a>        <span class="st">&#39;my-plugin-settings&#39;</span><span class="ot">,</span>          <span class="co">// Menu slug</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true"></a>        <span class="st">&#39;dprt_render_settings_page&#39;</span>    <span class="co">// Callback function</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true"></a>}</span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true"></a>add_action<span class="ot">(</span> <span class="st">&#39;admin_menu&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_add_settings_page&#39;</span> <span class="ot">);</span></span></code></pre>
</div>
<p>This adds a submenu under Settings. For a top-level menu, use <code>add_menu_page()</code> instead.</p>
<h2 id="registering-settings">Registering Settings</h2>
<p>Register each setting WordPress should manage:</p>
<div class="sourceCode" id="cb2">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true"></a><span class="kw">function</span> dprt_register_settings<span class="ot">()</span> {</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true"></a>    register_setting<span class="ot">(</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true"></a>        <span class="st">&#39;dprt_settings_group&#39;</span><span class="ot">,</span>       <span class="co">// Option group</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true"></a>        <span class="st">&#39;dprt_api_key&#39;</span><span class="ot">,</span>              <span class="co">// Option name</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true"></a>            <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;string&#39;</span><span class="ot">,</span></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true"></a>            <span class="st">&#39;sanitize_callback&#39;</span> =&gt; <span class="st">&#39;sanitize_text_field&#39;</span><span class="ot">,</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true"></a>            <span class="st">&#39;default&#39;</span> =&gt; <span class="st">&#39;&#39;</span></span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true"></a>        <span class="ot">)</span></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true"></a></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true"></a>    register_setting<span class="ot">(</span></span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true"></a>        <span class="st">&#39;dprt_settings_group&#39;</span><span class="ot">,</span></span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true"></a>        <span class="st">&#39;dprt_enable_feature&#39;</span><span class="ot">,</span></span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true"></a>            <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;boolean&#39;</span><span class="ot">,</span></span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true"></a>            <span class="st">&#39;default&#39;</span> =&gt; <span class="kw">false</span></span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true"></a>        <span class="ot">)</span></span>
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb2-20"><a href="#cb2-20" aria-hidden="true"></a>}</span>
<span id="cb2-21"><a href="#cb2-21" aria-hidden="true"></a>add_action<span class="ot">(</span> <span class="st">&#39;admin_init&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_register_settings&#39;</span> <span class="ot">);</span></span></code></pre>
</div>
<p>Each setting gets a name (stored in wp_options), type, sanitization callback, and default value.</p>
<h2 id="creating-settings-sections">Creating Settings Sections</h2>
<p>Organize settings into logical sections:</p>
<div class="sourceCode" id="cb3">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true"></a><span class="kw">function</span> dprt_register_settings_sections<span class="ot">()</span> {</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true"></a>    add_settings_section<span class="ot">(</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true"></a>        <span class="st">&#39;dprt_api_section&#39;</span><span class="ot">,</span>              <span class="co">// Section ID</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true"></a>        <span class="st">&#39;API Configuration&#39;</span><span class="ot">,</span>             <span class="co">// Section title</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true"></a>        <span class="st">&#39;dprt_api_section_callback&#39;</span><span class="ot">,</span>     <span class="co">// Section callback</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true"></a>        <span class="st">&#39;my-plugin-settings&#39;</span>             <span class="co">// Page slug</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true"></a></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true"></a>    add_settings_section<span class="ot">(</span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true"></a>        <span class="st">&#39;dprt_display_section&#39;</span><span class="ot">,</span></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true"></a>        <span class="st">&#39;Display Options&#39;</span><span class="ot">,</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true"></a>        <span class="st">&#39;dprt_display_section_callback&#39;</span><span class="ot">,</span></span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true"></a>        <span class="st">&#39;my-plugin-settings&#39;</span></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true"></a>}</span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true"></a>add_action<span class="ot">(</span> <span class="st">&#39;admin_init&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_register_settings_sections&#39;</span> <span class="ot">);</span></span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true"></a></span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true"></a><span class="kw">function</span> dprt_api_section_callback<span class="ot">()</span> {</span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;p&gt;Configure API settings for third-party integrations.&lt;/p&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true"></a>}</span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true"></a></span>
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true"></a><span class="kw">function</span> dprt_display_section_callback<span class="ot">()</span> {</span>
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;p&gt;Control how content displays on your site.&lt;/p&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true"></a>}</span></code></pre>
</div>
<p>Sections group related settings with descriptive headers and instructions.</p>
<h2 id="adding-settings-fields">Adding Settings Fields</h2>
<p>Add individual fields to sections:</p>
<div class="sourceCode" id="cb4">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true"></a><span class="kw">function</span> dprt_register_settings_fields<span class="ot">()</span> {</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true"></a>    <span class="co">// Text field</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true"></a>    add_settings_field<span class="ot">(</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true"></a>        <span class="st">&#39;dprt_api_key&#39;</span><span class="ot">,</span>                  <span class="co">// Field ID</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true"></a>        <span class="st">&#39;API Key&#39;</span><span class="ot">,</span>                       <span class="co">// Field title</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true"></a>        <span class="st">&#39;dprt_api_key_callback&#39;</span><span class="ot">,</span>         <span class="co">// Field callback</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true"></a>        <span class="st">&#39;my-plugin-settings&#39;</span><span class="ot">,</span>            <span class="co">// Page slug</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true"></a>        <span class="st">&#39;dprt_api_section&#39;</span>               <span class="co">// Section ID</span></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true"></a></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true"></a>    <span class="co">// Checkbox field</span></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true"></a>    add_settings_field<span class="ot">(</span></span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true"></a>        <span class="st">&#39;dprt_enable_feature&#39;</span><span class="ot">,</span></span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true"></a>        <span class="st">&#39;Enable Feature&#39;</span><span class="ot">,</span></span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true"></a>        <span class="st">&#39;dprt_enable_feature_callback&#39;</span><span class="ot">,</span></span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true"></a>        <span class="st">&#39;my-plugin-settings&#39;</span><span class="ot">,</span></span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true"></a>        <span class="st">&#39;dprt_display_section&#39;</span></span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true"></a>}</span>
<span id="cb4-20"><a href="#cb4-20" aria-hidden="true"></a>add_action<span class="ot">(</span> <span class="st">&#39;admin_init&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_register_settings_fields&#39;</span> <span class="ot">);</span></span></code></pre>
</div>
<h2 id="field-callback-functions">Field Callback Functions</h2>
<p>Field callbacks render the HTML inputs:</p>
<div class="sourceCode" id="cb5">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true"></a><span class="co">// Text input</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true"></a><span class="kw">function</span> dprt_api_key_callback<span class="ot">()</span> {</span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true"></a>    <span class="kw">$value</span> = get_option<span class="ot">(</span> <span class="st">&#39;dprt_api_key&#39;</span><span class="ot">,</span> <span class="st">&#39;&#39;</span> <span class="ot">);</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;input type=&quot;text&quot; name=&quot;dprt_api_key&quot; value=&quot;&#39;</span> . esc_attr<span class="ot">(</span> <span class="kw">$value</span> <span class="ot">)</span> . <span class="st">&#39;&quot; class=&quot;regular-text&quot;&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;p class=&quot;description&quot;&gt;Enter your API key from the provider.&lt;/p&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true"></a>}</span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true"></a></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true"></a><span class="co">// Checkbox</span></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true"></a><span class="kw">function</span> dprt_enable_feature_callback<span class="ot">()</span> {</span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true"></a>    <span class="kw">$value</span> = get_option<span class="ot">(</span> <span class="st">&#39;dprt_enable_feature&#39;</span><span class="ot">,</span> <span class="kw">false</span> <span class="ot">);</span></span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;input type=&quot;checkbox&quot; name=&quot;dprt_enable_feature&quot; value=&quot;1&quot; &#39;</span> . checked<span class="ot">(</span> <span class="dv">1</span><span class="ot">,</span> <span class="kw">$value</span><span class="ot">,</span> <span class="kw">false</span> <span class="ot">)</span> . <span class="st">&#39;&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;label&gt;Enable this experimental feature&lt;/label&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true"></a>}</span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true"></a></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true"></a><span class="co">// Select dropdown</span></span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true"></a><span class="kw">function</span> dprt_display_style_callback<span class="ot">()</span> {</span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true"></a>    <span class="kw">$value</span> = get_option<span class="ot">(</span> <span class="st">&#39;dprt_display_style&#39;</span><span class="ot">,</span> <span class="st">&#39;default&#39;</span> <span class="ot">);</span></span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true"></a>    <span class="kw">$options</span> = <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true"></a>        <span class="st">&#39;default&#39;</span> =&gt; <span class="st">&#39;Default Style&#39;</span><span class="ot">,</span></span>
<span id="cb5-20"><a href="#cb5-20" aria-hidden="true"></a>        <span class="st">&#39;minimal&#39;</span> =&gt; <span class="st">&#39;Minimal Style&#39;</span><span class="ot">,</span></span>
<span id="cb5-21"><a href="#cb5-21" aria-hidden="true"></a>        <span class="st">&#39;fancy&#39;</span> =&gt; <span class="st">&#39;Fancy Style&#39;</span></span>
<span id="cb5-22"><a href="#cb5-22" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb5-23"><a href="#cb5-23" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;select name=&quot;dprt_display_style&quot;&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb5-24"><a href="#cb5-24" aria-hidden="true"></a>    <span class="kw">foreach</span> <span class="ot">(</span> <span class="kw">$options</span> <span class="kw">as</span> <span class="kw">$key</span> =&gt; <span class="kw">$label</span> <span class="ot">)</span> {</span>
<span id="cb5-25"><a href="#cb5-25" aria-hidden="true"></a>        <span class="kw">echo</span> <span class="st">&#39;&lt;option value=&quot;&#39;</span> . esc_attr<span class="ot">(</span> <span class="kw">$key</span> <span class="ot">)</span> . <span class="st">&#39;&quot; &#39;</span> . selected<span class="ot">(</span> <span class="kw">$value</span><span class="ot">,</span> <span class="kw">$key</span><span class="ot">,</span> <span class="kw">false</span> <span class="ot">)</span> . <span class="st">&#39;&gt;&#39;</span> . esc_html<span class="ot">(</span> <span class="kw">$label</span> <span class="ot">)</span> . <span class="st">&#39;&lt;/option&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb5-26"><a href="#cb5-26" aria-hidden="true"></a>    }</span>
<span id="cb5-27"><a href="#cb5-27" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;/select&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb5-28"><a href="#cb5-28" aria-hidden="true"></a>}</span></code></pre>
</div>
<p>Always escape output and use WordPress helper functions like <code>checked()</code> and <code>selected()</code>.</p>
<h2 id="rendering-the-settings-page">Rendering the Settings Page</h2>
<p>The settings page displays all registered sections and fields:</p>
<div class="sourceCode" id="cb6">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true"></a><span class="kw">function</span> dprt_render_settings_page<span class="ot">()</span> {</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true"></a>    <span class="co">// Check user capabilities</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span> ! current_user_can<span class="ot">(</span> <span class="st">&#39;manage_options&#39;</span> <span class="ot">)</span> <span class="ot">)</span> {</span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true"></a>        <span class="kw">return</span><span class="ot">;</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true"></a>    }</span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true"></a></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true"></a>    <span class="co">// Show error/update messages</span></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true"></a>    settings_errors<span class="ot">(</span> <span class="st">&#39;dprt_messages&#39;</span> <span class="ot">);</span></span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true"></a>    <span class="kw">?&gt;</span></span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true"></a>    &lt;div <span class="kw">class</span>=<span class="st">&quot;wrap&quot;</span>&gt;</span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true"></a>        &lt;h1&gt;&lt;<span class="ot">?</span>php <span class="kw">echo</span> esc_html<span class="ot">(</span> get_admin_page_title<span class="ot">()</span> <span class="ot">);</span> <span class="kw">?&gt;</span>&lt;/h1&gt;</span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true"></a>        &lt;form action=<span class="st">&quot;options.php&quot;</span> method=<span class="st">&quot;post&quot;</span>&gt;</span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true"></a>            &lt;<span class="ot">?</span>php</span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true"></a>            <span class="co">// Output security fields</span></span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true"></a>            settings_fields<span class="ot">(</span> <span class="st">&#39;dprt_settings_group&#39;</span> <span class="ot">);</span></span>
<span id="cb6-16"><a href="#cb6-16" aria-hidden="true"></a></span>
<span id="cb6-17"><a href="#cb6-17" aria-hidden="true"></a>            <span class="co">// Output settings sections</span></span>
<span id="cb6-18"><a href="#cb6-18" aria-hidden="true"></a>            do_settings_sections<span class="ot">(</span> <span class="st">&#39;my-plugin-settings&#39;</span> <span class="ot">);</span></span>
<span id="cb6-19"><a href="#cb6-19" aria-hidden="true"></a></span>
<span id="cb6-20"><a href="#cb6-20" aria-hidden="true"></a>            <span class="co">// Output submit button</span></span>
<span id="cb6-21"><a href="#cb6-21" aria-hidden="true"></a>            submit_button<span class="ot">(</span> <span class="st">&#39;Save Settings&#39;</span> <span class="ot">);</span></span>
<span id="cb6-22"><a href="#cb6-22" aria-hidden="true"></a>            <span class="kw">?&gt;</span></span>
<span id="cb6-23"><a href="#cb6-23" aria-hidden="true"></a>        &lt;/form&gt;</span>
<span id="cb6-24"><a href="#cb6-24" aria-hidden="true"></a>    &lt;/div&gt;</span>
<span id="cb6-25"><a href="#cb6-25" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php</span>
<span id="cb6-26"><a href="#cb6-26" aria-hidden="true"></a>}</span></code></pre>
</div>
<p><code>settings_fields()</code> outputs hidden nonce fields. <code>do_settings_sections()</code> renders all registered sections and fields. <code>submit_button()</code> creates the submit button.</p>
<h2 id="custom-sanitization">Custom Sanitization</h2>
<p>Implement custom sanitization for complex data:</p>
<div class="sourceCode" id="cb7">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true"></a><span class="kw">function</span> dprt_sanitize_email_list<span class="ot">(</span> <span class="kw">$input</span> <span class="ot">)</span> {</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true"></a>    <span class="kw">$emails</span> = <span class="fu">explode</span><span class="ot">(</span> <span class="st">&#39;,&#39;</span><span class="ot">,</span> <span class="kw">$input</span> <span class="ot">);</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true"></a>    <span class="kw">$sanitized</span> = <span class="kw">array</span><span class="ot">();</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true"></a></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true"></a>    <span class="kw">foreach</span> <span class="ot">(</span> <span class="kw">$emails</span> <span class="kw">as</span> <span class="kw">$email</span> <span class="ot">)</span> {</span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true"></a>        <span class="kw">$email</span> = <span class="fu">trim</span><span class="ot">(</span> <span class="kw">$email</span> <span class="ot">);</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true"></a>        <span class="kw">if</span> <span class="ot">(</span> is_email<span class="ot">(</span> <span class="kw">$email</span> <span class="ot">)</span> <span class="ot">)</span> {</span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true"></a>            <span class="kw">$sanitized</span><span class="ot">[]</span> = sanitize_email<span class="ot">(</span> <span class="kw">$email</span> <span class="ot">);</span></span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true"></a>        }</span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true"></a>    }</span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true"></a></span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true"></a>    <span class="kw">return</span> <span class="fu">implode</span><span class="ot">(</span> <span class="st">&#39;, &#39;</span><span class="ot">,</span> <span class="kw">$sanitized</span> <span class="ot">);</span></span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true"></a>}</span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true"></a></span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true"></a>register_setting<span class="ot">(</span></span>
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true"></a>    <span class="st">&#39;dprt_settings_group&#39;</span><span class="ot">,</span></span>
<span id="cb7-17"><a href="#cb7-17" aria-hidden="true"></a>    <span class="st">&#39;dprt_email_list&#39;</span><span class="ot">,</span></span>
<span id="cb7-18"><a href="#cb7-18" aria-hidden="true"></a>    <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb7-19"><a href="#cb7-19" aria-hidden="true"></a>        <span class="st">&#39;sanitize_callback&#39;</span> =&gt; <span class="st">&#39;dprt_sanitize_email_list&#39;</span></span>
<span id="cb7-20"><a href="#cb7-20" aria-hidden="true"></a>    <span class="ot">)</span></span>
<span id="cb7-21"><a href="#cb7-21" aria-hidden="true"></a><span class="ot">);</span></span></code></pre>
</div>
<p>Sanitization callbacks clean data before saving to the database.</p>
<h2 id="validation-and-error-messages">Validation and Error Messages</h2>
<p>Add validation with admin notices:</p>
<div class="sourceCode" id="cb8">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true"></a><span class="kw">function</span> dprt_validate_api_key<span class="ot">(</span> <span class="kw">$value</span> <span class="ot">)</span> {</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span> <span class="fu">strlen</span><span class="ot">(</span> <span class="kw">$value</span> <span class="ot">)</span> &lt; <span class="dv">32</span> <span class="ot">)</span> {</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true"></a>        add_settings_error<span class="ot">(</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true"></a>            <span class="st">&#39;dprt_messages&#39;</span><span class="ot">,</span></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true"></a>            <span class="st">&#39;dprt_message&#39;</span><span class="ot">,</span></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true"></a>            <span class="st">&#39;API key must be at least 32 characters long.&#39;</span><span class="ot">,</span></span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true"></a>            <span class="st">&#39;error&#39;</span></span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true"></a>        <span class="ot">);</span></span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true"></a>        <span class="co">// Return old value to prevent invalid save</span></span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true"></a>        <span class="kw">return</span> get_option<span class="ot">(</span> <span class="st">&#39;dprt_api_key&#39;</span> <span class="ot">);</span></span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true"></a>    }</span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$value</span><span class="ot">;</span></span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="tabbed-settings-interface">Tabbed Settings Interface</h2>
<p>For complex plugins, organize settings into tabs:</p>
<div class="sourceCode" id="cb9">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true"></a><span class="kw">function</span> dprt_render_tabbed_settings_page<span class="ot">()</span> {</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true"></a>    <span class="kw">$active_tab</span> = <span class="kw">isset</span><span class="ot">(</span> <span class="kw">$_GET</span><span class="ot">[</span><span class="st">&#39;tab&#39;</span><span class="ot">]</span> <span class="ot">)</span> <span class="ot">?</span> <span class="kw">$_GET</span><span class="ot">[</span><span class="st">&#39;tab&#39;</span><span class="ot">]</span> <span class="ot">:</span> <span class="st">&#39;general&#39;</span><span class="ot">;</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true"></a>    <span class="kw">?&gt;</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true"></a>    &lt;div <span class="kw">class</span>=<span class="st">&quot;wrap&quot;</span>&gt;</span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true"></a>        &lt;h1&gt;My Plugin Settings&lt;/h1&gt;</span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true"></a>        &lt;h2 <span class="kw">class</span>=<span class="st">&quot;nav-tab-wrapper&quot;</span>&gt;</span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true"></a>            &lt;a href=<span class="st">&quot;?page=my-plugin-settings&amp;tab=general&quot;</span> <span class="kw">class</span>=<span class="st">&quot;nav-tab &lt;?php echo </span><span class="kw">$active_tab</span><span class="st"> === &#39;general&#39; ? &#39;nav-tab-active&#39; : &#39;&#39;; ?&gt;&quot;</span>&gt;General&lt;/a&gt;</span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true"></a>            &lt;a href=<span class="st">&quot;?page=my-plugin-settings&amp;tab=advanced&quot;</span> <span class="kw">class</span>=<span class="st">&quot;nav-tab &lt;?php echo </span><span class="kw">$active_tab</span><span class="st"> === &#39;advanced&#39; ? &#39;nav-tab-active&#39; : &#39;&#39;; ?&gt;&quot;</span>&gt;Advanced&lt;/a&gt;</span>
<span id="cb9-9"><a href="#cb9-9" aria-hidden="true"></a>        &lt;/h2&gt;</span>
<span id="cb9-10"><a href="#cb9-10" aria-hidden="true"></a>        &lt;form action=<span class="st">&quot;options.php&quot;</span> method=<span class="st">&quot;post&quot;</span>&gt;</span>
<span id="cb9-11"><a href="#cb9-11" aria-hidden="true"></a>            &lt;<span class="ot">?</span>php</span>
<span id="cb9-12"><a href="#cb9-12" aria-hidden="true"></a>            <span class="kw">if</span> <span class="ot">(</span> <span class="kw">$active_tab</span> === <span class="st">&#39;general&#39;</span> <span class="ot">)</span> {</span>
<span id="cb9-13"><a href="#cb9-13" aria-hidden="true"></a>                settings_fields<span class="ot">(</span> <span class="st">&#39;dprt_general_settings&#39;</span> <span class="ot">);</span></span>
<span id="cb9-14"><a href="#cb9-14" aria-hidden="true"></a>                do_settings_sections<span class="ot">(</span> <span class="st">&#39;dprt-general-settings&#39;</span> <span class="ot">);</span></span>
<span id="cb9-15"><a href="#cb9-15" aria-hidden="true"></a>            } <span class="kw">else</span> {</span>
<span id="cb9-16"><a href="#cb9-16" aria-hidden="true"></a>                settings_fields<span class="ot">(</span> <span class="st">&#39;dprt_advanced_settings&#39;</span> <span class="ot">);</span></span>
<span id="cb9-17"><a href="#cb9-17" aria-hidden="true"></a>                do_settings_sections<span class="ot">(</span> <span class="st">&#39;dprt-advanced-settings&#39;</span> <span class="ot">);</span></span>
<span id="cb9-18"><a href="#cb9-18" aria-hidden="true"></a>            }</span>
<span id="cb9-19"><a href="#cb9-19" aria-hidden="true"></a>            submit_button<span class="ot">();</span></span>
<span id="cb9-20"><a href="#cb9-20" aria-hidden="true"></a>            <span class="kw">?&gt;</span></span>
<span id="cb9-21"><a href="#cb9-21" aria-hidden="true"></a>        &lt;/form&gt;</span>
<span id="cb9-22"><a href="#cb9-22" aria-hidden="true"></a>    &lt;/div&gt;</span>
<span id="cb9-23"><a href="#cb9-23" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php</span>
<span id="cb9-24"><a href="#cb9-24" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="retrieving-saved-options">Retrieving Saved Options</h2>
<p>Access saved settings anywhere in your plugin:</p>
<div class="sourceCode" id="cb10">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true"></a><span class="co">// Single option</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true"></a><span class="kw">$api_key</span> = get_option<span class="ot">(</span> <span class="st">&#39;dprt_api_key&#39;</span><span class="ot">,</span> <span class="st">&#39;&#39;</span> <span class="ot">);</span></span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true"></a></span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true"></a><span class="co">// Multiple options</span></span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true"></a><span class="kw">$options</span> = <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true"></a>    <span class="st">&#39;api_key&#39;</span> =&gt; get_option<span class="ot">(</span> <span class="st">&#39;dprt_api_key&#39;</span><span class="ot">,</span> <span class="st">&#39;&#39;</span> <span class="ot">),</span></span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true"></a>    <span class="st">&#39;enable_feature&#39;</span> =&gt; get_option<span class="ot">(</span> <span class="st">&#39;dprt_enable_feature&#39;</span><span class="ot">,</span> <span class="kw">false</span> <span class="ot">),</span></span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true"></a>    <span class="st">&#39;display_style&#39;</span> =&gt; get_option<span class="ot">(</span> <span class="st">&#39;dprt_display_style&#39;</span><span class="ot">,</span> <span class="st">&#39;default&#39;</span> <span class="ot">)</span></span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true"></a><span class="ot">);</span></span></code></pre>
</div>
<p>Always provide default values as the second parameter.</p>
<h2 id="conclusion">Conclusion</h2>
<p>The WordPress Settings API streamlines plugin configuration. Register settings, create sections and fields, render the page with built-in functions, and WordPress handles security, validation, and data storage. This approach creates professional, secure settings pages that integrate seamlessly with WordPress admin.</p>
<ul>
<li>Real-world settings page examples</li>
</ul>
<p>Includes complete code examples, form templates, and best practices for creating user-friendly plugin settings interfaces.</p>
<h2 id="external-links">External Links</h2>
<ol type="1">
<li><a href="https://developer.wordpress.org/plugins/settings/">Settings API Documentation</a></li>
<li><a href="https://developer.wordpress.org/plugins/administration-menus/">Administration Menus</a></li>
<li><a href="https://developer.wordpress.org/apis/options/">Options API Reference</a></li>
<li><a href="https://developer.wordpress.org/plugins/security/data-validation/">Data Validation</a></li>
<li><a href="https://developer.wordpress.org/reference/hooks/admin_notices/">Admin Notices</a></li>
</ol>
<h2 id="call-to-action">Call to Action</h2>
<p>Supercharge your development! <a href="https://acfcopilotplugin.com/">ACF Copilot Pro</a> generates ACF field groups with AI, exports to PHP, and accelerates custom field workflows—try it free!</p>
<p>The post <a href="https://developryplugins.com/how-to-create-a-wordpress-plugin-settings-page-step-by-step/">How to Create a WordPress Plugin Settings Page (Step-by-Step)</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Create ACF Field Groups Programmatically with PHP</title>
		<link>https://developryplugins.com/how-to-create-acf-field-groups-programmatically-with-php/</link>
		
		<dc:creator><![CDATA[Krasen Slavov]]></dc:creator>
		<pubDate>Sat, 25 Jul 2026 09:00:00 +0000</pubDate>
				<category><![CDATA[Advanced Custom Fields (ACF) Tutorials]]></category>
		<category><![CDATA[acf php]]></category>
		<category><![CDATA[acf_add_local_field_group]]></category>
		<category><![CDATA[field registration]]></category>
		<category><![CDATA[programmatic fields]]></category>
		<category><![CDATA[version control]]></category>
		<guid isPermaLink="false">https://developryplugins.com/?p=134</guid>

					<description><![CDATA[<p>Programmatic ACF field registration through acf_add_local_field_group() enables version-controlled field configurations eliminating manual UI setup and database storage. From basic field group arrays and field type definitions to conditional logic arrays...</p>
<p>The post <a href="https://developryplugins.com/how-to-create-acf-field-groups-programmatically-with-php/">How to Create ACF Field Groups Programmatically with PHP</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><!-- @format --></p>
<p>Programmatic ACF field registration through acf_add_local_field_group() enables version-controlled field configurations eliminating manual UI setup and database storage. From basic field group arrays and field type definitions to conditional logic arrays and dynamic field generation, programmatic registration ensures consistent deployments. This comprehensive guide teaches acf_add_local_field_group() syntax, field array structure, location rules, conditional logic, field cloning, and advanced techniques creating maintainable ACF configurations through code.</p>
<h2 id="why-register-fields-programmatically">Why Register Fields Programmatically?</h2>
<p><strong>Benefits of Programmatic Registration</strong>:</p>
<ol type="1">
<li><strong>Version Control</strong>: Field configurations in Git</li>
<li><strong>Deployment</strong>: Automatic field sync across environments</li>
<li><strong>Code Review</strong>: Field changes reviewed in pull requests</li>
<li><strong>Portability</strong>: Easy theme/plugin distribution</li>
<li><strong>Performance</strong>: Faster than database lookups</li>
<li><strong>Documentation</strong>: Self-documenting field structure</li>
<li><strong>Automation</strong>: Dynamic field generation</li>
</ol>
<p><strong>Database vs Programmatic</strong>:</p>
<pre><code>Database (UI):
- Stored in wp_posts
- Manual export/import
- Sync issues between environments

Programmatic (PHP):
- Stored in theme/plugin files
- Git versioned
- Automatic sync via code deployment</code></pre>
<h2 id="basic-field-group-registration">Basic Field Group Registration</h2>
<p><strong>Simple Field Group</strong> (functions.php):</p>
<div class="sourceCode" id="cb2">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true"></a><span class="kw">function</span> mytheme_register_acf_fields<span class="ot">()</span> {</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true"></a>    <span class="co">// Check if ACF is installed</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span>!<span class="fu">function_exists</span><span class="ot">(</span><span class="st">&#39;acf_add_local_field_group&#39;</span><span class="ot">))</span> {</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true"></a>        <span class="kw">return</span><span class="ot">;</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true"></a>    }</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true"></a></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true"></a>    acf_add_local_field_group<span class="ot">(</span><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true"></a>        <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;group_product_details&#39;</span><span class="ot">,</span></span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true"></a>        <span class="st">&#39;title&#39;</span> =&gt; <span class="st">&#39;Product Details&#39;</span><span class="ot">,</span></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true"></a>        <span class="st">&#39;fields&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true"></a>            <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true"></a>                <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_product_price&#39;</span><span class="ot">,</span></span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true"></a>                <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Price&#39;</span><span class="ot">,</span></span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true"></a>                <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;product_price&#39;</span><span class="ot">,</span></span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true"></a>                <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;number&#39;</span><span class="ot">,</span></span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true"></a>                <span class="st">&#39;prefix&#39;</span> =&gt; <span class="st">&#39;$&#39;</span><span class="ot">,</span></span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true"></a>                <span class="st">&#39;prepend&#39;</span> =&gt; <span class="st">&#39;$&#39;</span><span class="ot">,</span></span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true"></a>                <span class="st">&#39;step&#39;</span> =&gt; <span class="fl">0.01</span><span class="ot">,</span></span>
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true"></a>                <span class="st">&#39;required&#39;</span> =&gt; <span class="dv">1</span><span class="ot">,</span></span>
<span id="cb2-20"><a href="#cb2-20" aria-hidden="true"></a>            <span class="ot">),</span></span>
<span id="cb2-21"><a href="#cb2-21" aria-hidden="true"></a>            <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb2-22"><a href="#cb2-22" aria-hidden="true"></a>                <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_product_sku&#39;</span><span class="ot">,</span></span>
<span id="cb2-23"><a href="#cb2-23" aria-hidden="true"></a>                <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;SKU&#39;</span><span class="ot">,</span></span>
<span id="cb2-24"><a href="#cb2-24" aria-hidden="true"></a>                <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;product_sku&#39;</span><span class="ot">,</span></span>
<span id="cb2-25"><a href="#cb2-25" aria-hidden="true"></a>                <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;text&#39;</span><span class="ot">,</span></span>
<span id="cb2-26"><a href="#cb2-26" aria-hidden="true"></a>                <span class="st">&#39;placeholder&#39;</span> =&gt; <span class="st">&#39;Enter SKU&#39;</span><span class="ot">,</span></span>
<span id="cb2-27"><a href="#cb2-27" aria-hidden="true"></a>            <span class="ot">),</span></span>
<span id="cb2-28"><a href="#cb2-28" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb2-29"><a href="#cb2-29" aria-hidden="true"></a>        <span class="st">&#39;location&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb2-30"><a href="#cb2-30" aria-hidden="true"></a>            <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb2-31"><a href="#cb2-31" aria-hidden="true"></a>                <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb2-32"><a href="#cb2-32" aria-hidden="true"></a>                    <span class="st">&#39;param&#39;</span> =&gt; <span class="st">&#39;post_type&#39;</span><span class="ot">,</span></span>
<span id="cb2-33"><a href="#cb2-33" aria-hidden="true"></a>                    <span class="st">&#39;operator&#39;</span> =&gt; <span class="st">&#39;==&#39;</span><span class="ot">,</span></span>
<span id="cb2-34"><a href="#cb2-34" aria-hidden="true"></a>                    <span class="st">&#39;value&#39;</span> =&gt; <span class="st">&#39;product&#39;</span><span class="ot">,</span></span>
<span id="cb2-35"><a href="#cb2-35" aria-hidden="true"></a>                <span class="ot">),</span></span>
<span id="cb2-36"><a href="#cb2-36" aria-hidden="true"></a>            <span class="ot">),</span></span>
<span id="cb2-37"><a href="#cb2-37" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb2-38"><a href="#cb2-38" aria-hidden="true"></a>    <span class="ot">));</span></span>
<span id="cb2-39"><a href="#cb2-39" aria-hidden="true"></a>}</span>
<span id="cb2-40"><a href="#cb2-40" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;acf/init&#39;</span><span class="ot">,</span> <span class="st">&#39;mytheme_register_acf_fields&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="field-group-array-structure">Field Group Array Structure</h2>
<p><strong>Complete Field Group Configuration</strong>:</p>
<div class="sourceCode" id="cb3">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true"></a>acf_add_local_field_group<span class="ot">(</span><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true"></a>    <span class="co">// Required</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;group_unique_key&#39;</span><span class="ot">,</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true"></a>    <span class="st">&#39;title&#39;</span> =&gt; <span class="st">&#39;Field Group Title&#39;</span><span class="ot">,</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true"></a></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true"></a>    <span class="co">// Optional settings</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true"></a>    <span class="st">&#39;fields&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(),</span> <span class="co">// Field array</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true"></a>    <span class="st">&#39;location&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(),</span> <span class="co">// Location rules</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true"></a>    <span class="st">&#39;menu_order&#39;</span> =&gt; <span class="dv">0</span><span class="ot">,</span> <span class="co">// Order in edit screen</span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true"></a>    <span class="st">&#39;position&#39;</span> =&gt; <span class="st">&#39;normal&#39;</span><span class="ot">,</span> <span class="co">// normal, acf_after_title, side</span></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true"></a>    <span class="st">&#39;style&#39;</span> =&gt; <span class="st">&#39;default&#39;</span><span class="ot">,</span> <span class="co">// default, seamless</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true"></a>    <span class="st">&#39;label_placement&#39;</span> =&gt; <span class="st">&#39;top&#39;</span><span class="ot">,</span> <span class="co">// top, left</span></span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true"></a>    <span class="st">&#39;instruction_placement&#39;</span> =&gt; <span class="st">&#39;label&#39;</span><span class="ot">,</span> <span class="co">// label, field</span></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true"></a>    <span class="st">&#39;hide_on_screen&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(),</span> <span class="co">// Hide WP metaboxes</span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true"></a>    <span class="st">&#39;active&#39;</span> =&gt; <span class="kw">true</span><span class="ot">,</span> <span class="co">// Active state</span></span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true"></a>    <span class="st">&#39;description&#39;</span> =&gt; <span class="st">&#39;&#39;</span><span class="ot">,</span> <span class="co">// Group description</span></span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true"></a><span class="ot">));</span></span></code></pre>
</div>
<h2 id="common-field-types">Common Field Types</h2>
<p><strong>Text Field</strong>:</p>
<div class="sourceCode" id="cb4">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_company_name&#39;</span><span class="ot">,</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Company Name&#39;</span><span class="ot">,</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;company_name&#39;</span><span class="ot">,</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;text&#39;</span><span class="ot">,</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true"></a>    <span class="st">&#39;default_value&#39;</span> =&gt; <span class="st">&#39;&#39;</span><span class="ot">,</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true"></a>    <span class="st">&#39;placeholder&#39;</span> =&gt; <span class="st">&#39;&#39;</span><span class="ot">,</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true"></a>    <span class="st">&#39;maxlength&#39;</span> =&gt; <span class="st">&#39;&#39;</span><span class="ot">,</span></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true"></a>    <span class="st">&#39;required&#39;</span> =&gt; <span class="dv">0</span><span class="ot">,</span></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true"></a>    <span class="st">&#39;prepend&#39;</span> =&gt; <span class="st">&#39;&#39;</span><span class="ot">,</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true"></a>    <span class="st">&#39;append&#39;</span> =&gt; <span class="st">&#39;&#39;</span><span class="ot">,</span></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Textarea Field</strong>:</p>
<div class="sourceCode" id="cb5">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_description&#39;</span><span class="ot">,</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Description&#39;</span><span class="ot">,</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;description&#39;</span><span class="ot">,</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;textarea&#39;</span><span class="ot">,</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true"></a>    <span class="st">&#39;rows&#39;</span> =&gt; <span class="dv">4</span><span class="ot">,</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true"></a>    <span class="st">&#39;new_lines&#39;</span> =&gt; <span class="st">&#39;wpautop&#39;</span><span class="ot">,</span> <span class="co">// wpautop, br, &#39;&#39;</span></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Number Field</strong>:</p>
<div class="sourceCode" id="cb6">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_quantity&#39;</span><span class="ot">,</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Quantity&#39;</span><span class="ot">,</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;quantity&#39;</span><span class="ot">,</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;number&#39;</span><span class="ot">,</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true"></a>    <span class="st">&#39;min&#39;</span> =&gt; <span class="dv">0</span><span class="ot">,</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true"></a>    <span class="st">&#39;max&#39;</span> =&gt; <span class="dv">100</span><span class="ot">,</span></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true"></a>    <span class="st">&#39;step&#39;</span> =&gt; <span class="dv">1</span><span class="ot">,</span></span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true"></a>    <span class="st">&#39;default_value&#39;</span> =&gt; <span class="dv">1</span><span class="ot">,</span></span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Email Field</strong>:</p>
<div class="sourceCode" id="cb7">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_contact_email&#39;</span><span class="ot">,</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Contact Email&#39;</span><span class="ot">,</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;contact_email&#39;</span><span class="ot">,</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;email&#39;</span><span class="ot">,</span></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true"></a>    <span class="st">&#39;required&#39;</span> =&gt; <span class="dv">1</span><span class="ot">,</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>URL Field</strong>:</p>
<div class="sourceCode" id="cb8">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_website&#39;</span><span class="ot">,</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Website URL&#39;</span><span class="ot">,</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;website&#39;</span><span class="ot">,</span></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;url&#39;</span><span class="ot">,</span></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true"></a>    <span class="st">&#39;placeholder&#39;</span> =&gt; <span class="st">&#39;https://&#39;</span><span class="ot">,</span></span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Select Field</strong>:</p>
<div class="sourceCode" id="cb9">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_category&#39;</span><span class="ot">,</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Category&#39;</span><span class="ot">,</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;category&#39;</span><span class="ot">,</span></span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;select&#39;</span><span class="ot">,</span></span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true"></a>    <span class="st">&#39;choices&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true"></a>        <span class="st">&#39;technology&#39;</span> =&gt; <span class="st">&#39;Technology&#39;</span><span class="ot">,</span></span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true"></a>        <span class="st">&#39;design&#39;</span> =&gt; <span class="st">&#39;Design&#39;</span><span class="ot">,</span></span>
<span id="cb9-9"><a href="#cb9-9" aria-hidden="true"></a>        <span class="st">&#39;marketing&#39;</span> =&gt; <span class="st">&#39;Marketing&#39;</span><span class="ot">,</span></span>
<span id="cb9-10"><a href="#cb9-10" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb9-11"><a href="#cb9-11" aria-hidden="true"></a>    <span class="st">&#39;default_value&#39;</span> =&gt; <span class="st">&#39;technology&#39;</span><span class="ot">,</span></span>
<span id="cb9-12"><a href="#cb9-12" aria-hidden="true"></a>    <span class="st">&#39;allow_null&#39;</span> =&gt; <span class="dv">0</span><span class="ot">,</span></span>
<span id="cb9-13"><a href="#cb9-13" aria-hidden="true"></a>    <span class="st">&#39;multiple&#39;</span> =&gt; <span class="dv">0</span><span class="ot">,</span></span>
<span id="cb9-14"><a href="#cb9-14" aria-hidden="true"></a>    <span class="st">&#39;ui&#39;</span> =&gt; <span class="dv">1</span><span class="ot">,</span> <span class="co">// Enhanced UI</span></span>
<span id="cb9-15"><a href="#cb9-15" aria-hidden="true"></a>    <span class="st">&#39;return_format&#39;</span> =&gt; <span class="st">&#39;value&#39;</span><span class="ot">,</span> <span class="co">// value, label, array</span></span>
<span id="cb9-16"><a href="#cb9-16" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Checkbox Field</strong>:</p>
<div class="sourceCode" id="cb10">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_features&#39;</span><span class="ot">,</span></span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Features&#39;</span><span class="ot">,</span></span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;features&#39;</span><span class="ot">,</span></span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;checkbox&#39;</span><span class="ot">,</span></span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true"></a>    <span class="st">&#39;choices&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true"></a>        <span class="st">&#39;ssl&#39;</span> =&gt; <span class="st">&#39;SSL Certificate&#39;</span><span class="ot">,</span></span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true"></a>        <span class="st">&#39;backup&#39;</span> =&gt; <span class="st">&#39;Daily Backups&#39;</span><span class="ot">,</span></span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true"></a>        <span class="st">&#39;support&#39;</span> =&gt; <span class="st">&#39;24/7 Support&#39;</span><span class="ot">,</span></span>
<span id="cb10-10"><a href="#cb10-10" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb10-11"><a href="#cb10-11" aria-hidden="true"></a>    <span class="st">&#39;default_value&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(),</span></span>
<span id="cb10-12"><a href="#cb10-12" aria-hidden="true"></a>    <span class="st">&#39;layout&#39;</span> =&gt; <span class="st">&#39;vertical&#39;</span><span class="ot">,</span> <span class="co">// vertical, horizontal</span></span>
<span id="cb10-13"><a href="#cb10-13" aria-hidden="true"></a>    <span class="st">&#39;toggle&#39;</span> =&gt; <span class="dv">0</span><span class="ot">,</span></span>
<span id="cb10-14"><a href="#cb10-14" aria-hidden="true"></a>    <span class="st">&#39;return_format&#39;</span> =&gt; <span class="st">&#39;value&#39;</span><span class="ot">,</span> <span class="co">// value, label, array</span></span>
<span id="cb10-15"><a href="#cb10-15" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Radio Button Field</strong>:</p>
<div class="sourceCode" id="cb11">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_status&#39;</span><span class="ot">,</span></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Status&#39;</span><span class="ot">,</span></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;status&#39;</span><span class="ot">,</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;radio&#39;</span><span class="ot">,</span></span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true"></a>    <span class="st">&#39;choices&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true"></a>        <span class="st">&#39;active&#39;</span> =&gt; <span class="st">&#39;Active&#39;</span><span class="ot">,</span></span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true"></a>        <span class="st">&#39;inactive&#39;</span> =&gt; <span class="st">&#39;Inactive&#39;</span><span class="ot">,</span></span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true"></a>        <span class="st">&#39;pending&#39;</span> =&gt; <span class="st">&#39;Pending&#39;</span><span class="ot">,</span></span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true"></a>    <span class="st">&#39;default_value&#39;</span> =&gt; <span class="st">&#39;active&#39;</span><span class="ot">,</span></span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true"></a>    <span class="st">&#39;layout&#39;</span> =&gt; <span class="st">&#39;horizontal&#39;</span><span class="ot">,</span></span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>True/False Field</strong>:</p>
<div class="sourceCode" id="cb12">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_featured&#39;</span><span class="ot">,</span></span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Featured&#39;</span><span class="ot">,</span></span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;is_featured&#39;</span><span class="ot">,</span></span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;true_false&#39;</span><span class="ot">,</span></span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true"></a>    <span class="st">&#39;default_value&#39;</span> =&gt; <span class="dv">0</span><span class="ot">,</span></span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true"></a>    <span class="st">&#39;ui&#39;</span> =&gt; <span class="dv">1</span><span class="ot">,</span> <span class="co">// Toggle UI</span></span>
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true"></a>    <span class="st">&#39;ui_on_text&#39;</span> =&gt; <span class="st">&#39;Yes&#39;</span><span class="ot">,</span></span>
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true"></a>    <span class="st">&#39;ui_off_text&#39;</span> =&gt; <span class="st">&#39;No&#39;</span><span class="ot">,</span></span>
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Image Field</strong>:</p>
<div class="sourceCode" id="cb13">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_featured_image&#39;</span><span class="ot">,</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Featured Image&#39;</span><span class="ot">,</span></span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;featured_image&#39;</span><span class="ot">,</span></span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;image&#39;</span><span class="ot">,</span></span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true"></a>    <span class="st">&#39;return_format&#39;</span> =&gt; <span class="st">&#39;array&#39;</span><span class="ot">,</span> <span class="co">// array, url, id</span></span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true"></a>    <span class="st">&#39;preview_size&#39;</span> =&gt; <span class="st">&#39;medium&#39;</span><span class="ot">,</span></span>
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true"></a>    <span class="st">&#39;library&#39;</span> =&gt; <span class="st">&#39;all&#39;</span><span class="ot">,</span> <span class="co">// all, uploadedTo</span></span>
<span id="cb13-9"><a href="#cb13-9" aria-hidden="true"></a>    <span class="st">&#39;min_width&#39;</span> =&gt; <span class="dv">800</span><span class="ot">,</span></span>
<span id="cb13-10"><a href="#cb13-10" aria-hidden="true"></a>    <span class="st">&#39;min_height&#39;</span> =&gt; <span class="dv">600</span><span class="ot">,</span></span>
<span id="cb13-11"><a href="#cb13-11" aria-hidden="true"></a>    <span class="st">&#39;max_size&#39;</span> =&gt; <span class="dv">2</span><span class="ot">,</span> <span class="co">// MB</span></span>
<span id="cb13-12"><a href="#cb13-12" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>File Field</strong>:</p>
<div class="sourceCode" id="cb14">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_download&#39;</span><span class="ot">,</span></span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Downloadable File&#39;</span><span class="ot">,</span></span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;download_file&#39;</span><span class="ot">,</span></span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;file&#39;</span><span class="ot">,</span></span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true"></a>    <span class="st">&#39;return_format&#39;</span> =&gt; <span class="st">&#39;array&#39;</span><span class="ot">,</span></span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true"></a>    <span class="st">&#39;library&#39;</span> =&gt; <span class="st">&#39;all&#39;</span><span class="ot">,</span></span>
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true"></a>    <span class="st">&#39;mime_types&#39;</span> =&gt; <span class="st">&#39;pdf,doc,docx&#39;</span><span class="ot">,</span></span>
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Wysiwyg Editor</strong>:</p>
<div class="sourceCode" id="cb15">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_content&#39;</span><span class="ot">,</span></span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Content&#39;</span><span class="ot">,</span></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;custom_content&#39;</span><span class="ot">,</span></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;wysiwyg&#39;</span><span class="ot">,</span></span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true"></a>    <span class="st">&#39;tabs&#39;</span> =&gt; <span class="st">&#39;all&#39;</span><span class="ot">,</span> <span class="co">// all, visual, text</span></span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true"></a>    <span class="st">&#39;toolbar&#39;</span> =&gt; <span class="st">&#39;full&#39;</span><span class="ot">,</span> <span class="co">// full, basic</span></span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true"></a>    <span class="st">&#39;media_upload&#39;</span> =&gt; <span class="dv">1</span><span class="ot">,</span></span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true"></a>    <span class="st">&#39;delay&#39;</span> =&gt; <span class="dv">0</span><span class="ot">,</span></span>
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<h2 id="date-and-time-fields">Date and Time Fields</h2>
<p><strong>Date Picker</strong>:</p>
<div class="sourceCode" id="cb16">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_event_date&#39;</span><span class="ot">,</span></span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Event Date&#39;</span><span class="ot">,</span></span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;event_date&#39;</span><span class="ot">,</span></span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;date_picker&#39;</span><span class="ot">,</span></span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true"></a>    <span class="st">&#39;display_format&#39;</span> =&gt; <span class="st">&#39;d/m/Y&#39;</span><span class="ot">,</span></span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true"></a>    <span class="st">&#39;return_format&#39;</span> =&gt; <span class="st">&#39;Y-m-d&#39;</span><span class="ot">,</span></span>
<span id="cb16-8"><a href="#cb16-8" aria-hidden="true"></a>    <span class="st">&#39;first_day&#39;</span> =&gt; <span class="dv">1</span><span class="ot">,</span> <span class="co">// 0 = Sunday, 1 = Monday</span></span>
<span id="cb16-9"><a href="#cb16-9" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Date Time Picker</strong>:</p>
<div class="sourceCode" id="cb17">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_publish_datetime&#39;</span><span class="ot">,</span></span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Publish Date &amp; Time&#39;</span><span class="ot">,</span></span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;publish_datetime&#39;</span><span class="ot">,</span></span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;date_time_picker&#39;</span><span class="ot">,</span></span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true"></a>    <span class="st">&#39;display_format&#39;</span> =&gt; <span class="st">&#39;d/m/Y g:i a&#39;</span><span class="ot">,</span></span>
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true"></a>    <span class="st">&#39;return_format&#39;</span> =&gt; <span class="st">&#39;Y-m-d H:i:s&#39;</span><span class="ot">,</span></span>
<span id="cb17-8"><a href="#cb17-8" aria-hidden="true"></a>    <span class="st">&#39;first_day&#39;</span> =&gt; <span class="dv">1</span><span class="ot">,</span></span>
<span id="cb17-9"><a href="#cb17-9" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Time Picker</strong>:</p>
<div class="sourceCode" id="cb18">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_opening_time&#39;</span><span class="ot">,</span></span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Opening Time&#39;</span><span class="ot">,</span></span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;opening_time&#39;</span><span class="ot">,</span></span>
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;time_picker&#39;</span><span class="ot">,</span></span>
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true"></a>    <span class="st">&#39;display_format&#39;</span> =&gt; <span class="st">&#39;g:i a&#39;</span><span class="ot">,</span></span>
<span id="cb18-7"><a href="#cb18-7" aria-hidden="true"></a>    <span class="st">&#39;return_format&#39;</span> =&gt; <span class="st">&#39;H:i:s&#39;</span><span class="ot">,</span></span>
<span id="cb18-8"><a href="#cb18-8" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<h2 id="relationship-and-post-object-fields">Relationship and Post Object Fields</h2>
<p><strong>Post Object Field</strong>:</p>
<div class="sourceCode" id="cb19">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_related_post&#39;</span><span class="ot">,</span></span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Related Post&#39;</span><span class="ot">,</span></span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;related_post&#39;</span><span class="ot">,</span></span>
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;post_object&#39;</span><span class="ot">,</span></span>
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true"></a>    <span class="st">&#39;post_type&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span><span class="st">&#39;post&#39;</span><span class="ot">,</span> <span class="st">&#39;page&#39;</span><span class="ot">),</span></span>
<span id="cb19-7"><a href="#cb19-7" aria-hidden="true"></a>    <span class="st">&#39;taxonomy&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(),</span></span>
<span id="cb19-8"><a href="#cb19-8" aria-hidden="true"></a>    <span class="st">&#39;allow_null&#39;</span> =&gt; <span class="dv">0</span><span class="ot">,</span></span>
<span id="cb19-9"><a href="#cb19-9" aria-hidden="true"></a>    <span class="st">&#39;multiple&#39;</span> =&gt; <span class="dv">0</span><span class="ot">,</span></span>
<span id="cb19-10"><a href="#cb19-10" aria-hidden="true"></a>    <span class="st">&#39;return_format&#39;</span> =&gt; <span class="st">&#39;object&#39;</span><span class="ot">,</span> <span class="co">// object, id</span></span>
<span id="cb19-11"><a href="#cb19-11" aria-hidden="true"></a>    <span class="st">&#39;ui&#39;</span> =&gt; <span class="dv">1</span><span class="ot">,</span></span>
<span id="cb19-12"><a href="#cb19-12" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Relationship Field</strong>:</p>
<div class="sourceCode" id="cb20">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_related_projects&#39;</span><span class="ot">,</span></span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Related Projects&#39;</span><span class="ot">,</span></span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;related_projects&#39;</span><span class="ot">,</span></span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;relationship&#39;</span><span class="ot">,</span></span>
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true"></a>    <span class="st">&#39;post_type&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span><span class="st">&#39;portfolio&#39;</span><span class="ot">),</span></span>
<span id="cb20-7"><a href="#cb20-7" aria-hidden="true"></a>    <span class="st">&#39;taxonomy&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(),</span></span>
<span id="cb20-8"><a href="#cb20-8" aria-hidden="true"></a>    <span class="st">&#39;filters&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span><span class="st">&#39;search&#39;</span><span class="ot">,</span> <span class="st">&#39;post_type&#39;</span><span class="ot">,</span> <span class="st">&#39;taxonomy&#39;</span><span class="ot">),</span></span>
<span id="cb20-9"><a href="#cb20-9" aria-hidden="true"></a>    <span class="st">&#39;min&#39;</span> =&gt; <span class="dv">0</span><span class="ot">,</span></span>
<span id="cb20-10"><a href="#cb20-10" aria-hidden="true"></a>    <span class="st">&#39;max&#39;</span> =&gt; <span class="dv">5</span><span class="ot">,</span></span>
<span id="cb20-11"><a href="#cb20-11" aria-hidden="true"></a>    <span class="st">&#39;return_format&#39;</span> =&gt; <span class="st">&#39;object&#39;</span><span class="ot">,</span></span>
<span id="cb20-12"><a href="#cb20-12" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<h2 id="repeater-field-acf-pro">Repeater Field (ACF PRO)</h2>
<p><strong>Repeater Configuration</strong>:</p>
<div class="sourceCode" id="cb21">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_team_members&#39;</span><span class="ot">,</span></span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Team Members&#39;</span><span class="ot">,</span></span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;team_members&#39;</span><span class="ot">,</span></span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;repeater&#39;</span><span class="ot">,</span></span>
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true"></a>    <span class="st">&#39;layout&#39;</span> =&gt; <span class="st">&#39;block&#39;</span><span class="ot">,</span> <span class="co">// table, block, row</span></span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true"></a>    <span class="st">&#39;button_label&#39;</span> =&gt; <span class="st">&#39;Add Team Member&#39;</span><span class="ot">,</span></span>
<span id="cb21-8"><a href="#cb21-8" aria-hidden="true"></a>    <span class="st">&#39;min&#39;</span> =&gt; <span class="dv">0</span><span class="ot">,</span></span>
<span id="cb21-9"><a href="#cb21-9" aria-hidden="true"></a>    <span class="st">&#39;max&#39;</span> =&gt; <span class="dv">10</span><span class="ot">,</span></span>
<span id="cb21-10"><a href="#cb21-10" aria-hidden="true"></a>    <span class="st">&#39;sub_fields&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb21-11"><a href="#cb21-11" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb21-12"><a href="#cb21-12" aria-hidden="true"></a>            <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_member_name&#39;</span><span class="ot">,</span></span>
<span id="cb21-13"><a href="#cb21-13" aria-hidden="true"></a>            <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Name&#39;</span><span class="ot">,</span></span>
<span id="cb21-14"><a href="#cb21-14" aria-hidden="true"></a>            <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;name&#39;</span><span class="ot">,</span></span>
<span id="cb21-15"><a href="#cb21-15" aria-hidden="true"></a>            <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;text&#39;</span><span class="ot">,</span></span>
<span id="cb21-16"><a href="#cb21-16" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb21-17"><a href="#cb21-17" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb21-18"><a href="#cb21-18" aria-hidden="true"></a>            <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_member_position&#39;</span><span class="ot">,</span></span>
<span id="cb21-19"><a href="#cb21-19" aria-hidden="true"></a>            <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Position&#39;</span><span class="ot">,</span></span>
<span id="cb21-20"><a href="#cb21-20" aria-hidden="true"></a>            <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;position&#39;</span><span class="ot">,</span></span>
<span id="cb21-21"><a href="#cb21-21" aria-hidden="true"></a>            <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;text&#39;</span><span class="ot">,</span></span>
<span id="cb21-22"><a href="#cb21-22" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb21-23"><a href="#cb21-23" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb21-24"><a href="#cb21-24" aria-hidden="true"></a>            <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_member_photo&#39;</span><span class="ot">,</span></span>
<span id="cb21-25"><a href="#cb21-25" aria-hidden="true"></a>            <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Photo&#39;</span><span class="ot">,</span></span>
<span id="cb21-26"><a href="#cb21-26" aria-hidden="true"></a>            <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;photo&#39;</span><span class="ot">,</span></span>
<span id="cb21-27"><a href="#cb21-27" aria-hidden="true"></a>            <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;image&#39;</span><span class="ot">,</span></span>
<span id="cb21-28"><a href="#cb21-28" aria-hidden="true"></a>            <span class="st">&#39;return_format&#39;</span> =&gt; <span class="st">&#39;array&#39;</span><span class="ot">,</span></span>
<span id="cb21-29"><a href="#cb21-29" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb21-30"><a href="#cb21-30" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb21-31"><a href="#cb21-31" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<h2 id="flexible-content-field-acf-pro">Flexible Content Field (ACF PRO)</h2>
<p><strong>Flexible Content Configuration</strong>:</p>
<div class="sourceCode" id="cb22">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_page_content&#39;</span><span class="ot">,</span></span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Page Content&#39;</span><span class="ot">,</span></span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;page_content&#39;</span><span class="ot">,</span></span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;flexible_content&#39;</span><span class="ot">,</span></span>
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true"></a>    <span class="st">&#39;button_label&#39;</span> =&gt; <span class="st">&#39;Add Content Block&#39;</span><span class="ot">,</span></span>
<span id="cb22-7"><a href="#cb22-7" aria-hidden="true"></a>    <span class="st">&#39;min&#39;</span> =&gt; <span class="dv">0</span><span class="ot">,</span></span>
<span id="cb22-8"><a href="#cb22-8" aria-hidden="true"></a>    <span class="st">&#39;max&#39;</span> =&gt; <span class="dv">20</span><span class="ot">,</span></span>
<span id="cb22-9"><a href="#cb22-9" aria-hidden="true"></a>    <span class="st">&#39;layouts&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb22-10"><a href="#cb22-10" aria-hidden="true"></a>        <span class="st">&#39;text_block&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb22-11"><a href="#cb22-11" aria-hidden="true"></a>            <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;layout_text&#39;</span><span class="ot">,</span></span>
<span id="cb22-12"><a href="#cb22-12" aria-hidden="true"></a>            <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;text_block&#39;</span><span class="ot">,</span></span>
<span id="cb22-13"><a href="#cb22-13" aria-hidden="true"></a>            <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Text Block&#39;</span><span class="ot">,</span></span>
<span id="cb22-14"><a href="#cb22-14" aria-hidden="true"></a>            <span class="st">&#39;display&#39;</span> =&gt; <span class="st">&#39;block&#39;</span><span class="ot">,</span></span>
<span id="cb22-15"><a href="#cb22-15" aria-hidden="true"></a>            <span class="st">&#39;sub_fields&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb22-16"><a href="#cb22-16" aria-hidden="true"></a>                <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb22-17"><a href="#cb22-17" aria-hidden="true"></a>                    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_heading&#39;</span><span class="ot">,</span></span>
<span id="cb22-18"><a href="#cb22-18" aria-hidden="true"></a>                    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Heading&#39;</span><span class="ot">,</span></span>
<span id="cb22-19"><a href="#cb22-19" aria-hidden="true"></a>                    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;heading&#39;</span><span class="ot">,</span></span>
<span id="cb22-20"><a href="#cb22-20" aria-hidden="true"></a>                    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;text&#39;</span><span class="ot">,</span></span>
<span id="cb22-21"><a href="#cb22-21" aria-hidden="true"></a>                <span class="ot">),</span></span>
<span id="cb22-22"><a href="#cb22-22" aria-hidden="true"></a>                <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb22-23"><a href="#cb22-23" aria-hidden="true"></a>                    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_content&#39;</span><span class="ot">,</span></span>
<span id="cb22-24"><a href="#cb22-24" aria-hidden="true"></a>                    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Content&#39;</span><span class="ot">,</span></span>
<span id="cb22-25"><a href="#cb22-25" aria-hidden="true"></a>                    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;content&#39;</span><span class="ot">,</span></span>
<span id="cb22-26"><a href="#cb22-26" aria-hidden="true"></a>                    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;wysiwyg&#39;</span><span class="ot">,</span></span>
<span id="cb22-27"><a href="#cb22-27" aria-hidden="true"></a>                <span class="ot">),</span></span>
<span id="cb22-28"><a href="#cb22-28" aria-hidden="true"></a>            <span class="ot">),</span></span>
<span id="cb22-29"><a href="#cb22-29" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb22-30"><a href="#cb22-30" aria-hidden="true"></a>        <span class="st">&#39;image_block&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb22-31"><a href="#cb22-31" aria-hidden="true"></a>            <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;layout_image&#39;</span><span class="ot">,</span></span>
<span id="cb22-32"><a href="#cb22-32" aria-hidden="true"></a>            <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;image_block&#39;</span><span class="ot">,</span></span>
<span id="cb22-33"><a href="#cb22-33" aria-hidden="true"></a>            <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Image Block&#39;</span><span class="ot">,</span></span>
<span id="cb22-34"><a href="#cb22-34" aria-hidden="true"></a>            <span class="st">&#39;display&#39;</span> =&gt; <span class="st">&#39;block&#39;</span><span class="ot">,</span></span>
<span id="cb22-35"><a href="#cb22-35" aria-hidden="true"></a>            <span class="st">&#39;sub_fields&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb22-36"><a href="#cb22-36" aria-hidden="true"></a>                <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb22-37"><a href="#cb22-37" aria-hidden="true"></a>                    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_image&#39;</span><span class="ot">,</span></span>
<span id="cb22-38"><a href="#cb22-38" aria-hidden="true"></a>                    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Image&#39;</span><span class="ot">,</span></span>
<span id="cb22-39"><a href="#cb22-39" aria-hidden="true"></a>                    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;image&#39;</span><span class="ot">,</span></span>
<span id="cb22-40"><a href="#cb22-40" aria-hidden="true"></a>                    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;image&#39;</span><span class="ot">,</span></span>
<span id="cb22-41"><a href="#cb22-41" aria-hidden="true"></a>                    <span class="st">&#39;return_format&#39;</span> =&gt; <span class="st">&#39;array&#39;</span><span class="ot">,</span></span>
<span id="cb22-42"><a href="#cb22-42" aria-hidden="true"></a>                <span class="ot">),</span></span>
<span id="cb22-43"><a href="#cb22-43" aria-hidden="true"></a>            <span class="ot">),</span></span>
<span id="cb22-44"><a href="#cb22-44" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb22-45"><a href="#cb22-45" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb22-46"><a href="#cb22-46" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<h2 id="gallery-field-acf-pro">Gallery Field (ACF PRO)</h2>
<p><strong>Gallery Configuration</strong>:</p>
<div class="sourceCode" id="cb23">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_project_gallery&#39;</span><span class="ot">,</span></span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Project Gallery&#39;</span><span class="ot">,</span></span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;project_gallery&#39;</span><span class="ot">,</span></span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;gallery&#39;</span><span class="ot">,</span></span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true"></a>    <span class="st">&#39;return_format&#39;</span> =&gt; <span class="st">&#39;array&#39;</span><span class="ot">,</span></span>
<span id="cb23-7"><a href="#cb23-7" aria-hidden="true"></a>    <span class="st">&#39;library&#39;</span> =&gt; <span class="st">&#39;all&#39;</span><span class="ot">,</span></span>
<span id="cb23-8"><a href="#cb23-8" aria-hidden="true"></a>    <span class="st">&#39;min&#39;</span> =&gt; <span class="dv">1</span><span class="ot">,</span></span>
<span id="cb23-9"><a href="#cb23-9" aria-hidden="true"></a>    <span class="st">&#39;max&#39;</span> =&gt; <span class="dv">50</span><span class="ot">,</span></span>
<span id="cb23-10"><a href="#cb23-10" aria-hidden="true"></a>    <span class="st">&#39;insert&#39;</span> =&gt; <span class="st">&#39;append&#39;</span><span class="ot">,</span> <span class="co">// append, prepend</span></span>
<span id="cb23-11"><a href="#cb23-11" aria-hidden="true"></a>    <span class="st">&#39;preview_size&#39;</span> =&gt; <span class="st">&#39;medium&#39;</span><span class="ot">,</span></span>
<span id="cb23-12"><a href="#cb23-12" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<h2 id="group-field">Group Field</h2>
<p><strong>Group Configuration</strong>:</p>
<div class="sourceCode" id="cb24">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_contact_info&#39;</span><span class="ot">,</span></span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Contact Information&#39;</span><span class="ot">,</span></span>
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;contact_info&#39;</span><span class="ot">,</span></span>
<span id="cb24-5"><a href="#cb24-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;group&#39;</span><span class="ot">,</span></span>
<span id="cb24-6"><a href="#cb24-6" aria-hidden="true"></a>    <span class="st">&#39;layout&#39;</span> =&gt; <span class="st">&#39;block&#39;</span><span class="ot">,</span> <span class="co">// block, table, row</span></span>
<span id="cb24-7"><a href="#cb24-7" aria-hidden="true"></a>    <span class="st">&#39;sub_fields&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb24-8"><a href="#cb24-8" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb24-9"><a href="#cb24-9" aria-hidden="true"></a>            <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_email&#39;</span><span class="ot">,</span></span>
<span id="cb24-10"><a href="#cb24-10" aria-hidden="true"></a>            <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Email&#39;</span><span class="ot">,</span></span>
<span id="cb24-11"><a href="#cb24-11" aria-hidden="true"></a>            <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;email&#39;</span><span class="ot">,</span></span>
<span id="cb24-12"><a href="#cb24-12" aria-hidden="true"></a>            <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;email&#39;</span><span class="ot">,</span></span>
<span id="cb24-13"><a href="#cb24-13" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb24-14"><a href="#cb24-14" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb24-15"><a href="#cb24-15" aria-hidden="true"></a>            <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_phone&#39;</span><span class="ot">,</span></span>
<span id="cb24-16"><a href="#cb24-16" aria-hidden="true"></a>            <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Phone&#39;</span><span class="ot">,</span></span>
<span id="cb24-17"><a href="#cb24-17" aria-hidden="true"></a>            <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;phone&#39;</span><span class="ot">,</span></span>
<span id="cb24-18"><a href="#cb24-18" aria-hidden="true"></a>            <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;text&#39;</span><span class="ot">,</span></span>
<span id="cb24-19"><a href="#cb24-19" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb24-20"><a href="#cb24-20" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb24-21"><a href="#cb24-21" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<h2 id="location-rules">Location Rules</h2>
<p><strong>Single Location Rule</strong>:</p>
<div class="sourceCode" id="cb25">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true"></a><span class="st">&#39;location&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true"></a>    <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true"></a>            <span class="st">&#39;param&#39;</span> =&gt; <span class="st">&#39;post_type&#39;</span><span class="ot">,</span></span>
<span id="cb25-5"><a href="#cb25-5" aria-hidden="true"></a>            <span class="st">&#39;operator&#39;</span> =&gt; <span class="st">&#39;==&#39;</span><span class="ot">,</span></span>
<span id="cb25-6"><a href="#cb25-6" aria-hidden="true"></a>            <span class="st">&#39;value&#39;</span> =&gt; <span class="st">&#39;product&#39;</span><span class="ot">,</span></span>
<span id="cb25-7"><a href="#cb25-7" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb25-8"><a href="#cb25-8" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb25-9"><a href="#cb25-9" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Multiple Location Rules (OR)</strong>:</p>
<div class="sourceCode" id="cb26">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true"></a><span class="st">&#39;location&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true"></a>    <span class="co">// Show on Products OR Pages</span></span>
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true"></a>    <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb26-4"><a href="#cb26-4" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb26-5"><a href="#cb26-5" aria-hidden="true"></a>            <span class="st">&#39;param&#39;</span> =&gt; <span class="st">&#39;post_type&#39;</span><span class="ot">,</span></span>
<span id="cb26-6"><a href="#cb26-6" aria-hidden="true"></a>            <span class="st">&#39;operator&#39;</span> =&gt; <span class="st">&#39;==&#39;</span><span class="ot">,</span></span>
<span id="cb26-7"><a href="#cb26-7" aria-hidden="true"></a>            <span class="st">&#39;value&#39;</span> =&gt; <span class="st">&#39;product&#39;</span><span class="ot">,</span></span>
<span id="cb26-8"><a href="#cb26-8" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb26-9"><a href="#cb26-9" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb26-10"><a href="#cb26-10" aria-hidden="true"></a>    <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb26-11"><a href="#cb26-11" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb26-12"><a href="#cb26-12" aria-hidden="true"></a>            <span class="st">&#39;param&#39;</span> =&gt; <span class="st">&#39;post_type&#39;</span><span class="ot">,</span></span>
<span id="cb26-13"><a href="#cb26-13" aria-hidden="true"></a>            <span class="st">&#39;operator&#39;</span> =&gt; <span class="st">&#39;==&#39;</span><span class="ot">,</span></span>
<span id="cb26-14"><a href="#cb26-14" aria-hidden="true"></a>            <span class="st">&#39;value&#39;</span> =&gt; <span class="st">&#39;page&#39;</span><span class="ot">,</span></span>
<span id="cb26-15"><a href="#cb26-15" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb26-16"><a href="#cb26-16" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb26-17"><a href="#cb26-17" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Multiple Conditions (AND)</strong>:</p>
<div class="sourceCode" id="cb27">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true"></a><span class="st">&#39;location&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true"></a>    <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true"></a>        <span class="co">// Show on Pages AND page template is &quot;Full Width&quot;</span></span>
<span id="cb27-4"><a href="#cb27-4" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb27-5"><a href="#cb27-5" aria-hidden="true"></a>            <span class="st">&#39;param&#39;</span> =&gt; <span class="st">&#39;post_type&#39;</span><span class="ot">,</span></span>
<span id="cb27-6"><a href="#cb27-6" aria-hidden="true"></a>            <span class="st">&#39;operator&#39;</span> =&gt; <span class="st">&#39;==&#39;</span><span class="ot">,</span></span>
<span id="cb27-7"><a href="#cb27-7" aria-hidden="true"></a>            <span class="st">&#39;value&#39;</span> =&gt; <span class="st">&#39;page&#39;</span><span class="ot">,</span></span>
<span id="cb27-8"><a href="#cb27-8" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb27-9"><a href="#cb27-9" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb27-10"><a href="#cb27-10" aria-hidden="true"></a>            <span class="st">&#39;param&#39;</span> =&gt; <span class="st">&#39;page_template&#39;</span><span class="ot">,</span></span>
<span id="cb27-11"><a href="#cb27-11" aria-hidden="true"></a>            <span class="st">&#39;operator&#39;</span> =&gt; <span class="st">&#39;==&#39;</span><span class="ot">,</span></span>
<span id="cb27-12"><a href="#cb27-12" aria-hidden="true"></a>            <span class="st">&#39;value&#39;</span> =&gt; <span class="st">&#39;template-full-width.php&#39;</span><span class="ot">,</span></span>
<span id="cb27-13"><a href="#cb27-13" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb27-14"><a href="#cb27-14" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb27-15"><a href="#cb27-15" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Common Location Parameters</strong>:</p>
<div class="sourceCode" id="cb28">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true"></a><span class="co">// Post Type</span></span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true"></a><span class="st">&#39;param&#39;</span> =&gt; <span class="st">&#39;post_type&#39;</span></span>
<span id="cb28-3"><a href="#cb28-3" aria-hidden="true"></a><span class="st">&#39;param&#39;</span> =&gt; <span class="st">&#39;post&#39;</span></span>
<span id="cb28-4"><a href="#cb28-4" aria-hidden="true"></a><span class="st">&#39;param&#39;</span> =&gt; <span class="st">&#39;page&#39;</span></span>
<span id="cb28-5"><a href="#cb28-5" aria-hidden="true"></a></span>
<span id="cb28-6"><a href="#cb28-6" aria-hidden="true"></a><span class="co">// Page Template</span></span>
<span id="cb28-7"><a href="#cb28-7" aria-hidden="true"></a><span class="st">&#39;param&#39;</span> =&gt; <span class="st">&#39;page_template&#39;</span></span>
<span id="cb28-8"><a href="#cb28-8" aria-hidden="true"></a></span>
<span id="cb28-9"><a href="#cb28-9" aria-hidden="true"></a><span class="co">// Taxonomy</span></span>
<span id="cb28-10"><a href="#cb28-10" aria-hidden="true"></a><span class="st">&#39;param&#39;</span> =&gt; <span class="st">&#39;post_taxonomy&#39;</span></span>
<span id="cb28-11"><a href="#cb28-11" aria-hidden="true"></a><span class="st">&#39;param&#39;</span> =&gt; <span class="st">&#39;post_category&#39;</span></span>
<span id="cb28-12"><a href="#cb28-12" aria-hidden="true"></a></span>
<span id="cb28-13"><a href="#cb28-13" aria-hidden="true"></a><span class="co">// User Role</span></span>
<span id="cb28-14"><a href="#cb28-14" aria-hidden="true"></a><span class="st">&#39;param&#39;</span> =&gt; <span class="st">&#39;current_user_role&#39;</span></span>
<span id="cb28-15"><a href="#cb28-15" aria-hidden="true"></a></span>
<span id="cb28-16"><a href="#cb28-16" aria-hidden="true"></a><span class="co">// Options Page</span></span>
<span id="cb28-17"><a href="#cb28-17" aria-hidden="true"></a><span class="st">&#39;param&#39;</span> =&gt; <span class="st">&#39;options_page&#39;</span></span></code></pre>
</div>
<h2 id="conditional-logic">Conditional Logic</h2>
<p><strong>Show Field Based on Another Field</strong>:</p>
<div class="sourceCode" id="cb29">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_enable_feature&#39;</span><span class="ot">,</span></span>
<span id="cb29-3"><a href="#cb29-3" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Enable Feature&#39;</span><span class="ot">,</span></span>
<span id="cb29-4"><a href="#cb29-4" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;enable_feature&#39;</span><span class="ot">,</span></span>
<span id="cb29-5"><a href="#cb29-5" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;true_false&#39;</span><span class="ot">,</span></span>
<span id="cb29-6"><a href="#cb29-6" aria-hidden="true"></a><span class="ot">),</span></span>
<span id="cb29-7"><a href="#cb29-7" aria-hidden="true"></a><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb29-8"><a href="#cb29-8" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_feature_settings&#39;</span><span class="ot">,</span></span>
<span id="cb29-9"><a href="#cb29-9" aria-hidden="true"></a>    <span class="st">&#39;label&#39;</span> =&gt; <span class="st">&#39;Feature Settings&#39;</span><span class="ot">,</span></span>
<span id="cb29-10"><a href="#cb29-10" aria-hidden="true"></a>    <span class="st">&#39;name&#39;</span> =&gt; <span class="st">&#39;feature_settings&#39;</span><span class="ot">,</span></span>
<span id="cb29-11"><a href="#cb29-11" aria-hidden="true"></a>    <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;text&#39;</span><span class="ot">,</span></span>
<span id="cb29-12"><a href="#cb29-12" aria-hidden="true"></a>    <span class="st">&#39;conditional_logic&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb29-13"><a href="#cb29-13" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb29-14"><a href="#cb29-14" aria-hidden="true"></a>            <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb29-15"><a href="#cb29-15" aria-hidden="true"></a>                <span class="st">&#39;field&#39;</span> =&gt; <span class="st">&#39;field_enable_feature&#39;</span><span class="ot">,</span></span>
<span id="cb29-16"><a href="#cb29-16" aria-hidden="true"></a>                <span class="st">&#39;operator&#39;</span> =&gt; <span class="st">&#39;==&#39;</span><span class="ot">,</span></span>
<span id="cb29-17"><a href="#cb29-17" aria-hidden="true"></a>                <span class="st">&#39;value&#39;</span> =&gt; <span class="st">&#39;1&#39;</span><span class="ot">,</span></span>
<span id="cb29-18"><a href="#cb29-18" aria-hidden="true"></a>            <span class="ot">),</span></span>
<span id="cb29-19"><a href="#cb29-19" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb29-20"><a href="#cb29-20" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb29-21"><a href="#cb29-21" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Multiple Conditions (AND)</strong>:</p>
<div class="sourceCode" id="cb30">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true"></a><span class="st">&#39;conditional_logic&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true"></a>    <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb30-3"><a href="#cb30-3" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb30-4"><a href="#cb30-4" aria-hidden="true"></a>            <span class="st">&#39;field&#39;</span> =&gt; <span class="st">&#39;field_type&#39;</span><span class="ot">,</span></span>
<span id="cb30-5"><a href="#cb30-5" aria-hidden="true"></a>            <span class="st">&#39;operator&#39;</span> =&gt; <span class="st">&#39;==&#39;</span><span class="ot">,</span></span>
<span id="cb30-6"><a href="#cb30-6" aria-hidden="true"></a>            <span class="st">&#39;value&#39;</span> =&gt; <span class="st">&#39;premium&#39;</span><span class="ot">,</span></span>
<span id="cb30-7"><a href="#cb30-7" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb30-8"><a href="#cb30-8" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb30-9"><a href="#cb30-9" aria-hidden="true"></a>            <span class="st">&#39;field&#39;</span> =&gt; <span class="st">&#39;field_active&#39;</span><span class="ot">,</span></span>
<span id="cb30-10"><a href="#cb30-10" aria-hidden="true"></a>            <span class="st">&#39;operator&#39;</span> =&gt; <span class="st">&#39;==&#39;</span><span class="ot">,</span></span>
<span id="cb30-11"><a href="#cb30-11" aria-hidden="true"></a>            <span class="st">&#39;value&#39;</span> =&gt; <span class="st">&#39;1&#39;</span><span class="ot">,</span></span>
<span id="cb30-12"><a href="#cb30-12" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb30-13"><a href="#cb30-13" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb30-14"><a href="#cb30-14" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<p><strong>Multiple Conditions (OR)</strong>:</p>
<div class="sourceCode" id="cb31">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true"></a><span class="st">&#39;conditional_logic&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true"></a>    <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb31-3"><a href="#cb31-3" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb31-4"><a href="#cb31-4" aria-hidden="true"></a>            <span class="st">&#39;field&#39;</span> =&gt; <span class="st">&#39;field_color&#39;</span><span class="ot">,</span></span>
<span id="cb31-5"><a href="#cb31-5" aria-hidden="true"></a>            <span class="st">&#39;operator&#39;</span> =&gt; <span class="st">&#39;==&#39;</span><span class="ot">,</span></span>
<span id="cb31-6"><a href="#cb31-6" aria-hidden="true"></a>            <span class="st">&#39;value&#39;</span> =&gt; <span class="st">&#39;red&#39;</span><span class="ot">,</span></span>
<span id="cb31-7"><a href="#cb31-7" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb31-8"><a href="#cb31-8" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb31-9"><a href="#cb31-9" aria-hidden="true"></a>    <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb31-10"><a href="#cb31-10" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb31-11"><a href="#cb31-11" aria-hidden="true"></a>            <span class="st">&#39;field&#39;</span> =&gt; <span class="st">&#39;field_color&#39;</span><span class="ot">,</span></span>
<span id="cb31-12"><a href="#cb31-12" aria-hidden="true"></a>            <span class="st">&#39;operator&#39;</span> =&gt; <span class="st">&#39;==&#39;</span><span class="ot">,</span></span>
<span id="cb31-13"><a href="#cb31-13" aria-hidden="true"></a>            <span class="st">&#39;value&#39;</span> =&gt; <span class="st">&#39;blue&#39;</span><span class="ot">,</span></span>
<span id="cb31-14"><a href="#cb31-14" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb31-15"><a href="#cb31-15" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb31-16"><a href="#cb31-16" aria-hidden="true"></a><span class="ot">)</span></span></code></pre>
</div>
<h2 id="dynamic-field-registration">Dynamic Field Registration</h2>
<p><strong>Generate Fields from Array</strong>:</p>
<div class="sourceCode" id="cb32">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true"></a><span class="kw">function</span> mytheme_generate_dynamic_fields<span class="ot">()</span> {</span>
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true"></a>    <span class="kw">$social_networks</span> = <span class="kw">array</span><span class="ot">(</span><span class="st">&#39;facebook&#39;</span><span class="ot">,</span> <span class="st">&#39;twitter&#39;</span><span class="ot">,</span> <span class="st">&#39;instagram&#39;</span><span class="ot">,</span> <span class="st">&#39;linkedin&#39;</span><span class="ot">);</span></span>
<span id="cb32-3"><a href="#cb32-3" aria-hidden="true"></a>    <span class="kw">$fields</span> = <span class="kw">array</span><span class="ot">();</span></span>
<span id="cb32-4"><a href="#cb32-4" aria-hidden="true"></a></span>
<span id="cb32-5"><a href="#cb32-5" aria-hidden="true"></a>    <span class="kw">foreach</span> <span class="ot">(</span><span class="kw">$social_networks</span> <span class="kw">as</span> <span class="kw">$network</span><span class="ot">)</span> {</span>
<span id="cb32-6"><a href="#cb32-6" aria-hidden="true"></a>        <span class="kw">$fields</span><span class="ot">[]</span> = <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb32-7"><a href="#cb32-7" aria-hidden="true"></a>            <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_&#39;</span> . <span class="kw">$network</span><span class="ot">,</span></span>
<span id="cb32-8"><a href="#cb32-8" aria-hidden="true"></a>            <span class="st">&#39;label&#39;</span> =&gt; <span class="fu">ucfirst</span><span class="ot">(</span><span class="kw">$network</span><span class="ot">)</span> . <span class="st">&#39; URL&#39;</span><span class="ot">,</span></span>
<span id="cb32-9"><a href="#cb32-9" aria-hidden="true"></a>            <span class="st">&#39;name&#39;</span> =&gt; <span class="kw">$network</span> . <span class="st">&#39;_url&#39;</span><span class="ot">,</span></span>
<span id="cb32-10"><a href="#cb32-10" aria-hidden="true"></a>            <span class="st">&#39;type&#39;</span> =&gt; <span class="st">&#39;url&#39;</span><span class="ot">,</span></span>
<span id="cb32-11"><a href="#cb32-11" aria-hidden="true"></a>        <span class="ot">);</span></span>
<span id="cb32-12"><a href="#cb32-12" aria-hidden="true"></a>    }</span>
<span id="cb32-13"><a href="#cb32-13" aria-hidden="true"></a></span>
<span id="cb32-14"><a href="#cb32-14" aria-hidden="true"></a>    acf_add_local_field_group<span class="ot">(</span><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb32-15"><a href="#cb32-15" aria-hidden="true"></a>        <span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;group_social_links&#39;</span><span class="ot">,</span></span>
<span id="cb32-16"><a href="#cb32-16" aria-hidden="true"></a>        <span class="st">&#39;title&#39;</span> =&gt; <span class="st">&#39;Social Links&#39;</span><span class="ot">,</span></span>
<span id="cb32-17"><a href="#cb32-17" aria-hidden="true"></a>        <span class="st">&#39;fields&#39;</span> =&gt; <span class="kw">$fields</span><span class="ot">,</span></span>
<span id="cb32-18"><a href="#cb32-18" aria-hidden="true"></a>        <span class="st">&#39;location&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb32-19"><a href="#cb32-19" aria-hidden="true"></a>            <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb32-20"><a href="#cb32-20" aria-hidden="true"></a>                <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb32-21"><a href="#cb32-21" aria-hidden="true"></a>                    <span class="st">&#39;param&#39;</span> =&gt; <span class="st">&#39;options_page&#39;</span><span class="ot">,</span></span>
<span id="cb32-22"><a href="#cb32-22" aria-hidden="true"></a>                    <span class="st">&#39;operator&#39;</span> =&gt; <span class="st">&#39;==&#39;</span><span class="ot">,</span></span>
<span id="cb32-23"><a href="#cb32-23" aria-hidden="true"></a>                    <span class="st">&#39;value&#39;</span> =&gt; <span class="st">&#39;acf-options&#39;</span><span class="ot">,</span></span>
<span id="cb32-24"><a href="#cb32-24" aria-hidden="true"></a>                <span class="ot">),</span></span>
<span id="cb32-25"><a href="#cb32-25" aria-hidden="true"></a>            <span class="ot">),</span></span>
<span id="cb32-26"><a href="#cb32-26" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb32-27"><a href="#cb32-27" aria-hidden="true"></a>    <span class="ot">));</span></span>
<span id="cb32-28"><a href="#cb32-28" aria-hidden="true"></a>}</span>
<span id="cb32-29"><a href="#cb32-29" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;acf/init&#39;</span><span class="ot">,</span> <span class="st">&#39;mytheme_generate_dynamic_fields&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="best-practices">Best Practices</h2>
<p><strong>Unique Keys</strong>:</p>
<div class="sourceCode" id="cb33">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true"></a><span class="co">// Good - unique, descriptive keys</span></span>
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true"></a><span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_product_price&#39;</span></span>
<span id="cb33-3"><a href="#cb33-3" aria-hidden="true"></a><span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;group_product_details&#39;</span></span>
<span id="cb33-4"><a href="#cb33-4" aria-hidden="true"></a></span>
<span id="cb33-5"><a href="#cb33-5" aria-hidden="true"></a><span class="co">// Bad - generic, duplicate-prone keys</span></span>
<span id="cb33-6"><a href="#cb33-6" aria-hidden="true"></a><span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;field_1&#39;</span></span>
<span id="cb33-7"><a href="#cb33-7" aria-hidden="true"></a><span class="st">&#39;key&#39;</span> =&gt; <span class="st">&#39;group_1&#39;</span></span></code></pre>
</div>
<p><strong>Organize in Separate Files</strong>:</p>
<pre><code>theme/
├── inc/
│   └── acf/
│       ├── field-groups.php
│       ├── product-fields.php
│       ├── page-fields.php
│       └── options-fields.php</code></pre>
<p><strong>Include in functions.php</strong>:</p>
<div class="sourceCode" id="cb35">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true"></a><span class="kw">require_once</span> get_template_directory<span class="ot">()</span> . <span class="st">&#39;/inc/acf/field-groups.php&#39;</span><span class="ot">;</span></span></code></pre>
</div>
<p><strong>Use Constants for Keys</strong>:</p>
<div class="sourceCode" id="cb36">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true"></a><span class="fu">define</span><span class="ot">(</span><span class="st">&#39;MYTHEME_PRODUCT_GROUP&#39;</span><span class="ot">,</span> <span class="st">&#39;group_product_details&#39;</span><span class="ot">);</span></span>
<span id="cb36-2"><a href="#cb36-2" aria-hidden="true"></a><span class="fu">define</span><span class="ot">(</span><span class="st">&#39;MYTHEME_PRICE_FIELD&#39;</span><span class="ot">,</span> <span class="st">&#39;field_product_price&#39;</span><span class="ot">);</span></span>
<span id="cb36-3"><a href="#cb36-3" aria-hidden="true"></a></span>
<span id="cb36-4"><a href="#cb36-4" aria-hidden="true"></a>acf_add_local_field_group<span class="ot">(</span><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb36-5"><a href="#cb36-5" aria-hidden="true"></a>    <span class="st">&#39;key&#39;</span> =&gt; <span class="kw">MYTHEME_PRODUCT_GROUP</span><span class="ot">,</span></span>
<span id="cb36-6"><a href="#cb36-6" aria-hidden="true"></a>    <span class="st">&#39;fields&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb36-7"><a href="#cb36-7" aria-hidden="true"></a>        <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb36-8"><a href="#cb36-8" aria-hidden="true"></a>            <span class="st">&#39;key&#39;</span> =&gt; <span class="kw">MYTHEME_PRICE_FIELD</span><span class="ot">,</span></span>
<span id="cb36-9"><a href="#cb36-9" aria-hidden="true"></a>            <span class="co">// ...</span></span>
<span id="cb36-10"><a href="#cb36-10" aria-hidden="true"></a>        <span class="ot">),</span></span>
<span id="cb36-11"><a href="#cb36-11" aria-hidden="true"></a>    <span class="ot">),</span></span>
<span id="cb36-12"><a href="#cb36-12" aria-hidden="true"></a><span class="ot">));</span></span></code></pre>
</div>
<h2 id="conclusion">Conclusion</h2>
<p>Programmatic ACF field registration with acf_add_local_field_group() enables version-controlled field configurations eliminating manual UI setup and database dependencies. Register field groups with unique keys and comprehensive field arrays, implement location rules for targeted display, add conditional logic for dynamic field visibility, and organize field registrations in separate files for maintainability. Programmatic registration ensures consistent ACF deployments across environments while providing code review capabilities and automatic synchronization through version control systems.</p>
<h2 id="external-links">External Links</h2>
<ol type="1">
<li><a href="https://www.advancedcustomfields.com/resources/register-fields-via-php/">acf_add_local_field_group() Documentation</a></li>
<li><a href="https://www.advancedcustomfields.com/resources/#field-types">Field Type Settings</a></li>
<li><a href="https://www.advancedcustomfields.com/resources/location/">Location Rules</a></li>
<li><a href="https://www.advancedcustomfields.com/resources/conditional-logic/">Conditional Logic</a></li>
<li><a href="https://www.advancedcustomfields.com/resources/local-json/">Local JSON Feature</a></li>
</ol>
<h2 id="call-to-action">Call to Action</h2>
<p>Programmatic field configurations need backup protection. <a href="https://backupcopilotplugin.com/">Backup Copilot Pro</a> backs up your WordPress theme files and ACF code automatically. Safeguard your version-controlled fields—start your free 30-day trial today!</p>
<p>The post <a href="https://developryplugins.com/how-to-create-acf-field-groups-programmatically-with-php/">How to Create ACF Field Groups Programmatically with PHP</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Create XML Sitemaps in WordPress for Better Indexing</title>
		<link>https://developryplugins.com/how-to-create-xml-sitemaps-in-wordpress-for-better-indexing/</link>
		
		<dc:creator><![CDATA[Krasen Slavov]]></dc:creator>
		<pubDate>Mon, 20 Jul 2026 09:00:00 +0000</pubDate>
				<category><![CDATA[WordPress SEO & Digital Marketing]]></category>
		<category><![CDATA[google indexing]]></category>
		<category><![CDATA[search console]]></category>
		<category><![CDATA[seo fundamentals]]></category>
		<category><![CDATA[site crawling]]></category>
		<category><![CDATA[xml sitemap]]></category>
		<guid isPermaLink="false">https://developryplugins.com/?p=135</guid>

					<description><![CDATA[<p>XML sitemaps help search engines discover and index WordPress content efficiently. These structured files list all important URLs, guiding crawlers to fresh content and indicating update priorities. This comprehensive guide...</p>
<p>The post <a href="https://developryplugins.com/how-to-create-xml-sitemaps-in-wordpress-for-better-indexing/">How to Create XML Sitemaps in WordPress for Better Indexing</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><!-- @format --></p>
<p>XML sitemaps help search engines discover and index WordPress content efficiently. These structured files list all important URLs, guiding crawlers to fresh content and indicating update priorities. This comprehensive guide teaches XML sitemap creation, optimization, submission to search engines, and troubleshooting for maximum indexing efficiency.</p>
<h2 id="what-is-an-xml-sitemap">What Is an XML Sitemap</h2>
<p>XML sitemaps are machine-readable files listing website URLs with metadata about content freshness, update frequency, and relative importance. Search engines use sitemaps to discover pages, especially on large sites or sites with poor internal linking.</p>
<p><strong>Basic XML Sitemap Structure</strong>:</p>
<div class="sourceCode" id="cb1">
<pre class="sourceCode xml"><code class="sourceCode xml"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true"></a><span class="kw">&lt;?xml</span> version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;<span class="kw">?&gt;</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true"></a><span class="kw">&lt;urlset</span><span class="ot"> xmlns=</span><span class="st">&quot;http://www.sitemaps.org/schemas/sitemap/0.9&quot;</span><span class="kw">&gt;</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true"></a>  <span class="kw">&lt;url&gt;</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true"></a>    <span class="kw">&lt;loc&gt;</span>https://example.com/page/<span class="kw">&lt;/loc&gt;</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true"></a>    <span class="kw">&lt;lastmod&gt;</span>2025-01-15<span class="kw">&lt;/lastmod&gt;</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true"></a>    <span class="kw">&lt;changefreq&gt;</span>weekly<span class="kw">&lt;/changefreq&gt;</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true"></a>    <span class="kw">&lt;priority&gt;</span>0.8<span class="kw">&lt;/priority&gt;</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true"></a>  <span class="kw">&lt;/url&gt;</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true"></a><span class="kw">&lt;/urlset&gt;</span></span></code></pre>
</div>
<h2 id="why-xml-sitemaps-matter-for-seo">Why XML Sitemaps Matter for SEO</h2>
<p><strong>Faster Indexing</strong>: New content discovered within hours instead of days.</p>
<p><strong>Complete Coverage</strong>: Ensures all important pages indexed, especially those with few backlinks.</p>
<p><strong>Crawl Efficiency</strong>: Guides search bots to updated content first.</p>
<p><strong>Large Site Management</strong>: Critical for sites with 100+ pages.</p>
<p><strong>Content Prioritization</strong>: Indicates which pages matter most.</p>
<h2 id="wordpress-default-sitemap-wordpress-5.5">WordPress Default Sitemap (WordPress 5.5+)</h2>
<p>WordPress generates basic XML sitemaps automatically since version 5.5.</p>
<p><strong>Access Default Sitemap</strong>:</p>
<pre><code>https://yoursite.com/wp-sitemap.xml</code></pre>
<p><strong>Sitemap Index Structure</strong>:</p>
<ul>
<li>wp-sitemap-posts-post-1.xml (blog posts)</li>
<li>wp-sitemap-posts-page-1.xml (pages)</li>
<li>wp-sitemap-taxonomies-category-1.xml (categories)</li>
<li>wp-sitemap-taxonomies-post_tag-1.xml (tags)</li>
<li>wp-sitemap-users-1.xml (author archives)</li>
</ul>
<p><strong>Limitations</strong>:</p>
<ul>
<li>Basic functionality only</li>
<li>No priority or change frequency</li>
<li>Limited customization options</li>
<li>No advanced features</li>
</ul>
<h2 id="creating-advanced-sitemaps-with-yoast-seo">Creating Advanced Sitemaps with Yoast SEO</h2>
<p>Yoast SEO provides more comprehensive sitemap functionality.</p>
<p><strong>Enabling Yoast Sitemap</strong>:</p>
<ol type="1">
<li>Install Yoast SEO plugin</li>
<li>Navigate to SEO → General → Features</li>
<li>Enable XML sitemaps</li>
<li>Access sitemap at: yoursite.com/sitemap_index.xml</li>
</ol>
<p><strong>Yoast Sitemap Features</strong>:</p>
<ul>
<li>Automatic updates</li>
<li>Excluded content types</li>
<li>Custom post type inclusion</li>
<li>Taxonomy sitemaps</li>
<li>Image sitemaps</li>
<li>News sitemaps (premium)</li>
</ul>
<p><strong>Configuring Yoast Sitemap</strong>:</p>
<ol type="1">
<li>Go to SEO → Search Appearance</li>
<li>Select content type (Posts, Pages, etc.)</li>
<li>Toggle “Show in search results”</li>
<li>Set noindex for unwanted content</li>
</ol>
<h2 id="creating-sitemaps-with-rank-math">Creating Sitemaps with Rank Math</h2>
<p>Rank Math offers similar advanced sitemap features.</p>
<p><strong>Enabling Rank Math Sitemap</strong>:</p>
<ol type="1">
<li>Install Rank Math plugin</li>
<li>Navigate to Rank Math → Sitemap Settings</li>
<li>Enable sitemaps</li>
<li>Access at: yoursite.com/sitemap_index.xml</li>
</ol>
<p><strong>Rank Math Features</strong>:</p>
<ul>
<li>Automatic generation</li>
<li>Exclude specific URLs</li>
<li>Ping search engines on update</li>
<li>Author/date archive inclusion</li>
<li>Custom sitemap links</li>
</ul>
<h2 id="manual-xml-sitemap-creation">Manual XML Sitemap Creation</h2>
<p>For custom requirements, generate sitemaps programmatically.</p>
<p><strong>Simple Sitemap Function</strong>:</p>
<div class="sourceCode" id="cb3">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true"></a><span class="kw">function</span> dprt_generate_sitemap<span class="ot">()</span> {</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true"></a>    <span class="kw">$posts</span> = get_posts<span class="ot">(</span><span class="kw">array</span><span class="ot">(</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true"></a>        <span class="st">&#39;post_type&#39;</span> =&gt; <span class="st">&#39;post&#39;</span><span class="ot">,</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true"></a>        <span class="st">&#39;post_status&#39;</span> =&gt; <span class="st">&#39;publish&#39;</span><span class="ot">,</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true"></a>        <span class="st">&#39;numberposts&#39;</span> =&gt; <span class="dv">-1</span><span class="ot">,</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true"></a>        <span class="st">&#39;orderby&#39;</span> =&gt; <span class="st">&#39;modified&#39;</span><span class="ot">,</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true"></a>    <span class="ot">));</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true"></a></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true"></a>    <span class="kw">$sitemap</span> = <span class="st">&#39;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true"></a>    <span class="kw">$sitemap</span> .= <span class="st">&#39;&lt;urlset xmlns=&quot;http://www.sitemaps.org/schemas/sitemap/0.9&quot;&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true"></a></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true"></a>    <span class="kw">foreach</span> <span class="ot">(</span><span class="kw">$posts</span> <span class="kw">as</span> <span class="kw">$post</span><span class="ot">)</span> {</span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true"></a>        <span class="kw">$sitemap</span> .= <span class="st">&#39;&lt;url&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true"></a>        <span class="kw">$sitemap</span> .= <span class="st">&#39;&lt;loc&gt;&#39;</span> . get_permalink<span class="ot">(</span><span class="kw">$post</span>-&gt;<span class="kw">ID</span><span class="ot">)</span> . <span class="st">&#39;&lt;/loc&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true"></a>        <span class="kw">$sitemap</span> .= <span class="st">&#39;&lt;lastmod&gt;&#39;</span> . get_the_modified_date<span class="ot">(</span><span class="st">&#39;c&#39;</span><span class="ot">,</span> <span class="kw">$post</span>-&gt;<span class="kw">ID</span><span class="ot">)</span> . <span class="st">&#39;&lt;/lastmod&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true"></a>        <span class="kw">$sitemap</span> .= <span class="st">&#39;&lt;changefreq&gt;weekly&lt;/changefreq&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true"></a>        <span class="kw">$sitemap</span> .= <span class="st">&#39;&lt;priority&gt;0.8&lt;/priority&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true"></a>        <span class="kw">$sitemap</span> .= <span class="st">&#39;&lt;/url&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true"></a>    }</span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true"></a></span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true"></a>    <span class="kw">$sitemap</span> .= <span class="st">&#39;&lt;/urlset&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true"></a></span>
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true"></a>    <span class="fu">file_put_contents</span><span class="ot">(</span><span class="kw">ABSPATH</span> . <span class="st">&#39;sitemap.xml&#39;</span><span class="ot">,</span> <span class="kw">$sitemap</span><span class="ot">);</span></span>
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true"></a>}</span>
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true"></a></span>
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true"></a><span class="co">// Generate sitemap when post published/updated</span></span>
<span id="cb3-27"><a href="#cb3-27" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;save_post&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_generate_sitemap&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="sitemap-best-practices">Sitemap Best Practices</h2>
<p><strong>1. Include Only Indexable URLs</strong></p>
<p>Exclude:</p>
<ul>
<li>Duplicate content</li>
<li>Noindexed pages</li>
<li>Login/admin pages</li>
<li>Thank you pages</li>
<li>Cart/checkout pages</li>
</ul>
<p><strong>2. Keep Under 50,000 URLs</strong></p>
<p>Split large sitemaps into multiple files.</p>
<p><strong>Sitemap Index Example</strong>:</p>
<div class="sourceCode" id="cb4">
<pre class="sourceCode xml"><code class="sourceCode xml"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true"></a><span class="kw">&lt;?xml</span> version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;<span class="kw">?&gt;</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true"></a><span class="kw">&lt;sitemapindex</span><span class="ot"> xmlns=</span><span class="st">&quot;http://www.sitemaps.org/schemas/sitemap/0.9&quot;</span><span class="kw">&gt;</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true"></a>  <span class="kw">&lt;sitemap&gt;</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true"></a>    <span class="kw">&lt;loc&gt;</span>https://example.com/sitemap-posts.xml<span class="kw">&lt;/loc&gt;</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true"></a>    <span class="kw">&lt;lastmod&gt;</span>2025-01-15<span class="kw">&lt;/lastmod&gt;</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true"></a>  <span class="kw">&lt;/sitemap&gt;</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true"></a>  <span class="kw">&lt;sitemap&gt;</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true"></a>    <span class="kw">&lt;loc&gt;</span>https://example.com/sitemap-pages.xml<span class="kw">&lt;/loc&gt;</span></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true"></a>    <span class="kw">&lt;lastmod&gt;</span>2025-01-10<span class="kw">&lt;/lastmod&gt;</span></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true"></a>  <span class="kw">&lt;/sitemap&gt;</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true"></a><span class="kw">&lt;/sitemapindex&gt;</span></span></code></pre>
</div>
<p><strong>3. Keep File Size Under 50MB</strong></p>
<p>Compress large sitemaps with gzip.</p>
<p><strong>4. Update Regularly</strong></p>
<p>Regenerate when content published or updated.</p>
<p><strong>5. Use Accurate lastmod Dates</strong></p>
<p>Helps search engines prioritize crawling fresh content.</p>
<h2 id="submitting-sitemap-to-google">Submitting Sitemap to Google</h2>
<p><strong>Google Search Console</strong>:</p>
<ol type="1">
<li>Log into search.google.com/search-console</li>
<li>Select property</li>
<li>Navigate to Sitemaps (left menu)</li>
<li>Enter sitemap URL: sitemap_index.xml</li>
<li>Click Submit</li>
</ol>
<p><strong>Verify Submission</strong>: Check “Discovered” and “Submitted” URL counts match expectations.</p>
<p><strong>Automatic Ping</strong> (optional):</p>
<div class="sourceCode" id="cb5">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true"></a><span class="kw">function</span> dprt_ping_google<span class="ot">(</span><span class="kw">$post_id</span><span class="ot">)</span> {</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span>get_post_status<span class="ot">(</span><span class="kw">$post_id</span><span class="ot">)</span> == <span class="st">&#39;publish&#39;</span><span class="ot">)</span> {</span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true"></a>        <span class="kw">$sitemap_url</span> = <span class="fu">urlencode</span><span class="ot">(</span>home_url<span class="ot">(</span><span class="st">&#39;/sitemap_index.xml&#39;</span><span class="ot">));</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true"></a>        wp_remote_get<span class="ot">(</span><span class="st">&#39;http://www.google.com/ping?sitemap=&#39;</span> . <span class="kw">$sitemap_url</span><span class="ot">);</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true"></a>    }</span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true"></a>}</span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;publish_post&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_ping_google&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="submitting-to-other-search-engines">Submitting to Other Search Engines</h2>
<p><strong>Bing Webmaster Tools</strong>:</p>
<ol type="1">
<li>Visit bing.com/webmasters</li>
<li>Add site</li>
<li>Navigate to Sitemaps</li>
<li>Submit sitemap URL</li>
</ol>
<p><strong>Yandex Webmaster</strong>:</p>
<ol type="1">
<li>Visit webmaster.yandex.com</li>
<li>Add site</li>
<li>Go to Indexing → Sitemap files</li>
<li>Add sitemap URL</li>
</ol>
<h2 id="image-sitemaps">Image Sitemaps</h2>
<p>Help Google discover and index images.</p>
<p><strong>Image Sitemap Structure</strong>:</p>
<div class="sourceCode" id="cb6">
<pre class="sourceCode xml"><code class="sourceCode xml"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true"></a><span class="kw">&lt;url&gt;</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true"></a>  <span class="kw">&lt;loc&gt;</span>https://example.com/post-with-images/<span class="kw">&lt;/loc&gt;</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true"></a>  <span class="kw">&lt;image:image&gt;</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true"></a>    <span class="kw">&lt;image:loc&gt;</span>https://example.com/image.jpg<span class="kw">&lt;/image:loc&gt;</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true"></a>    <span class="kw">&lt;image:caption&gt;</span>Image caption here<span class="kw">&lt;/image:caption&gt;</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true"></a>    <span class="kw">&lt;image:title&gt;</span>Image title<span class="kw">&lt;/image:title&gt;</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true"></a>  <span class="kw">&lt;/image:image&gt;</span></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true"></a><span class="kw">&lt;/url&gt;</span></span></code></pre>
</div>
<p>Yoast SEO automatically includes images in sitemaps.</p>
<h2 id="video-sitemaps">Video Sitemaps</h2>
<p>Enhance video content discovery.</p>
<p><strong>Video Sitemap Example</strong>:</p>
<div class="sourceCode" id="cb7">
<pre class="sourceCode xml"><code class="sourceCode xml"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true"></a><span class="kw">&lt;url&gt;</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true"></a>  <span class="kw">&lt;loc&gt;</span>https://example.com/video-post/<span class="kw">&lt;/loc&gt;</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true"></a>  <span class="kw">&lt;video:video&gt;</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true"></a>    <span class="kw">&lt;video:thumbnail_loc&gt;</span>https://example.com/thumb.jpg<span class="kw">&lt;/video:thumbnail_loc&gt;</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true"></a>    <span class="kw">&lt;video:title&gt;</span>Video Title<span class="kw">&lt;/video:title&gt;</span></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true"></a>    <span class="kw">&lt;video:description&gt;</span>Video description<span class="kw">&lt;/video:description&gt;</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true"></a>    <span class="kw">&lt;video:content_loc&gt;</span>https://example.com/video.mp4<span class="kw">&lt;/video:content_loc&gt;</span></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true"></a>    <span class="kw">&lt;video:duration&gt;</span>600<span class="kw">&lt;/video:duration&gt;</span></span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true"></a>  <span class="kw">&lt;/video:video&gt;</span></span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true"></a><span class="kw">&lt;/url&gt;</span></span></code></pre>
</div>
<h2 id="excluding-urls-from-sitemap">Excluding URLs from Sitemap</h2>
<p><strong>Yoast SEO &#8211; Individual Posts</strong>:</p>
<ol type="1">
<li>Edit post/page</li>
<li>Scroll to Yoast meta box</li>
<li>Advanced tab</li>
<li>Set “Allow search engines to show this Post in search results?” to No</li>
</ol>
<p><strong>Yoast SEO &#8211; Entire Post Types</strong>: SEO → Search Appearance → Content Types → Toggle off</p>
<p><strong>Rank Math &#8211; Individual Posts</strong>: Rank Math meta box → Advanced → Robots Meta → Select noindex</p>
<p><strong>Manual Exclusion</strong>:</p>
<div class="sourceCode" id="cb8">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;wpseo_sitemap_exclude_post_type&#39;</span><span class="ot">,</span> <span class="kw">function</span><span class="ot">(</span><span class="kw">$excluded</span><span class="ot">,</span> <span class="kw">$post_type</span><span class="ot">)</span> {</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span><span class="kw">$post_type</span> === <span class="st">&#39;custom_post_type&#39;</span><span class="ot">)</span> {</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true"></a>        <span class="kw">return</span> <span class="kw">true</span><span class="ot">;</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true"></a>    }</span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$excluded</span><span class="ot">;</span></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true"></a>}<span class="ot">,</span> <span class="dv">10</span><span class="ot">,</span> <span class="dv">2</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="woocommerce-sitemaps">WooCommerce Sitemaps</h2>
<p>E-commerce sites require careful sitemap configuration.</p>
<p><strong>Include</strong>:</p>
<ul>
<li>Product pages (in stock)</li>
<li>Product categories</li>
<li>Main shop page</li>
</ul>
<p><strong>Exclude</strong>:</p>
<ul>
<li>Out of stock products</li>
<li>Cart/checkout pages</li>
<li>My account pages</li>
<li>Order confirmation pages</li>
</ul>
<p><strong>Yoast WooCommerce SEO</strong> (addon): Automatically optimizes WooCommerce sitemaps.</p>
<h2 id="multilingual-sitemaps">Multilingual Sitemaps</h2>
<p>For multilingual sites (WPML, Polylang, etc.).</p>
<p><strong>Hreflang in Sitemaps</strong>:</p>
<div class="sourceCode" id="cb9">
<pre class="sourceCode xml"><code class="sourceCode xml"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true"></a><span class="kw">&lt;url&gt;</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true"></a>  <span class="kw">&lt;loc&gt;</span>https://example.com/page/<span class="kw">&lt;/loc&gt;</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true"></a>  <span class="kw">&lt;xhtml:link</span><span class="ot"> rel=</span><span class="st">&quot;alternate&quot;</span><span class="ot"> hreflang=</span><span class="st">&quot;en&quot;</span><span class="ot"> href=</span><span class="st">&quot;https://example.com/page/&quot;</span> <span class="kw">/&gt;</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true"></a>  <span class="kw">&lt;xhtml:link</span><span class="ot"> rel=</span><span class="st">&quot;alternate&quot;</span><span class="ot"> hreflang=</span><span class="st">&quot;es&quot;</span><span class="ot"> href=</span><span class="st">&quot;https://example.es/pagina/&quot;</span> <span class="kw">/&gt;</span></span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true"></a>  <span class="kw">&lt;xhtml:link</span><span class="ot"> rel=</span><span class="st">&quot;alternate&quot;</span><span class="ot"> hreflang=</span><span class="st">&quot;fr&quot;</span><span class="ot"> href=</span><span class="st">&quot;https://example.fr/page/&quot;</span> <span class="kw">/&gt;</span></span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true"></a><span class="kw">&lt;/url&gt;</span></span></code></pre>
</div>
<p>WPML and Polylang automatically generate language-specific sitemaps.</p>
<h2 id="troubleshooting-sitemap-issues">Troubleshooting Sitemap Issues</h2>
<p><strong>Sitemap Not Found (404)</strong>:</p>
<ul>
<li>Flush permalinks: Settings → Permalinks → Save</li>
<li>Check plugin conflicts</li>
<li>Verify .htaccess rules</li>
</ul>
<p><strong>Duplicate Sitemaps</strong>: Disable WordPress core sitemap if using plugin:</p>
<div class="sourceCode" id="cb10">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;wp_sitemaps_enabled&#39;</span><span class="ot">,</span> <span class="st">&#39;__return_false&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<p><strong>Sitemap Not Updating</strong>:</p>
<ul>
<li>Clear caching plugins</li>
<li>Regenerate sitemap manually</li>
<li>Check file permissions</li>
</ul>
<p><strong>Crawl Errors in Search Console</strong>:</p>
<ul>
<li>Review excluded URLs</li>
<li>Fix broken internal links</li>
<li>Remove deleted pages from sitemap</li>
</ul>
<h2 id="monitoring-sitemap-performance">Monitoring Sitemap Performance</h2>
<p><strong>Google Search Console Insights</strong>:</p>
<ol type="1">
<li>Navigate to Sitemaps report</li>
<li>Check submitted vs. indexed URLs</li>
<li>Investigate discrepancies</li>
<li>Monitor error reports</li>
</ol>
<p><strong>Expected Indexing</strong>:</p>
<ul>
<li>Small sites (under 100 pages): 80-100% indexed</li>
<li>Medium sites (100-1,000): 70-90% indexed</li>
<li>Large sites (1,000+): 60-80% indexed</li>
</ul>
<h2 id="advanced-sitemap-optimizations">Advanced Sitemap Optimizations</h2>
<p><strong>Priority Values</strong>:</p>
<ul>
<li>Homepage: 1.0</li>
<li>Main category pages: 0.8</li>
<li>Blog posts: 0.6</li>
<li>Tag archives: 0.4</li>
</ul>
<p><strong>Change Frequency</strong>:</p>
<ul>
<li>News sites: daily</li>
<li>Blogs: weekly</li>
<li>Static pages: monthly</li>
<li>Archived content: yearly</li>
</ul>
<p><strong>Custom Sitemap Routes</strong>:</p>
<div class="sourceCode" id="cb11">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;init&#39;</span><span class="ot">,</span> <span class="kw">function</span><span class="ot">()</span> {</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true"></a>    add_rewrite_rule<span class="ot">(</span></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true"></a>        <span class="st">&#39;custom-sitemap\.xml$&#39;</span><span class="ot">,</span></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true"></a>        <span class="st">&#39;index.php?custom_sitemap=1&#39;</span><span class="ot">,</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true"></a>        <span class="st">&#39;top&#39;</span></span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true"></a>    <span class="ot">);</span></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true"></a>}<span class="ot">);</span></span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true"></a></span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;query_vars&#39;</span><span class="ot">,</span> <span class="kw">function</span><span class="ot">(</span><span class="kw">$vars</span><span class="ot">)</span> {</span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true"></a>    <span class="kw">$vars</span><span class="ot">[]</span> = <span class="st">&#39;custom_sitemap&#39;</span><span class="ot">;</span></span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$vars</span><span class="ot">;</span></span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true"></a>}<span class="ot">);</span></span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true"></a></span>
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;template_redirect&#39;</span><span class="ot">,</span> <span class="kw">function</span><span class="ot">()</span> {</span>
<span id="cb11-15"><a href="#cb11-15" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span>get_query_var<span class="ot">(</span><span class="st">&#39;custom_sitemap&#39;</span><span class="ot">))</span> {</span>
<span id="cb11-16"><a href="#cb11-16" aria-hidden="true"></a>        <span class="fu">header</span><span class="ot">(</span><span class="st">&#39;Content-Type: application/xml&#39;</span><span class="ot">);</span></span>
<span id="cb11-17"><a href="#cb11-17" aria-hidden="true"></a>        <span class="co">// Generate custom sitemap</span></span>
<span id="cb11-18"><a href="#cb11-18" aria-hidden="true"></a>        <span class="kw">exit</span><span class="ot">;</span></span>
<span id="cb11-19"><a href="#cb11-19" aria-hidden="true"></a>    }</span>
<span id="cb11-20"><a href="#cb11-20" aria-hidden="true"></a>}<span class="ot">);</span></span></code></pre>
</div>
<h2 id="sitemap-caching">Sitemap Caching</h2>
<p>Cache sitemaps for performance.</p>
<p><strong>Cache Sitemap Output</strong>:</p>
<div class="sourceCode" id="cb12">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true"></a><span class="kw">function</span> dprt_cached_sitemap<span class="ot">()</span> {</span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true"></a>    <span class="kw">$cached</span> = get_transient<span class="ot">(</span><span class="st">&#39;dprt_sitemap_cache&#39;</span><span class="ot">);</span></span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span><span class="kw">$cached</span><span class="ot">)</span> {</span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true"></a>        <span class="kw">return</span> <span class="kw">$cached</span><span class="ot">;</span></span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true"></a>    }</span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true"></a></span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true"></a>    <span class="co">// Generate sitemap</span></span>
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true"></a>    <span class="kw">$sitemap</span> = dprt_generate_sitemap<span class="ot">();</span></span>
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true"></a></span>
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true"></a>    set_transient<span class="ot">(</span><span class="st">&#39;dprt_sitemap_cache&#39;</span><span class="ot">,</span> <span class="kw">$sitemap</span><span class="ot">,</span> <span class="dv">12</span> * <span class="kw">HOUR_IN_SECONDS</span><span class="ot">);</span></span>
<span id="cb12-11"><a href="#cb12-11" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$sitemap</span><span class="ot">;</span></span>
<span id="cb12-12"><a href="#cb12-12" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="conclusion">Conclusion</h2>
<p>WordPress XML sitemaps improve search engine indexing through structured URL lists, metadata about content freshness, and efficient crawl guidance. Use Yoast SEO or Rank Math for comprehensive sitemap management, submit to Google Search Console and Bing Webmaster Tools, exclude non-indexable content, and monitor performance regularly. Proper sitemap implementation ensures all valuable content gets discovered and indexed efficiently.</p>
<h2 id="external-links">External Links</h2>
<ol type="1">
<li><a href="https://search.google.com/search-console">Google Search Console</a></li>
<li><a href="https://www.sitemaps.org/protocol.html">XML Sitemap Protocol</a></li>
<li><a href="https://yoast.com/wordpress/plugins/seo/">Yoast SEO Plugin</a></li>
<li><a href="https://rankmath.com/">Rank Math SEO</a></li>
<li><a href="https://www.bing.com/webmasters/">Bing Webmaster Tools</a></li>
</ol>
<h2 id="call-to-action">Call to Action</h2>
<p>SEO configurations need protection. <a href="https://backupcopilotplugin.com/">Backup Copilot Pro</a> safeguards your WordPress sitemap settings and SEO data. Protect your indexing optimizations—start your free 30-day trial today!</p>
<p>The post <a href="https://developryplugins.com/how-to-create-xml-sitemaps-in-wordpress-for-better-indexing/">How to Create XML Sitemaps in WordPress for Better Indexing</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></content:encoded>
					
		
		<enclosure url="https://example.com/video.mp4" length="0" type="video/mp4" />

			</item>
		<item>
		<title>How to Customize WordPress Login Page Without Plugins</title>
		<link>https://developryplugins.com/how-to-customize-wordpress-login-page-without-plugins/</link>
		
		<dc:creator><![CDATA[Krasen Slavov]]></dc:creator>
		<pubDate>Wed, 15 Jul 2026 09:00:00 +0000</pubDate>
				<category><![CDATA[WordPress Tips Tricks & Hacks]]></category>
		<category><![CDATA[custom login]]></category>
		<category><![CDATA[login customization]]></category>
		<category><![CDATA[login page]]></category>
		<category><![CDATA[white label]]></category>
		<category><![CDATA[wordpress branding]]></category>
		<guid isPermaLink="false">https://developryplugins.com/?p=190</guid>

					<description><![CDATA[<p>WordPress login page customization transforms generic wp-login.php into branded experiences matching site identity. From logo replacement and color schemes to complete CSS overhauls and background images, login customization establishes professional...</p>
<p>The post <a href="https://developryplugins.com/how-to-customize-wordpress-login-page-without-plugins/">How to Customize WordPress Login Page Without Plugins</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><!-- @format --></p>
<p>WordPress login page customization transforms generic wp-login.php into branded experiences matching site identity. From logo replacement and color schemes to complete CSS overhauls and background images, login customization establishes professional first impressions without plugin overhead. This comprehensive guide teaches login page branding, styling, functionality modifications, and security enhancements through code-based approaches.</p>
<h2 id="why-customize-login-page">Why Customize Login Page</h2>
<p><strong>Professional Branding</strong>: First touchpoint for admins and contributors.</p>
<p><strong>Client Impressions</strong>: Agencies benefit from white-label experiences.</p>
<p><strong>Security Through Obscurity</strong>: Custom appearance discourages automated attacks.</p>
<p><strong>User Experience</strong>: Familiar branding increases user confidence.</p>
<p><strong>Performance</strong>: Code-based approach faster than plugins.</p>
<h2 id="custom-logo">Custom Logo</h2>
<p><strong>Replace WordPress Logo</strong>:</p>
<div class="sourceCode" id="cb1">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true"></a><span class="kw">function</span> dprt_custom_login_logo<span class="ot">()</span> {</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true"></a>    <span class="kw">?&gt;</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true"></a>    &lt;style type=<span class="st">&quot;text/css&quot;</span>&gt;</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true"></a>        <span class="co">#login h1 a, .login h1 a {</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true"></a>            background-image: url<span class="ot">(</span>&lt;<span class="ot">?</span>php <span class="kw">echo</span> get_stylesheet_directory_uri<span class="ot">();</span> <span class="kw">?&gt;</span>/images/login-logo.png<span class="ot">);</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true"></a>            height: 80px<span class="ot">;</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true"></a>            width: 320px<span class="ot">;</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true"></a>            background-size: contain<span class="ot">;</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true"></a>            background-repeat: no-repeat<span class="ot">;</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true"></a>            padding-bottom: 30px<span class="ot">;</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true"></a>        }</span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true"></a>    &lt;/style&gt;</span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php</span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true"></a>}</span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;login_enqueue_scripts&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_custom_login_logo&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<p><strong>Logo Specifications</strong>:</p>
<ul>
<li>Recommended size: 320×80 pixels</li>
<li>Formats: PNG (transparency), SVG (scalable)</li>
<li>Path: theme/images/login-logo.png</li>
</ul>
<h2 id="logo-url-and-title">Logo URL and Title</h2>
<p>By default, logo links to wordpress.org. Change to your site:</p>
<div class="sourceCode" id="cb2">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true"></a><span class="kw">function</span> dprt_login_logo_url<span class="ot">()</span> {</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true"></a>    <span class="kw">return</span> home_url<span class="ot">();</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true"></a>}</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;login_headerurl&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_login_logo_url&#39;</span><span class="ot">);</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true"></a></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true"></a><span class="kw">function</span> dprt_login_logo_url_title<span class="ot">()</span> {</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true"></a>    <span class="kw">return</span> get_bloginfo<span class="ot">(</span><span class="st">&#39;name&#39;</span><span class="ot">);</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true"></a>}</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;login_headertext&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_login_logo_url_title&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<p>Now logo links to site homepage with site name as title attribute.</p>
<h2 id="custom-login-styles">Custom Login Styles</h2>
<p><strong>Complete Login Page Styling</strong>:</p>
<div class="sourceCode" id="cb3">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true"></a><span class="kw">function</span> dprt_custom_login_styles<span class="ot">()</span> {</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true"></a>    <span class="kw">?&gt;</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true"></a>    &lt;style type=<span class="st">&quot;text/css&quot;</span>&gt;</span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true"></a>        body.login {</span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true"></a>            background: linear-gradient<span class="ot">(</span>135deg<span class="ot">,</span> <span class="co">#667eea 0%, #764ba2 100%);</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true"></a>        }</span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true"></a></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true"></a>        .login form {</span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true"></a>            border: none<span class="ot">;</span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true"></a>            box-shadow: <span class="dv">0</span> 10px 40px rgba<span class="ot">(</span><span class="dv">0</span><span class="ot">,</span> <span class="dv">0</span><span class="ot">,</span> <span class="dv">0</span><span class="ot">,</span> <span class="fl">0.2</span><span class="ot">);</span></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true"></a>            border-radius: 10px<span class="ot">;</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true"></a>        }</span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true"></a></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true"></a>        .login label {</span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true"></a>            color: <span class="co">#444;</span></span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true"></a>            font-size: 14px<span class="ot">;</span></span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true"></a>        }</span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true"></a></span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true"></a>        .login input<span class="ot">[</span>type=<span class="st">&quot;text&quot;</span><span class="ot">],</span></span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true"></a>        .login input<span class="ot">[</span>type=<span class="st">&quot;password&quot;</span><span class="ot">]</span> {</span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true"></a>            border: 2px solid <span class="co">#ddd;</span></span>
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true"></a>            border-radius: 5px<span class="ot">;</span></span>
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true"></a>            padding: 8px 12px<span class="ot">;</span></span>
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true"></a>            font-size: 14px<span class="ot">;</span></span>
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true"></a>        }</span>
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true"></a></span>
<span id="cb3-27"><a href="#cb3-27" aria-hidden="true"></a>        .login input<span class="ot">[</span>type=<span class="st">&quot;text&quot;</span><span class="ot">]</span>:focus<span class="ot">,</span></span>
<span id="cb3-28"><a href="#cb3-28" aria-hidden="true"></a>        .login input<span class="ot">[</span>type=<span class="st">&quot;password&quot;</span><span class="ot">]</span>:focus {</span>
<span id="cb3-29"><a href="#cb3-29" aria-hidden="true"></a>            border-color: <span class="co">#667eea;</span></span>
<span id="cb3-30"><a href="#cb3-30" aria-hidden="true"></a>            box-shadow: <span class="dv">0</span> <span class="dv">0</span> 5px rgba<span class="ot">(</span><span class="dv">102</span><span class="ot">,</span> <span class="dv">126</span><span class="ot">,</span> <span class="dv">234</span><span class="ot">,</span> <span class="fl">0.5</span><span class="ot">);</span></span>
<span id="cb3-31"><a href="#cb3-31" aria-hidden="true"></a>        }</span>
<span id="cb3-32"><a href="#cb3-32" aria-hidden="true"></a></span>
<span id="cb3-33"><a href="#cb3-33" aria-hidden="true"></a>        .wp-core-ui .button-primary {</span>
<span id="cb3-34"><a href="#cb3-34" aria-hidden="true"></a>            background: <span class="co">#667eea;</span></span>
<span id="cb3-35"><a href="#cb3-35" aria-hidden="true"></a>            border-color: <span class="co">#667eea;</span></span>
<span id="cb3-36"><a href="#cb3-36" aria-hidden="true"></a>            box-shadow: none<span class="ot">;</span></span>
<span id="cb3-37"><a href="#cb3-37" aria-hidden="true"></a>            text-shadow: none<span class="ot">;</span></span>
<span id="cb3-38"><a href="#cb3-38" aria-hidden="true"></a>            border-radius: 5px<span class="ot">;</span></span>
<span id="cb3-39"><a href="#cb3-39" aria-hidden="true"></a>            padding: 8px 20px<span class="ot">;</span></span>
<span id="cb3-40"><a href="#cb3-40" aria-hidden="true"></a>            font-size: 15px<span class="ot">;</span></span>
<span id="cb3-41"><a href="#cb3-41" aria-hidden="true"></a>        }</span>
<span id="cb3-42"><a href="#cb3-42" aria-hidden="true"></a></span>
<span id="cb3-43"><a href="#cb3-43" aria-hidden="true"></a>        .wp-core-ui .button-primary:hover {</span>
<span id="cb3-44"><a href="#cb3-44" aria-hidden="true"></a>            background: <span class="co">#5568d3;</span></span>
<span id="cb3-45"><a href="#cb3-45" aria-hidden="true"></a>            border-color: <span class="co">#5568d3;</span></span>
<span id="cb3-46"><a href="#cb3-46" aria-hidden="true"></a>        }</span>
<span id="cb3-47"><a href="#cb3-47" aria-hidden="true"></a></span>
<span id="cb3-48"><a href="#cb3-48" aria-hidden="true"></a>        .login <span class="co">#backtoblog a,</span></span>
<span id="cb3-49"><a href="#cb3-49" aria-hidden="true"></a>        .login <span class="co">#nav a {</span></span>
<span id="cb3-50"><a href="#cb3-50" aria-hidden="true"></a>            color: <span class="co">#fff;</span></span>
<span id="cb3-51"><a href="#cb3-51" aria-hidden="true"></a>            text-decoration: none<span class="ot">;</span></span>
<span id="cb3-52"><a href="#cb3-52" aria-hidden="true"></a>        }</span>
<span id="cb3-53"><a href="#cb3-53" aria-hidden="true"></a></span>
<span id="cb3-54"><a href="#cb3-54" aria-hidden="true"></a>        .login <span class="co">#backtoblog a:hover,</span></span>
<span id="cb3-55"><a href="#cb3-55" aria-hidden="true"></a>        .login <span class="co">#nav a:hover {</span></span>
<span id="cb3-56"><a href="#cb3-56" aria-hidden="true"></a>            color: <span class="co">#f0f0f0;</span></span>
<span id="cb3-57"><a href="#cb3-57" aria-hidden="true"></a>        }</span>
<span id="cb3-58"><a href="#cb3-58" aria-hidden="true"></a></span>
<span id="cb3-59"><a href="#cb3-59" aria-hidden="true"></a>        .login .message<span class="ot">,</span></span>
<span id="cb3-60"><a href="#cb3-60" aria-hidden="true"></a>        .login .success {</span>
<span id="cb3-61"><a href="#cb3-61" aria-hidden="true"></a>            border-left-color: <span class="co">#667eea;</span></span>
<span id="cb3-62"><a href="#cb3-62" aria-hidden="true"></a>        }</span>
<span id="cb3-63"><a href="#cb3-63" aria-hidden="true"></a></span>
<span id="cb3-64"><a href="#cb3-64" aria-hidden="true"></a>        <span class="co">#login_error {</span></span>
<span id="cb3-65"><a href="#cb3-65" aria-hidden="true"></a>            border-left-color: <span class="co">#dc3232;</span></span>
<span id="cb3-66"><a href="#cb3-66" aria-hidden="true"></a>        }</span>
<span id="cb3-67"><a href="#cb3-67" aria-hidden="true"></a>    &lt;/style&gt;</span>
<span id="cb3-68"><a href="#cb3-68" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php</span>
<span id="cb3-69"><a href="#cb3-69" aria-hidden="true"></a>}</span>
<span id="cb3-70"><a href="#cb3-70" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;login_enqueue_scripts&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_custom_login_styles&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="background-image">Background Image</h2>
<p><strong>Full-Screen Background</strong>:</p>
<div class="sourceCode" id="cb4">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true"></a><span class="kw">function</span> dprt_login_background<span class="ot">()</span> {</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true"></a>    <span class="kw">?&gt;</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true"></a>    &lt;style type=<span class="st">&quot;text/css&quot;</span>&gt;</span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true"></a>        body.login {</span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true"></a>            background-image: url<span class="ot">(</span>&lt;<span class="ot">?</span>php <span class="kw">echo</span> get_stylesheet_directory_uri<span class="ot">();</span> <span class="kw">?&gt;</span>/images/login-background.jpg<span class="ot">);</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true"></a>            background-size: cover<span class="ot">;</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true"></a>            background-position: center<span class="ot">;</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true"></a>            background-repeat: no-repeat<span class="ot">;</span></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true"></a>            background-attachment: fixed<span class="ot">;</span></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true"></a>        }</span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true"></a></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true"></a>        .login form {</span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true"></a>            background: rgba<span class="ot">(</span><span class="dv">255</span><span class="ot">,</span> <span class="dv">255</span><span class="ot">,</span> <span class="dv">255</span><span class="ot">,</span> <span class="fl">0.95</span><span class="ot">);</span></span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true"></a>            backdrop-filter: blur<span class="ot">(</span>10px<span class="ot">);</span></span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true"></a>        }</span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true"></a>    &lt;/style&gt;</span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php</span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true"></a>}</span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;login_enqueue_scripts&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_login_background&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<p><strong>Background Image Requirements</strong>:</p>
<ul>
<li>High resolution (1920×1080 minimum)</li>
<li>Optimized file size (under 500KB)</li>
<li>Appropriate licensing</li>
</ul>
<h2 id="custom-login-messages">Custom Login Messages</h2>
<p><strong>Replace Generic Error Messages</strong>:</p>
<div class="sourceCode" id="cb5">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true"></a><span class="kw">function</span> dprt_custom_login_errors<span class="ot">()</span> {</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true"></a>    <span class="kw">return</span> <span class="st">&#39;Invalid username or password. Please try again.&#39;</span><span class="ot">;</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true"></a>}</span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;login_errors&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_custom_login_errors&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<p>Security benefit: Generic message doesn’t reveal whether username or password incorrect.</p>
<p><strong>Custom Welcome Message</strong>:</p>
<div class="sourceCode" id="cb6">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true"></a><span class="kw">function</span> dprt_custom_login_message<span class="ot">()</span> {</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true"></a>    <span class="kw">return</span> <span class="st">&#39;&lt;p class=&quot;message&quot;&gt;Welcome! Please log in to access your dashboard.&lt;/p&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true"></a>}</span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;login_message&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_custom_login_message&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="enqueue-custom-stylesheet">Enqueue Custom Stylesheet</h2>
<p><strong>Separate CSS File Approach</strong>:</p>
<div class="sourceCode" id="cb7">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true"></a><span class="kw">function</span> dprt_enqueue_login_stylesheet<span class="ot">()</span> {</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true"></a>    wp_enqueue_style<span class="ot">(</span><span class="st">&#39;custom-login&#39;</span><span class="ot">,</span> get_stylesheet_directory_uri<span class="ot">()</span> . <span class="st">&#39;/css/login.css&#39;</span><span class="ot">);</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true"></a>}</span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;login_enqueue_scripts&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_enqueue_login_stylesheet&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<p><strong>login.css</strong> (in theme/css/login.css):</p>
<div class="sourceCode" id="cb8">
<pre class="sourceCode css"><code class="sourceCode css"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true"></a>body<span class="fu">.login</span> {</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true"></a>    <span class="kw">background</span>: <span class="cn">#f1f1f1</span><span class="op">;</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true"></a>}</span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true"></a></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true"></a><span class="pp">#login</span> h1 a<span class="op">,</span></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true"></a><span class="fu">.login</span> h1 a {</span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true"></a>    <span class="kw">background-image</span>: <span class="fu">url(</span><span class="st">../images/login-logo.png</span><span class="fu">)</span><span class="op">;</span></span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true"></a>    <span class="kw">height</span>: <span class="dv">80</span><span class="dt">px</span><span class="op">;</span></span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true"></a>    <span class="kw">width</span>: <span class="dv">320</span><span class="dt">px</span><span class="op">;</span></span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true"></a>    <span class="kw">background-size</span>: <span class="dv">contain</span><span class="op">;</span></span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true"></a>    <span class="kw">background-repeat</span>: <span class="dv">no-repeat</span><span class="op">;</span></span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true"></a>    <span class="kw">padding-bottom</span>: <span class="dv">30</span><span class="dt">px</span><span class="op">;</span></span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true"></a>}</span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true"></a></span>
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true"></a><span class="fu">.login</span> form {</span>
<span id="cb8-16"><a href="#cb8-16" aria-hidden="true"></a>    <span class="kw">border</span>: <span class="dv">1</span><span class="dt">px</span> <span class="dv">solid</span> <span class="cn">#ddd</span><span class="op">;</span></span>
<span id="cb8-17"><a href="#cb8-17" aria-hidden="true"></a>    <span class="kw">box-shadow</span>: <span class="dv">0</span> <span class="dv">1</span><span class="dt">px</span> <span class="dv">3</span><span class="dt">px</span> <span class="fu">rgba(</span><span class="dv">0</span><span class="op">,</span> <span class="dv">0</span><span class="op">,</span> <span class="dv">0</span><span class="op">,</span> <span class="dv">0.1</span><span class="fu">)</span><span class="op">;</span></span>
<span id="cb8-18"><a href="#cb8-18" aria-hidden="true"></a>}</span>
<span id="cb8-19"><a href="#cb8-19" aria-hidden="true"></a></span>
<span id="cb8-20"><a href="#cb8-20" aria-hidden="true"></a><span class="co">/* Additional styles... */</span></span></code></pre>
</div>
<p>Benefits: Better organization, easier maintenance, browser caching.</p>
<h2 id="remove-remember-me-checkbox">Remove “Remember Me” Checkbox</h2>
<div class="sourceCode" id="cb9">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true"></a><span class="kw">function</span> dprt_remove_rememberme<span class="ot">()</span> {</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true"></a>    <span class="kw">?&gt;</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true"></a>    &lt;style&gt;</span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true"></a>        .login .forgetmenot { display: none<span class="ot">;</span> }</span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true"></a>    &lt;/style&gt;</span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php</span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true"></a>}</span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;login_head&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_remove_rememberme&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<p>Security consideration for shared computers.</p>
<h2 id="custom-login-footer">Custom Login Footer</h2>
<p><strong>Add Custom Text Below Form</strong>:</p>
<div class="sourceCode" id="cb10">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true"></a><span class="kw">function</span> dprt_custom_login_footer<span class="ot">()</span> {</span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;p style=&quot;text-align: center; color: #666; margin-top: 20px;&quot;&gt;</span></span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true"></a><span class="st">        Need help? &lt;a href=&quot;mailto:support@example.com&quot;&gt;Contact Support&lt;/a&gt;</span></span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true"></a><span class="st">    &lt;/p&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true"></a>}</span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;login_footer&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_custom_login_footer&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="hide-lost-your-password-link">Hide “Lost Your Password” Link</h2>
<div class="sourceCode" id="cb11">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true"></a><span class="kw">function</span> dprt_remove_lostpassword<span class="ot">()</span> {</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true"></a>    <span class="kw">?&gt;</span></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true"></a>    &lt;style&gt;</span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true"></a>        .login <span class="co">#nav { display: none; }</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true"></a>    &lt;/style&gt;</span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php</span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true"></a>}</span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;login_head&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_remove_lostpassword&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<p>Useful for restricted client sites or when using custom password reset.</p>
<h2 id="custom-login-redirect">Custom Login Redirect</h2>
<p><strong>Redirect by User Role</strong>:</p>
<div class="sourceCode" id="cb12">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true"></a><span class="kw">function</span> dprt_login_redirect<span class="ot">(</span><span class="kw">$redirect_to</span><span class="ot">,</span> <span class="kw">$request</span><span class="ot">,</span> <span class="kw">$user</span><span class="ot">)</span> {</span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true"></a>    <span class="co">// Check user object exists</span></span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span><span class="kw">isset</span><span class="ot">(</span><span class="kw">$user</span>-&gt;roles<span class="ot">)</span> &amp;&amp; <span class="fu">is_array</span><span class="ot">(</span><span class="kw">$user</span>-&gt;roles<span class="ot">))</span> {</span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true"></a>        <span class="co">// Administrators go to dashboard</span></span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true"></a>        <span class="kw">if</span> <span class="ot">(</span><span class="fu">in_array</span><span class="ot">(</span><span class="st">&#39;administrator&#39;</span><span class="ot">,</span> <span class="kw">$user</span>-&gt;roles<span class="ot">))</span> {</span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true"></a>            <span class="kw">return</span> admin_url<span class="ot">();</span></span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true"></a>        }</span>
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true"></a>        <span class="co">// Editors go to posts</span></span>
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true"></a>        <span class="kw">elseif</span> <span class="ot">(</span><span class="fu">in_array</span><span class="ot">(</span><span class="st">&#39;editor&#39;</span><span class="ot">,</span> <span class="kw">$user</span>-&gt;roles<span class="ot">))</span> {</span>
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true"></a>            <span class="kw">return</span> admin_url<span class="ot">(</span><span class="st">&#39;edit.php&#39;</span><span class="ot">);</span></span>
<span id="cb12-11"><a href="#cb12-11" aria-hidden="true"></a>        }</span>
<span id="cb12-12"><a href="#cb12-12" aria-hidden="true"></a>        <span class="co">// Authors/contributors go to profile</span></span>
<span id="cb12-13"><a href="#cb12-13" aria-hidden="true"></a>        <span class="kw">else</span> {</span>
<span id="cb12-14"><a href="#cb12-14" aria-hidden="true"></a>            <span class="kw">return</span> admin_url<span class="ot">(</span><span class="st">&#39;profile.php&#39;</span><span class="ot">);</span></span>
<span id="cb12-15"><a href="#cb12-15" aria-hidden="true"></a>        }</span>
<span id="cb12-16"><a href="#cb12-16" aria-hidden="true"></a>    }</span>
<span id="cb12-17"><a href="#cb12-17" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$redirect_to</span><span class="ot">;</span></span>
<span id="cb12-18"><a href="#cb12-18" aria-hidden="true"></a>}</span>
<span id="cb12-19"><a href="#cb12-19" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;login_redirect&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_login_redirect&#39;</span><span class="ot">,</span> <span class="dv">10</span><span class="ot">,</span> <span class="dv">3</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="add-custom-javascript">Add Custom JavaScript</h2>
<p><strong>Client-Side Functionality</strong>:</p>
<div class="sourceCode" id="cb13">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true"></a><span class="kw">function</span> dprt_custom_login_js<span class="ot">()</span> {</span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true"></a>    <span class="kw">?&gt;</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true"></a>    &lt;script type=<span class="st">&quot;text/javascript&quot;</span>&gt;</span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true"></a>        document.addEventListener<span class="ot">(</span><span class="st">&#39;DOMContentLoaded&#39;</span><span class="ot">,</span> <span class="kw">function</span><span class="ot">()</span> {</span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true"></a>            <span class="co">// Auto-focus username field</span></span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true"></a>            <span class="er">var</span> usernameField = document.getElementById<span class="ot">(</span><span class="st">&#39;user_login&#39;</span><span class="ot">);</span></span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true"></a>            <span class="kw">if</span> <span class="ot">(</span>usernameField<span class="ot">)</span> {</span>
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true"></a>                usernameField.focus<span class="ot">();</span></span>
<span id="cb13-9"><a href="#cb13-9" aria-hidden="true"></a>            }</span>
<span id="cb13-10"><a href="#cb13-10" aria-hidden="true"></a></span>
<span id="cb13-11"><a href="#cb13-11" aria-hidden="true"></a>            <span class="co">// Add placeholder text</span></span>
<span id="cb13-12"><a href="#cb13-12" aria-hidden="true"></a>            usernameField.placeholder = <span class="st">&#39;Enter your username&#39;</span><span class="ot">;</span></span>
<span id="cb13-13"><a href="#cb13-13" aria-hidden="true"></a>            document.getElementById<span class="ot">(</span><span class="st">&#39;user_pass&#39;</span><span class="ot">)</span>.placeholder = <span class="st">&#39;Enter your password&#39;</span><span class="ot">;</span></span>
<span id="cb13-14"><a href="#cb13-14" aria-hidden="true"></a>        }<span class="ot">);</span></span>
<span id="cb13-15"><a href="#cb13-15" aria-hidden="true"></a>    &lt;/script&gt;</span>
<span id="cb13-16"><a href="#cb13-16" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php</span>
<span id="cb13-17"><a href="#cb13-17" aria-hidden="true"></a>}</span>
<span id="cb13-18"><a href="#cb13-18" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;login_footer&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_custom_login_js&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="complete-login-page-template">Complete Login Page Template</h2>
<p><strong>All-in-One Implementation</strong>:</p>
<div class="sourceCode" id="cb14">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true"></a><span class="co">// Custom logo</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true"></a><span class="kw">function</span> dprt_custom_login_logo<span class="ot">()</span> {</span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true"></a>    <span class="kw">?&gt;</span></span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true"></a>    &lt;style&gt;</span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true"></a>        <span class="co">#login h1 a {</span></span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true"></a>            background-image: url<span class="ot">(</span>&lt;<span class="ot">?</span>php <span class="kw">echo</span> get_stylesheet_directory_uri<span class="ot">();</span> <span class="kw">?&gt;</span>/images/login-logo.png<span class="ot">);</span></span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true"></a>            height: 80px<span class="ot">;</span></span>
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true"></a>            width: 320px<span class="ot">;</span></span>
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true"></a>            background-size: contain<span class="ot">;</span></span>
<span id="cb14-10"><a href="#cb14-10" aria-hidden="true"></a>            background-repeat: no-repeat<span class="ot">;</span></span>
<span id="cb14-11"><a href="#cb14-11" aria-hidden="true"></a>            padding-bottom: 30px<span class="ot">;</span></span>
<span id="cb14-12"><a href="#cb14-12" aria-hidden="true"></a>        }</span>
<span id="cb14-13"><a href="#cb14-13" aria-hidden="true"></a>    &lt;/style&gt;</span>
<span id="cb14-14"><a href="#cb14-14" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php</span>
<span id="cb14-15"><a href="#cb14-15" aria-hidden="true"></a>}</span>
<span id="cb14-16"><a href="#cb14-16" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;login_enqueue_scripts&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_custom_login_logo&#39;</span><span class="ot">);</span></span>
<span id="cb14-17"><a href="#cb14-17" aria-hidden="true"></a></span>
<span id="cb14-18"><a href="#cb14-18" aria-hidden="true"></a><span class="co">// Logo URL</span></span>
<span id="cb14-19"><a href="#cb14-19" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;login_headerurl&#39;</span><span class="ot">,</span> <span class="kw">function</span><span class="ot">()</span> { <span class="kw">return</span> home_url<span class="ot">();</span> }<span class="ot">);</span></span>
<span id="cb14-20"><a href="#cb14-20" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;login_headertext&#39;</span><span class="ot">,</span> <span class="kw">function</span><span class="ot">()</span> { <span class="kw">return</span> get_bloginfo<span class="ot">(</span><span class="st">&#39;name&#39;</span><span class="ot">);</span> }<span class="ot">);</span></span>
<span id="cb14-21"><a href="#cb14-21" aria-hidden="true"></a></span>
<span id="cb14-22"><a href="#cb14-22" aria-hidden="true"></a><span class="co">// Custom styles</span></span>
<span id="cb14-23"><a href="#cb14-23" aria-hidden="true"></a><span class="kw">function</span> dprt_custom_login_styles<span class="ot">()</span> {</span>
<span id="cb14-24"><a href="#cb14-24" aria-hidden="true"></a>    wp_enqueue_style<span class="ot">(</span><span class="st">&#39;custom-login&#39;</span><span class="ot">,</span> get_stylesheet_directory_uri<span class="ot">()</span> . <span class="st">&#39;/css/login.css&#39;</span><span class="ot">);</span></span>
<span id="cb14-25"><a href="#cb14-25" aria-hidden="true"></a>}</span>
<span id="cb14-26"><a href="#cb14-26" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;login_enqueue_scripts&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_custom_login_styles&#39;</span><span class="ot">);</span></span>
<span id="cb14-27"><a href="#cb14-27" aria-hidden="true"></a></span>
<span id="cb14-28"><a href="#cb14-28" aria-hidden="true"></a><span class="co">// Custom error message</span></span>
<span id="cb14-29"><a href="#cb14-29" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;login_errors&#39;</span><span class="ot">,</span> <span class="kw">function</span><span class="ot">()</span> {</span>
<span id="cb14-30"><a href="#cb14-30" aria-hidden="true"></a>    <span class="kw">return</span> <span class="st">&#39;Login failed. Please check your credentials and try again.&#39;</span><span class="ot">;</span></span>
<span id="cb14-31"><a href="#cb14-31" aria-hidden="true"></a>}<span class="ot">);</span></span>
<span id="cb14-32"><a href="#cb14-32" aria-hidden="true"></a></span>
<span id="cb14-33"><a href="#cb14-33" aria-hidden="true"></a><span class="co">// Login redirect</span></span>
<span id="cb14-34"><a href="#cb14-34" aria-hidden="true"></a><span class="kw">function</span> dprt_login_redirect<span class="ot">(</span><span class="kw">$redirect_to</span><span class="ot">,</span> <span class="kw">$request</span><span class="ot">,</span> <span class="kw">$user</span><span class="ot">)</span> {</span>
<span id="cb14-35"><a href="#cb14-35" aria-hidden="true"></a>    <span class="kw">return</span> <span class="ot">(</span><span class="fu">is_array</span><span class="ot">(</span><span class="kw">$user</span>-&gt;roles<span class="ot">)</span> &amp;&amp; <span class="fu">in_array</span><span class="ot">(</span><span class="st">&#39;administrator&#39;</span><span class="ot">,</span> <span class="kw">$user</span>-&gt;roles<span class="ot">))</span> <span class="ot">?</span> admin_url<span class="ot">()</span> <span class="ot">:</span> home_url<span class="ot">();</span></span>
<span id="cb14-36"><a href="#cb14-36" aria-hidden="true"></a>}</span>
<span id="cb14-37"><a href="#cb14-37" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;login_redirect&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_login_redirect&#39;</span><span class="ot">,</span> <span class="dv">10</span><span class="ot">,</span> <span class="dv">3</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="mobile-responsive-login">Mobile-Responsive Login</h2>
<p><strong>Ensure Mobile Compatibility</strong>:</p>
<div class="sourceCode" id="cb15">
<pre class="sourceCode css"><code class="sourceCode css"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true"></a><span class="im">@media</span> <span class="kw">only</span> <span class="dv">screen</span> <span class="kw">and</span> (<span class="kw">max-width</span>: <span class="dv">768</span><span class="dt">px</span>) {</span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true"></a>    <span class="pp">#login</span> {</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true"></a>        <span class="kw">padding</span>: <span class="dv">20</span><span class="dt">px</span> <span class="dv">0</span><span class="op">;</span></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true"></a>    }</span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true"></a></span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true"></a>    <span class="fu">.login</span> form {</span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true"></a>        <span class="kw">margin-left</span>: <span class="dv">20</span><span class="dt">px</span><span class="op">;</span></span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true"></a>        <span class="kw">margin-right</span>: <span class="dv">20</span><span class="dt">px</span><span class="op">;</span></span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true"></a>        <span class="kw">padding</span>: <span class="dv">20</span><span class="dt">px</span><span class="op">;</span></span>
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true"></a>    }</span>
<span id="cb15-11"><a href="#cb15-11" aria-hidden="true"></a></span>
<span id="cb15-12"><a href="#cb15-12" aria-hidden="true"></a>    <span class="pp">#login</span> h1 a {</span>
<span id="cb15-13"><a href="#cb15-13" aria-hidden="true"></a>        <span class="kw">width</span>: <span class="dv">250</span><span class="dt">px</span><span class="op">;</span></span>
<span id="cb15-14"><a href="#cb15-14" aria-hidden="true"></a>        <span class="kw">background-size</span>: <span class="dv">contain</span><span class="op">;</span></span>
<span id="cb15-15"><a href="#cb15-15" aria-hidden="true"></a>    }</span>
<span id="cb15-16"><a href="#cb15-16" aria-hidden="true"></a>}</span></code></pre>
</div>
<h2 id="language-selector">Language Selector</h2>
<p><strong>Multilingual Login Page</strong>:</p>
<div class="sourceCode" id="cb16">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true"></a><span class="kw">function</span> dprt_login_language_selector<span class="ot">()</span> {</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;div class=&quot;language-selector&quot; style=&quot;text-align: center; margin-top: 20px;&quot;&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true"></a>    <span class="co">// Custom language switcher HTML</span></span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true"></a>    <span class="kw">echo</span> <span class="st">&#39;&lt;/div&gt;&#39;</span><span class="ot">;</span></span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true"></a>}</span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;login_footer&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_login_language_selector&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="security-enhancements">Security Enhancements</h2>
<p><strong>Limit Login Attempts</strong> (without plugin):</p>
<div class="sourceCode" id="cb17">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true"></a><span class="kw">function</span> dprt_check_attempted_login<span class="ot">(</span><span class="kw">$user</span><span class="ot">,</span> <span class="kw">$username</span><span class="ot">,</span> <span class="kw">$password</span><span class="ot">)</span> {</span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true"></a>    <span class="kw">$login_attempts</span> = get_transient<span class="ot">(</span><span class="st">&#39;attempted_login&#39;</span><span class="ot">);</span></span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true"></a></span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span><span class="kw">$login_attempts</span> &amp;&amp; <span class="kw">$login_attempts</span> &gt;= <span class="dv">3</span><span class="ot">)</span> {</span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true"></a>        <span class="kw">return</span> <span class="kw">new</span> WP_Error<span class="ot">(</span><span class="st">&#39;too_many_attempts&#39;</span><span class="ot">,</span> <span class="st">&#39;Too many failed login attempts. Please wait 15 minutes.&#39;</span><span class="ot">);</span></span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true"></a>    }</span>
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true"></a></span>
<span id="cb17-8"><a href="#cb17-8" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$user</span><span class="ot">;</span></span>
<span id="cb17-9"><a href="#cb17-9" aria-hidden="true"></a>}</span>
<span id="cb17-10"><a href="#cb17-10" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;authenticate&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_check_attempted_login&#39;</span><span class="ot">,</span> <span class="dv">30</span><span class="ot">,</span> <span class="dv">3</span><span class="ot">);</span></span>
<span id="cb17-11"><a href="#cb17-11" aria-hidden="true"></a></span>
<span id="cb17-12"><a href="#cb17-12" aria-hidden="true"></a><span class="kw">function</span> dprt_login_failed<span class="ot">()</span> {</span>
<span id="cb17-13"><a href="#cb17-13" aria-hidden="true"></a>    <span class="kw">$login_attempts</span> = get_transient<span class="ot">(</span><span class="st">&#39;attempted_login&#39;</span><span class="ot">);</span></span>
<span id="cb17-14"><a href="#cb17-14" aria-hidden="true"></a>    <span class="kw">$login_attempts</span> = <span class="kw">$login_attempts</span> <span class="ot">?</span> <span class="kw">$login_attempts</span> + <span class="dv">1</span> <span class="ot">:</span> <span class="dv">1</span><span class="ot">;</span></span>
<span id="cb17-15"><a href="#cb17-15" aria-hidden="true"></a>    set_transient<span class="ot">(</span><span class="st">&#39;attempted_login&#39;</span><span class="ot">,</span> <span class="kw">$login_attempts</span><span class="ot">,</span> <span class="dv">900</span><span class="ot">);</span> <span class="co">// 15 minutes</span></span>
<span id="cb17-16"><a href="#cb17-16" aria-hidden="true"></a>}</span>
<span id="cb17-17"><a href="#cb17-17" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;wp_login_failed&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_login_failed&#39;</span><span class="ot">);</span></span></code></pre>
</div>
<p><strong>CAPTCHA Integration</strong> (Google reCAPTCHA):</p>
<div class="sourceCode" id="cb18">
<pre class="sourceCode php"><code class="sourceCode php"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true"></a><span class="kw">function</span> dprt_add_captcha_to_login<span class="ot">()</span> {</span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true"></a>    <span class="kw">?&gt;</span></span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true"></a>    &lt;div <span class="kw">class</span>=<span class="st">&quot;g-recaptcha&quot;</span> data-sitekey=<span class="st">&quot;YOUR_SITE_KEY&quot;</span>&gt;&lt;/div&gt;</span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true"></a>    &lt;script src=<span class="st">&quot;https://www.google.com/recaptcha/api.js&quot;</span> async defer&gt;&lt;/script&gt;</span>
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true"></a>    &lt;<span class="ot">?</span>php</span>
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true"></a>}</span>
<span id="cb18-7"><a href="#cb18-7" aria-hidden="true"></a>add_action<span class="ot">(</span><span class="st">&#39;login_form&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_add_captcha_to_login&#39;</span><span class="ot">);</span></span>
<span id="cb18-8"><a href="#cb18-8" aria-hidden="true"></a></span>
<span id="cb18-9"><a href="#cb18-9" aria-hidden="true"></a><span class="kw">function</span> dprt_verify_captcha<span class="ot">(</span><span class="kw">$user</span><span class="ot">,</span> <span class="kw">$username</span><span class="ot">,</span> <span class="kw">$password</span><span class="ot">)</span> {</span>
<span id="cb18-10"><a href="#cb18-10" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span>!<span class="kw">isset</span><span class="ot">(</span><span class="kw">$_POST</span><span class="ot">[</span><span class="st">&#39;g-recaptcha-response&#39;</span><span class="ot">]))</span> {</span>
<span id="cb18-11"><a href="#cb18-11" aria-hidden="true"></a>        <span class="kw">return</span> <span class="kw">new</span> WP_Error<span class="ot">(</span><span class="st">&#39;captcha_error&#39;</span><span class="ot">,</span> <span class="st">&#39;Please complete the CAPTCHA.&#39;</span><span class="ot">);</span></span>
<span id="cb18-12"><a href="#cb18-12" aria-hidden="true"></a>    }</span>
<span id="cb18-13"><a href="#cb18-13" aria-hidden="true"></a></span>
<span id="cb18-14"><a href="#cb18-14" aria-hidden="true"></a>    <span class="kw">$response</span> = wp_remote_post<span class="ot">(</span><span class="st">&#39;https://www.google.com/recaptcha/api/siteverify&#39;</span><span class="ot">,</span> <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb18-15"><a href="#cb18-15" aria-hidden="true"></a>        <span class="st">&#39;body&#39;</span> =&gt; <span class="kw">array</span><span class="ot">(</span></span>
<span id="cb18-16"><a href="#cb18-16" aria-hidden="true"></a>            <span class="st">&#39;secret&#39;</span> =&gt; <span class="st">&#39;YOUR_SECRET_KEY&#39;</span><span class="ot">,</span></span>
<span id="cb18-17"><a href="#cb18-17" aria-hidden="true"></a>            <span class="st">&#39;response&#39;</span> =&gt; <span class="kw">$_POST</span><span class="ot">[</span><span class="st">&#39;g-recaptcha-response&#39;</span><span class="ot">]</span></span>
<span id="cb18-18"><a href="#cb18-18" aria-hidden="true"></a>        <span class="ot">)</span></span>
<span id="cb18-19"><a href="#cb18-19" aria-hidden="true"></a>    <span class="ot">));</span></span>
<span id="cb18-20"><a href="#cb18-20" aria-hidden="true"></a></span>
<span id="cb18-21"><a href="#cb18-21" aria-hidden="true"></a>    <span class="kw">$result</span> = <span class="fu">json_decode</span><span class="ot">(</span>wp_remote_retrieve_body<span class="ot">(</span><span class="kw">$response</span><span class="ot">));</span></span>
<span id="cb18-22"><a href="#cb18-22" aria-hidden="true"></a></span>
<span id="cb18-23"><a href="#cb18-23" aria-hidden="true"></a>    <span class="kw">if</span> <span class="ot">(</span>!<span class="kw">$result</span>-&gt;success<span class="ot">)</span> {</span>
<span id="cb18-24"><a href="#cb18-24" aria-hidden="true"></a>        <span class="kw">return</span> <span class="kw">new</span> WP_Error<span class="ot">(</span><span class="st">&#39;captcha_failed&#39;</span><span class="ot">,</span> <span class="st">&#39;CAPTCHA verification failed.&#39;</span><span class="ot">);</span></span>
<span id="cb18-25"><a href="#cb18-25" aria-hidden="true"></a>    }</span>
<span id="cb18-26"><a href="#cb18-26" aria-hidden="true"></a></span>
<span id="cb18-27"><a href="#cb18-27" aria-hidden="true"></a>    <span class="kw">return</span> <span class="kw">$user</span><span class="ot">;</span></span>
<span id="cb18-28"><a href="#cb18-28" aria-hidden="true"></a>}</span>
<span id="cb18-29"><a href="#cb18-29" aria-hidden="true"></a>add_filter<span class="ot">(</span><span class="st">&#39;authenticate&#39;</span><span class="ot">,</span> <span class="st">&#39;dprt_verify_captcha&#39;</span><span class="ot">,</span> <span class="dv">30</span><span class="ot">,</span> <span class="dv">3</span><span class="ot">);</span></span></code></pre>
</div>
<h2 id="testing-login-customizations">Testing Login Customizations</h2>
<p><strong>Test Across Browsers</strong>:</p>
<ul>
<li>Chrome</li>
<li>Firefox</li>
<li>Safari</li>
<li>Edge</li>
</ul>
<p><strong>Test Scenarios</strong>:</p>
<ul>
<li>Successful login</li>
<li>Failed login</li>
<li>Password reset</li>
<li>Mobile devices</li>
<li>Different screen sizes</li>
</ul>
<p><strong>Logout and Test</strong>: Always test as logged-out user to see actual login page.</p>
<h2 id="troubleshooting">Troubleshooting</h2>
<p><strong>Logo Not Appearing</strong>:</p>
<ul>
<li>Check image path</li>
<li>Verify image exists</li>
<li>Inspect browser console for 404 errors</li>
</ul>
<p><strong>Styles Not Applying</strong>:</p>
<ul>
<li>Clear browser cache</li>
<li>Check CSS syntax</li>
<li>Verify hook priority</li>
<li>Inspect element to see applied styles</li>
</ul>
<p><strong>Redirect Not Working</strong>:</p>
<ul>
<li>Verify user role checks</li>
<li>Test with different user roles</li>
<li>Check for conflicting plugins</li>
</ul>
<h2 id="best-practices">Best Practices</h2>
<p><strong>Keep It Simple</strong>: Overly complex designs may confuse users.</p>
<p><strong>Maintain Readability</strong>: Ensure sufficient contrast and legible fonts.</p>
<p><strong>Test Thoroughly</strong>: Verify functionality across devices and browsers.</p>
<p><strong>Backup First</strong>: Save working code before modifications.</p>
<p><strong>Use Child Themes</strong>: Prevent customization loss during theme updates.</p>
<p><strong>Performance</strong>: Optimize images and minimize CSS/JS.</p>
<h2 id="conclusion">Conclusion</h2>
<p>WordPress login page customization creates branded experiences through logo replacement, custom styling, background images, and security enhancements without plugins. Implement CSS modifications via login_enqueue_scripts hook, modify logo URL and title with filters, customize messages and redirects, and add security features like login attempt limiting. Code-based customization provides better performance, complete control, and professional client experiences.</p>
<h2 id="external-links">External Links</h2>
<ol type="1">
<li><a href="https://developer.wordpress.org/reference/hooks/login_enqueue_scripts/">WordPress Login Hooks</a></li>
<li><a href="https://codex.wordpress.org/Customizing_the_Login_Form">Login Customization Codex</a></li>
<li><a href="https://www.google.com/recaptcha/">Google reCAPTCHA</a></li>
<li><a href="https://cssgradient.io/">CSS Gradient Generator</a></li>
<li><a href="https://dribbble.com/tags/login">Login Page Inspiration</a></li>
</ol>
<h2 id="call-to-action">Call to Action</h2>
<p>Login customizations need protection. <a href="https://backupcopilotplugin.com/">Backup Copilot Pro</a> safeguards your WordPress custom code and configurations. Protect your login page modifications—start your free 30-day trial today!</p>
<p>The post <a href="https://developryplugins.com/how-to-customize-wordpress-login-page-without-plugins/">How to Customize WordPress Login Page Without Plugins</a> appeared first on <a href="https://developryplugins.com">Developry Plugins</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
