<?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>Mehdi Nazari: WordPress Developer</title>
	<atom:link href="https://mehdinazari.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://mehdinazari.com</link>
	<description>Tips for WordPress plugin development, WordPress template design and WordPress SEO by experienced WordPress developer Mehdi Nazari</description>
	<lastBuildDate>Sat, 17 Jun 2023 08:25:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>983 WordPress Education Themes &#124; June 2023 Compare</title>
		<link>https://mehdinazari.com/wordpress-education-themes/</link>
					<comments>https://mehdinazari.com/wordpress-education-themes/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Sat, 03 Jun 2023 10:35:30 +0000</pubDate>
				<category><![CDATA[Top WordPress Themes]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Facts]]></category>
		<category><![CDATA[WordPress Showcase]]></category>
		<category><![CDATA[Best WordPress Themes]]></category>
		<category><![CDATA[Comparing WordPress Themes]]></category>
		<category><![CDATA[Introducing WordPress Themes]]></category>
		<category><![CDATA[WordPress Themes Review]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=7326</guid>

					<description><![CDATA[<p>I found 983 WordPress Education Themes, free &#38; premium, and reviewed them to tell you the best theme for WordPress educational websites (statistics + charts) Summary: What I Learned After Checking 983 WordPress Education Themes My key findings after reviewing available WordPress themes for educational websites at the start of June 2023 are listed here: [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/wordpress-education-themes/">983 WordPress Education Themes | June 2023 Compare</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>I found 983 WordPress Education Themes, free &amp; premium, and reviewed them to tell you the best theme for WordPress educational websites (statistics + charts)</p>



<span id="more-7326"></span>



<h2 class="wp-block-heading"><strong>Summary:</strong> What I Learned After Checking 983 WordPress Education Themes</h2>



<p>My key findings after reviewing available WordPress themes for educational websites at the <strong>start of June 2023</strong> are listed here:</p>



<ul class="wp-block-list">
<li>The WordPress themes directory has 511 free education themes</li>



<li>Free educational themes have 21.24 million downloads in total (WordPress directory of themes)</li>



<li>The best free WordPress theme for an educational website is <a href="https://wordpress.org/themes/total/" target="_blank" rel="noopener" title="">Total by HashThemes</a></li>



<li>The most popular marketplace for purchasing premium education themes is ThemeForest, with 209 themes available and over 266K purchases made to this date</li>



<li>The best-selling premium education theme is <a href="https://themeforest.net/item/education-wordpress-theme-education-wp/14058034" target="_blank" rel="noopener" title="">Eduma</a>, with 39.1K sales</li>



<li>The cheapest WordPress theme for an educational website is <a href="https://themeforest.net/item/buntington-education-wp-theme/8509553" target="_blank" rel="noopener" title="">Buntington</a> ($17)</li>



<li>The most expensive WordPress themes for educational websites are <a href="https://themeforest.net/item/eduin-online-course-wordpress-theme/22722676" target="_blank" rel="noopener" title="">Eduin</a>, <a href="https://themeforest.net/item/learn-education-elearning-wordpress-theme/15202423" target="_blank" rel="noopener" title="">Learn</a>, and <a href="https://themeforest.net/item/edufair-multipurpose-wordpress-theme-for-education/22002806" target="_blank" rel="noopener" title="">Edufair</a> ($199)</li>



<li>The weighted average rating for premium educational themes is 4.62 out of 5 (from 12,709 reviews in the ThemeForest &amp; TemplateMonster)</li>



<li>Premium educational themes have 275K purchases in total (ThemeForest &amp; TemplateMonster)</li>
</ul>



<h2 class="wp-block-heading">Finding WordPress Education Themes</h2>



<p>If you are looking for an education theme for WordPress, check these places to download the best options:</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img fetchpriority="high" decoding="async" width="2400" height="1260" src="https://mehdinazari.com/wp-content/uploads/2023/06/wp-education-themes-chart-free-vs-premium.jpg" alt="Chart of available education themes for WordPress" class="wp-image-7469" srcset="https://mehdinazari.com/wp-content/uploads/2023/06/wp-education-themes-chart-free-vs-premium.jpg 2400w, https://mehdinazari.com/wp-content/uploads/2023/06/wp-education-themes-chart-free-vs-premium-300x158.jpg 300w, https://mehdinazari.com/wp-content/uploads/2023/06/wp-education-themes-chart-free-vs-premium-1024x538.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2023/06/wp-education-themes-chart-free-vs-premium-768x403.jpg 768w, https://mehdinazari.com/wp-content/uploads/2023/06/wp-education-themes-chart-free-vs-premium-1536x806.jpg 1536w, https://mehdinazari.com/wp-content/uploads/2023/06/wp-education-themes-chart-free-vs-premium-2048x1075.jpg 2048w, https://mehdinazari.com/wp-content/uploads/2023/06/wp-education-themes-chart-free-vs-premium-200x105.jpg 200w, https://mehdinazari.com/wp-content/uploads/2023/06/wp-education-themes-chart-free-vs-premium-600x315.jpg 600w, https://mehdinazari.com/wp-content/uploads/2023/06/wp-education-themes-chart-free-vs-premium-800x420.jpg 800w" sizes="(max-width: 2400px) 100vw, 2400px" /><figcaption class="wp-element-caption"><a href="https://mehdinazari.com/wp-content/uploads/2023/06/wp-education-themes-chart-free-vs-premium.jpg" target="_blank" rel="noopener" title="">Chart of available education themes for WordPress</a></figcaption></figure>
</div>


<h3 class="wp-block-heading"><strong>Official WordPress themes</strong> directory with 511 free education themes</h3>



<p>Free WordPress themes are available to download in the <a href="https://wordpress.org/themes/" title="">official directory of WordPress themes</a>, which <strong>has 10,860 themes for all kinds of websites</strong> to this date (beginning of June 2023).</p>



<p>The official <strong><a href="https://wordpress.org/themes/tags/education/" target="_blank" rel="noopener" title="">WordPress themes directory has 511 educational themes</a></strong> available for free download.</p>



<p>Currently, <strong>4.7% of WordPress&#8217;s official directory themes are educational</strong>.</p>



<p>The <strong>only commercial education theme in the official WordPress directory is the <a href="https://wordpress.org/themes/featuredlite/" target="_blank" rel="noopener" title="">FeaturedLite theme</a></strong> which is available to download free but offers more features if you pay the cost ($59 for now, was $89).</p>



<h3 class="wp-block-heading"><strong>ThemeForest</strong> with 291 premium education themes for WordPress</h3>



<p>ThemeForest is a leading platform for premium WordPress themes, <a href="https://themeforest.net/category/wordpress/education" target="_blank" rel="noopener" title="">offering over 291 high-quality education themes</a>.</p>



<p>Most of these themes are created to satisfy the needs of educational institutions and individuals who want to create an online presence for their courses, tutorials, or other educational content.</p>



<p>With ThemeForest&#8217;s vast collection of education-focused WordPress templates, users can choose from various designs and features based on their preferences. And there is a live demo for themes to preview what you&#8217;ll get.</p>



<p>Whether running an e-learning platform or creating an online presence for your school or university department, ThemeForest has everything you need to build a professional-looking website quickly and easily.</p>



<p>The only downside is the pricing, which <strong>ranges between $17 to $199, excluding tax and handling fee</strong> per order.</p>



<p><strong>The handling fee for orders in ThemeForest is $1 for less than $10 orders, $2 for orders between $10 to $75, and any order above $75 has no fees</strong>.</p>



<h3 class="wp-block-heading"><strong>TemplateMonster</strong> with 181 premium education themes for WordPress</h3>



<p>TemplateMonster is a well-known digital marketplace offering various WordPress themes for various industries.</p>



<p>To this date, <strong>TemplateMonster has <a href="https://www.templatemonster.com/category/education-wordpress-themes/?page=5&amp;sort=highest" target="_blank" rel="noopener" title="">181 premium education themes for WordPress</a></strong> that offers to educational institutions such as schools, universities, online courses, and training centers.</p>



<p>These themes are designed to create user-friendly interfaces that can help educators build functional websites without coding or design skills. These themes have a live demo to test and compare themes before purchasing.</p>



<p>The <strong>price range for TemplateMonster&#8217;s WordPress education themes is between $24 to $109, including tax</strong>. And You may be able to get a 10% discount if you send them a message in live chat support. But <strong>there is a $2 handling fee for purchases over $10</strong>.</p>



<h2 class="wp-block-heading"><strong>Free Themes</strong> for WordPress Educational Websites</h2>



<p>As I mentioned before, the <strong>WordPress themes directory has 511 education themes</strong>, and <strong>more than half of them (277 themes) were updated or added in 2023</strong>:</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" width="2400" height="1260" src="https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-last-update-chart.jpg" alt="Chart of last update date for free WordPress education themes" class="wp-image-7427" srcset="https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-last-update-chart.jpg 2400w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-last-update-chart-300x158.jpg 300w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-last-update-chart-1024x538.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-last-update-chart-768x403.jpg 768w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-last-update-chart-1536x806.jpg 1536w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-last-update-chart-2048x1075.jpg 2048w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-last-update-chart-200x105.jpg 200w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-last-update-chart-600x315.jpg 600w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-last-update-chart-800x420.jpg 800w" sizes="(max-width: 2400px) 100vw, 2400px" /><figcaption class="wp-element-caption"><a href="https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-last-update-chart.jpg" target="_blank" rel="noopener" title="">Chart of last update date for free WordPress education themes</a></figcaption></figure>
</div>


<h3 class="wp-block-heading"><strong>The most popular</strong> free WordPress education themes in 2023 (based on active installs)</h3>



<p>Now that we&#8217;re in the middle of 2023, <strong>these 511 free WordPress education themes have 314,420 active installs</strong> in total.</p>



<p>From this number, <strong>less popular themes have 102,420 active installs in total </strong><strong>(&gt;1k active, 437 themes)</strong>, and <strong>popular themes (&lt;1k active, 71 themes) have 212,000 active installs</strong>.</p>



<p>This means <strong>14% of WordPress education themes are responsible for nearly 67.5% of active installs</strong>.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img decoding="async" src="https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-popular-vs-unpopular.jpg" alt="Count of popular vs. unpopular free active WordPress education themes" class="wp-image-7428" width="840" height="441" srcset="https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-popular-vs-unpopular.jpg 2400w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-popular-vs-unpopular-300x158.jpg 300w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-popular-vs-unpopular-1024x538.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-popular-vs-unpopular-768x403.jpg 768w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-popular-vs-unpopular-1536x806.jpg 1536w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-popular-vs-unpopular-2048x1075.jpg 2048w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-popular-vs-unpopular-200x105.jpg 200w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-popular-vs-unpopular-600x315.jpg 600w, https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-popular-vs-unpopular-800x420.jpg 800w" sizes="(max-width: 840px) 100vw, 840px" /><figcaption class="wp-element-caption"><a href="https://mehdinazari.com/wp-content/uploads/2023/06/wordpress-education-themes-popular-vs-unpopular.jpg" target="_blank" rel="noopener" title="">Count of popular vs. unpopular free active WordPress education themes</a></figcaption></figure>
</div>


<h4 class="wp-block-heading">Top 10 most popular free WordPress education themes in 2023 (based on active installs)</h4>



<p>Here is the list of 10 themes that have the most active installs from the WordPress themes directory (In the below list, `Total` is the name of a theme, not summation):</p>



<ol class="wp-block-list">
<li><a href="https://wordpress.org/themes/total/" target="_blank" rel="noopener" title="">Total</a> (name of a theme): 50K active installs</li>



<li><a href="https://wordpress.org/themes/tempera/" target="_blank" rel="noopener" title="">Tempera</a>: 10K active installs</li>



<li><a href="https://wordpress.org/themes/tutorstarter/" target="_blank" rel="noopener" title="">TutorStarter</a>: 10K active installs</li>



<li><a href="https://wordpress.org/themes/education-hub/" target="_blank" rel="noopener" title="">Education Hub</a>: 10K active installs</li>



<li><a href="https://wordpress.org/themes/shoppingcart/" target="_blank" rel="noopener" title="">ShoppingCart</a>: 8K active installs</li>



<li><a href="https://wordpress.org/themes/enigma/" target="_blank" rel="noopener" title="">Enigma</a>: 7K active installs</li>



<li><a href="https://wordpress.org/themes/catch-responsive/" target="_blank" rel="noopener" title="">Catch Responsive</a>: 6K active installs</li>



<li><a href="https://wordpress.org/themes/agama/" target="_blank" rel="noopener" title="">Agama</a>: 5K active installs</li>



<li><a href="https://wordpress.org/themes/education-base/" target="_blank" rel="noopener" title="">Education Base</a>: 5K active installs</li>



<li><a href="https://wordpress.org/themes/educational-zone/" target="_blank" rel="noopener" title="">Educational Zone</a>: 5K active installs</li>
</ol>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="2400" height="1600" src="https://mehdinazari.com/wp-content/uploads/2023/06/top-installed-free-wordpress-education-themes.jpg" alt="Top 10 installed free WordPress education themes" class="wp-image-7429" srcset="https://mehdinazari.com/wp-content/uploads/2023/06/top-installed-free-wordpress-education-themes.jpg 2400w, https://mehdinazari.com/wp-content/uploads/2023/06/top-installed-free-wordpress-education-themes-300x200.jpg 300w, https://mehdinazari.com/wp-content/uploads/2023/06/top-installed-free-wordpress-education-themes-1024x683.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2023/06/top-installed-free-wordpress-education-themes-768x512.jpg 768w, https://mehdinazari.com/wp-content/uploads/2023/06/top-installed-free-wordpress-education-themes-1536x1024.jpg 1536w, https://mehdinazari.com/wp-content/uploads/2023/06/top-installed-free-wordpress-education-themes-2048x1365.jpg 2048w, https://mehdinazari.com/wp-content/uploads/2023/06/top-installed-free-wordpress-education-themes-25x18.jpg 25w, https://mehdinazari.com/wp-content/uploads/2023/06/top-installed-free-wordpress-education-themes-864x576.jpg 864w, https://mehdinazari.com/wp-content/uploads/2023/06/top-installed-free-wordpress-education-themes-158x105.jpg 158w, https://mehdinazari.com/wp-content/uploads/2023/06/top-installed-free-wordpress-education-themes-473x315.jpg 473w, https://mehdinazari.com/wp-content/uploads/2023/06/top-installed-free-wordpress-education-themes-800x533.jpg 800w" sizes="auto, (max-width: 2400px) 100vw, 2400px" /><figcaption class="wp-element-caption"><a href="https://mehdinazari.com/wp-content/uploads/2023/06/top-installed-free-wordpress-education-themes.jpg" target="_blank" rel="noopener" title="">Top 10 installed free WordPress education themes</a></figcaption></figure>
</div>


<h3 class="wp-block-heading"><strong>The most downloaded</strong> free WordPress education themes</h3>



<p>To make this more helpful, I compared the download counts for 2023 and all years in two sections:</p>



<h4 class="wp-block-heading">Most downloaded free education themes in 2023</h4>



<p>These themes are the most downloaded WordPress education themes in 2023:</p>



<ol class="wp-block-list">
<li><a href="https://wordpress.org/themes/total/" target="_blank" rel="noreferrer noopener">Total</a>: 55.8K downloads in 2023</li>



<li><a href="https://wordpress.org/themes/pressbook/" target="_blank" rel="noreferrer noopener">PressBook</a>: 41.3K downloads in 2023</li>



<li><a href="https://wordpress.org/themes/tutorstarter/" target="_blank" rel="noreferrer noopener">TutorStarter</a>: 17.6K downloads in 2023</li>



<li><a href="https://wordpress.org/themes/elearning-education/" target="_blank" rel="noreferrer noopener">eLearning Education</a>: 17.2K downloads in 2023</li>



<li><a href="https://wordpress.org/themes/oceanly/" target="_blank" rel="noreferrer noopener">Oceanly</a>: 17.1K downloads in 2023</li>



<li><a href="https://wordpress.org/themes/eduvert/" target="_blank" rel="noreferrer noopener">Eduvert</a>: 16.7K downloads in 2023</li>



<li><a href="https://wordpress.org/themes/education-zone/" target="_blank" rel="noreferrer noopener">Education Zone</a>: 16.3K downloads in 2023</li>



<li><a href="https://wordpress.org/themes/education-insight/" target="_blank" rel="noreferrer noopener">Education Insight</a>: 16K downloads in 2023</li>



<li><a href="https://wordpress.org/themes/author-writer/" target="_blank" rel="noreferrer noopener">Author Writer</a>: 12.8K downloads in 2023</li>



<li><a href="https://wordpress.org/themes/lms-education/" target="_blank" rel="noreferrer noopener">LMS Education</a>: 12.5K downloads in 2023</li>
</ol>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="2400" height="1600" src="https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-2023.jpg" alt="Top 10 most downloaded free WordPress education themes in 2023" class="wp-image-7430" srcset="https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-2023.jpg 2400w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-2023-300x200.jpg 300w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-2023-1024x683.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-2023-768x512.jpg 768w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-2023-1536x1024.jpg 1536w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-2023-2048x1365.jpg 2048w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-2023-25x18.jpg 25w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-2023-864x576.jpg 864w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-2023-158x105.jpg 158w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-2023-473x315.jpg 473w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-2023-800x533.jpg 800w" sizes="auto, (max-width: 2400px) 100vw, 2400px" /><figcaption class="wp-element-caption"><a href="https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-2023.jpg" target="_blank" rel="noopener" title="">Top 10 most downloaded free WordPress education themes in 2023</a></figcaption></figure>
</div>


<h4 class="wp-block-heading">Most downloaded free education themes in all years</h4>



<p>Here is the list of the most downloaded free education themes of all time (2023 and before):</p>



<ol class="wp-block-list">
<li><a href="https://wordpress.org/themes/enigma/" target="_blank" rel="noreferrer noopener">Enigma</a>: 1.25M total downloads</li>



<li><a href="https://wordpress.org/themes/total/" target="_blank" rel="noreferrer noopener">Total</a>: 988.5K total downloads</li>



<li><a href="https://wordpress.org/themes/tempera/" target="_blank" rel="noreferrer noopener">Tempera</a>: 690K total downloads</li>



<li><a href="https://wordpress.org/themes/agama/" target="_blank" rel="noreferrer noopener">Agama</a>: 666K total downloads</li>



<li><a href="https://wordpress.org/themes/catch-responsive/" target="_blank" rel="noreferrer noopener">Catch Responsive</a>: 466.9K total downloads</li>



<li><a href="https://wordpress.org/themes/education-hub/" target="_blank" rel="noreferrer noopener">Education Hub</a>: 425.3K total downloads</li>



<li><a href="https://wordpress.org/themes/education-zone/" target="_blank" rel="noreferrer noopener">Education Zone</a>: 394.7K total downloads</li>



<li><a href="https://wordpress.org/themes/catch-kathmandu/" target="_blank" rel="noreferrer noopener">Catch Kathmandu</a>: 363.2K total downloads</li>



<li><a href="https://wordpress.org/themes/catch-everest/" target="_blank" rel="noreferrer noopener">Catch Everest</a>: 333.2K total downloads</li>



<li><a href="https://wordpress.org/themes/simplify/" target="_blank" rel="noreferrer noopener">Simplify</a>: 326.9K total downloads</li>
</ol>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="2400" height="1600" src="https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-all.jpg" alt="Top 10 most downloaded free WordPress education themes in all years" class="wp-image-7431" srcset="https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-all.jpg 2400w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-all-300x200.jpg 300w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-all-1024x683.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-all-768x512.jpg 768w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-all-1536x1024.jpg 1536w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-all-2048x1365.jpg 2048w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-all-25x18.jpg 25w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-all-864x576.jpg 864w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-all-158x105.jpg 158w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-all-473x315.jpg 473w, https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-all-800x533.jpg 800w" sizes="auto, (max-width: 2400px) 100vw, 2400px" /><figcaption class="wp-element-caption"><a href="https://mehdinazari.com/wp-content/uploads/2023/06/top-downloaded-free-wordpress-education-themes-all.jpg" target="_blank" rel="noopener" title="">Top 10 most downloaded free WordPress education themes in all years</a></figcaption></figure>
</div>


<h3 class="wp-block-heading"><strong>My picks</strong> for the best free WordPress education themes</h3>



<p>Below tables is the list of best WordPress themes for an educational WordPress website. These themes may not be the most downloaded or rated in the WordPress directory, but I still think they are the best.</p>



<figure class="wp-block-table aligncenter has-medium-font-size"><table><thead><tr><th class="has-text-align-left" data-align="left">Theme Name</th><th class="has-text-align-center" data-align="center">Installs</th><th class="has-text-align-center" data-align="center">Total Downloads</th><th class="has-text-align-center" data-align="center">2023 Downloads</th><th class="has-text-align-center" data-align="center">Rating</th><th class="has-text-align-center" data-align="center">Update</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left"><a href="https://wordpress.org/themes/total/" target="_blank" rel="noopener" title="">Total</a></td><td class="has-text-align-center" data-align="center">50K</td><td class="has-text-align-center" data-align="center">1.25M</td><td class="has-text-align-center" data-align="center">55.8K</td><td class="has-text-align-center" data-align="center">4.5/5<br />57 Reviews</td><td class="has-text-align-center" data-align="center">2023<br />June 1</td></tr><tr><td class="has-text-align-left" data-align="left"><a href="https://wordpress.org/themes/education-hub/" target="_blank" rel="noopener" title="Education Hub">Education Hub</a></td><td class="has-text-align-center" data-align="center">10K</td><td class="has-text-align-center" data-align="center">425.3K</td><td class="has-text-align-center" data-align="center">4.6K</td><td class="has-text-align-center" data-align="center">4.5/5<br />17 Reviews</td><td class="has-text-align-center" data-align="center">2022<br />Aug 24</td></tr><tr><td class="has-text-align-left" data-align="left"><a href="https://wordpress.org/themes/education-zone/" target="_blank" rel="noopener" title="">Education Zone</a></td><td class="has-text-align-center" data-align="center">4K</td><td class="has-text-align-center" data-align="center">394.7K</td><td class="has-text-align-center" data-align="center">16.3K</td><td class="has-text-align-center" data-align="center">5/5<br />38 Reviews</td><td class="has-text-align-center" data-align="center">2022<br />Oct 11</td></tr><tr><td class="has-text-align-left" data-align="left"><a href="https://wordpress.org/themes/agama/" target="_blank" rel="noopener" title="">Agama</a></td><td class="has-text-align-center" data-align="center">5K</td><td class="has-text-align-center" data-align="center">666K</td><td class="has-text-align-center" data-align="center">3.7K</td><td class="has-text-align-center" data-align="center">4.5/5<br />44 Reviews</td><td class="has-text-align-center" data-align="center">2022<br />Apr 17</td></tr><tr><td class="has-text-align-left" data-align="left"><a href="https://wordpress.org/themes/elearning-education/" target="_blank" rel="noopener" title="">eLearning Education</a></td><td class="has-text-align-center" data-align="center">600</td><td class="has-text-align-center" data-align="center">60.3K</td><td class="has-text-align-center" data-align="center">17.2K</td><td class="has-text-align-center" data-align="center">5/5<br />2 Reviews</td><td class="has-text-align-center" data-align="center">2023<br />May 13</td></tr><tr><td class="has-text-align-left" data-align="left"><a href="https://wordpress.org/themes/author-writer/" target="_blank" rel="noopener" title="">Author Writer</a></td><td class="has-text-align-center" data-align="center">300</td><td class="has-text-align-center" data-align="center">28.4K</td><td class="has-text-align-center" data-align="center">12.8K</td><td class="has-text-align-center" data-align="center">3.5/5<br />2 Reviews</td><td class="has-text-align-center" data-align="center">2023<br />May 22</td></tr><tr><td class="has-text-align-left" data-align="left"><a href="https://wordpress.org/themes/kindergarten-education/" target="_blank" rel="noopener" title="">Kindergarten Education</a></td><td class="has-text-align-center" data-align="center">500</td><td class="has-text-align-center" data-align="center">98.2K</td><td class="has-text-align-center" data-align="center">5.9K</td><td class="has-text-align-center" data-align="center">4.5/5<br />6 Reviews</td><td class="has-text-align-center" data-align="center">2023<br />May 26</td></tr><tr><td class="has-text-align-left" data-align="left"><a href="https://wordpress.org/themes/vw-kindergarten/" target="_blank" rel="noopener" title="">VW Kindergarten</a></td><td class="has-text-align-center" data-align="center">200</td><td class="has-text-align-center" data-align="center">13K</td><td class="has-text-align-center" data-align="center">2.9K</td><td class="has-text-align-center" data-align="center">None</td><td class="has-text-align-center" data-align="center">2023<br />May 20</td></tr></tbody></table></figure>



<h2 class="wp-block-heading"><strong>Premium Themes</strong> for WordPress Educational Websites</h2>



<p>I checked premium themes in ThemeForest and TemplateMonster. These two marketplaces are very popular when it&#8217;s come to premium WordPress themes.</p>



<p><strong>ThemeForest has 291 education themes</strong> for WordPress, and <strong>TemplateMonster has 181 themes</strong>.</p>



<h3 class="wp-block-heading">Top seller Premium WordPress education themes</h3>



<p><strong>ThemeForest has sold WordPress education themes over 266K times</strong>. And <strong>TemplateMonster has sold education themes over 9K times</strong> to this date (June 2023).</p>



<h4 class="wp-block-heading">Top seller WordPress education themes on ThemeForest</h4>



<p>These themes are the top 10 most-sold WordPress education themes on ThemeForest:</p>



<ol class="wp-block-list">
<li><a href="https://themeforest.net/item/education-wordpress-theme-education-wp/14058034" target="_blank" rel="noreferrer noopener">Eduma</a>: 39.1K sales</li>



<li><a href="https://themeforest.net/item/wplms-learning-management-system/6780226" target="_blank" rel="noreferrer noopener">WPLMS</a>: 27.4K sales</li>



<li><a href="https://themeforest.net/item/masterstudy-education-center-wordpress-theme/12170274" target="_blank" rel="noreferrer noopener">Masterstudy</a>: 18.8K sales</li>



<li><a href="https://themeforest.net/item/speaker-and-life-coach-wordpress-theme-coaching-wp/17097658" target="_blank" rel="noreferrer noopener">Coaching</a>: 6.6K sales</li>



<li><a href="https://themeforest.net/item/lms-learning-management-system-education-lms-wordpress-theme/7867581" target="_blank" rel="noreferrer noopener">LMS Education Theme</a>: 6.1K sales</li>



<li><a href="https://themeforest.net/item/university-education-event-and-course-theme/8412116" target="_blank" rel="noreferrer noopener">University</a>: 5.9K sales</li>



<li><a href="https://themeforest.net/item/course-builder-wordpress-learning-management-system-theme-elearning-software/20370918" target="_blank" rel="noreferrer noopener">Course Builder</a>: 5.1K sales</li>



<li><a href="https://themeforest.net/item/the-keynote-conference-event-meeting-wordpress-theme/9718856" target="_blank" rel="noreferrer noopener">The Keynote</a>: 5K sales</li>



<li><a href="https://themeforest.net/item/clever-course-learning-management-system-theme/8645312" target="_blank" rel="noreferrer noopener">Clever Course</a>: 4.7K sales</li>



<li><a href="https://themeforest.net/item/grand-college-wordpress-theme-for-education/1865598" target="_blank" rel="noreferrer noopener">Grand College</a>: 4.6K sales</li>
</ol>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="2400" height="1600" src="https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-themeforest.jpg" alt="Top 10 most-sold education themes on ThemeForest until June 2023" class="wp-image-7452" srcset="https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-themeforest.jpg 2400w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-themeforest-300x200.jpg 300w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-themeforest-1024x683.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-themeforest-768x512.jpg 768w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-themeforest-1536x1024.jpg 1536w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-themeforest-2048x1365.jpg 2048w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-themeforest-25x18.jpg 25w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-themeforest-864x576.jpg 864w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-themeforest-158x105.jpg 158w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-themeforest-473x315.jpg 473w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-themeforest-800x533.jpg 800w" sizes="auto, (max-width: 2400px) 100vw, 2400px" /><figcaption class="wp-element-caption"><a href="https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-themeforest.jpg" target="_blank" rel="noopener" title="">Top 10 most-sold education themes on ThemeForest until June 2023</a></figcaption></figure>
</div>


<h4 class="wp-block-heading">Top seller WordPress education themes on TemplateMonster</h4>



<p>These themes are the top 10 best seller WordPress education themes on TemplateMonster:</p>



<ol class="wp-block-list">
<li><a href="https://www.templatemonster.com/wordpress-themes/81170.html" target="_blank" rel="noreferrer noopener">Innomerce</a>: 622 sales</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/poket-business-and-multipurpose-responsive-wordpress-theme-220512.html" target="_blank" rel="noreferrer noopener">Poket</a>: 584 sales</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/51770.html" target="_blank" rel="noreferrer noopener">High School</a>: 417 sales</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/52949.html" target="_blank" rel="noreferrer noopener">Legend</a>: 351 sales</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/55026.html" target="_blank" rel="noreferrer noopener">School District</a>: 292 sales</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/themex-multipurpose-responsive-wordpress-theme-122890.html" target="_blank" rel="noreferrer noopener">Themex</a>: 269 sales</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/happy-learning-primary-school-wordpress-theme-60129.html" target="_blank" rel="noreferrer noopener">Happy Learning</a>: 231 sales</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/54991.html" target="_blank" rel="noreferrer noopener">Englot</a>: 220 sales</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/educat-education-wordpress-theme-70629.html" target="_blank" rel="noreferrer noopener">Educat</a>: 218 sales</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/education-hub-wordpress-theme-58872.html" target="_blank" rel="noreferrer noopener">Education</a>: 208 sales</li>
</ol>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="2400" height="1600" src="https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-templatemonster.jpg" alt="Top 10 most-sold education themes on TemplateMonster until June 2023" class="wp-image-7472" srcset="https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-templatemonster.jpg 2400w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-templatemonster-300x200.jpg 300w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-templatemonster-1024x683.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-templatemonster-768x512.jpg 768w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-templatemonster-1536x1024.jpg 1536w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-templatemonster-2048x1365.jpg 2048w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-templatemonster-25x18.jpg 25w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-templatemonster-864x576.jpg 864w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-templatemonster-158x105.jpg 158w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-templatemonster-473x315.jpg 473w, https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-templatemonster-800x533.jpg 800w" sizes="auto, (max-width: 2400px) 100vw, 2400px" /><figcaption class="wp-element-caption"><a href="https://mehdinazari.com/wp-content/uploads/2023/06/most-sold-education-themes-templatemonster.jpg" target="_blank" rel="noopener" title="">Top 10 most-sold education themes on TemplateMonster until June 2023</a></figcaption></figure>
</div>


<h3 class="wp-block-heading"><strong>The average price</strong> of premium WordPress education themes in 2023</h3>



<p><strong>ThemeForest has higher prices than TemplateMonster</strong>. Also, in the below prices, taxation is not included.</p>



<p>TemplateMonster shows the final price for themes, but ThemeForest adds the tax when you want to checkout.</p>



<p>The <strong>good thing about ThemeForest is the vast collection</strong> of WordPress education themes.</p>



<h4 class="wp-block-heading">The average price of education themes in ThemeForest</h4>



<p><strong>$61 is the average price in ThemeForest</strong> for a WordPress education theme (summation of prices/count of themes).</p>



<p><strong>$59 is ThemeForest&#8217;s most popular pricing tag</strong> for WordPress education themes. I found <strong>69 education themes with a $59 price tag</strong>.</p>



<p>After that, <strong>$69 is ThemeForest&#8217;s second most popular pricing tag for WordPress education themes</strong>. I found <strong>49 themes that have a $69 price tag</strong>.</p>



<p>The <strong>third place of most popular pricing tags is $49</strong>, with <strong>48 themes</strong> under this price.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="2400" height="1600" src="https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-themeforest.jpg" alt="Count of WordPress education themes for each price range on ThemeForest" class="wp-image-7455" srcset="https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-themeforest.jpg 2400w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-themeforest-300x200.jpg 300w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-themeforest-1024x683.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-themeforest-768x512.jpg 768w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-themeforest-1536x1024.jpg 1536w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-themeforest-2048x1365.jpg 2048w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-themeforest-25x18.jpg 25w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-themeforest-864x576.jpg 864w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-themeforest-158x105.jpg 158w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-themeforest-473x315.jpg 473w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-themeforest-800x533.jpg 800w" sizes="auto, (max-width: 2400px) 100vw, 2400px" /><figcaption class="wp-element-caption"><a href="https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-themeforest.jpg" target="_blank" rel="noopener" title="">Count of WordPress education themes for each price range on ThemeForest</a></figcaption></figure>
</div>


<h4 class="wp-block-heading">The average price of education themes in TemplateMonster</h4>



<p><strong>$61.7 is the average price in TemplateMonster</strong> for a WordPress education theme (summation of prices/count of themes).</p>



<p><strong>$67 is ThemeForest&#8217;s most popular pricing tag</strong> for WordPress education themes. I found <strong>37 education themes with a $67 price tag</strong>.</p>



<p><strong>Second popular pricing tag is $85 with 24 themes</strong> under this price. <strong>Third place belongs to $83 with 11 themes</strong>.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="2400" height="1600" src="https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-templatemonster.jpg" alt="Count of WordPress education themes for each price range on TemplateMonster" class="wp-image-7473" srcset="https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-templatemonster.jpg 2400w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-templatemonster-300x200.jpg 300w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-templatemonster-1024x683.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-templatemonster-768x512.jpg 768w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-templatemonster-1536x1024.jpg 1536w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-templatemonster-2048x1365.jpg 2048w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-templatemonster-25x18.jpg 25w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-templatemonster-864x576.jpg 864w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-templatemonster-158x105.jpg 158w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-templatemonster-473x315.jpg 473w, https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-templatemonster-800x533.jpg 800w" sizes="auto, (max-width: 2400px) 100vw, 2400px" /><figcaption class="wp-element-caption"><a href="https://mehdinazari.com/wp-content/uploads/2023/06/price-ranges-education-themes-templatemonster.jpg" target="_blank" rel="noopener" title="">Count of WordPress education themes for each price range on TemplateMonster</a></figcaption></figure>
</div>


<h3 class="wp-block-heading"><strong>The maximum price</strong> of premium WordPress education themes in 2023</h3>



<p>Read below to see the maximum price for education themes and which are the most expensive themes.</p>



<h4 class="wp-block-heading">The maximum price of education themes in ThemeForest</h4>



<p>The <strong>highest price for a WordPress education theme in Themeforest is $199</strong>. The Learn theme, Edufair Theme, and Eduin theme are priced at 199 dollars. Learn has 305 sales, Edufair has 119 sales, and Eduin has 112 sales to this date (June 2023).</p>



<p>Here is the list of the top 10 most expensive education themes for WordPress in ThemeForest:</p>



<ol class="wp-block-list">
<li><a href="https://themeforest.net/item/eduin-online-course-wordpress-theme/22722676" target="_blank" rel="noreferrer noopener">Eduin</a>: $199 (112 purchases)</li>



<li><a href="https://themeforest.net/item/learn-education-elearning-wordpress-theme/15202423" target="_blank" rel="noreferrer noopener">Learn</a>: $199 (305 purchases)</li>



<li><a href="https://themeforest.net/item/edufair-multipurpose-wordpress-theme-for-education/22002806" target="_blank" rel="noreferrer noopener">Edufair</a>: $199 (119 purchases)</li>



<li><a href="https://themeforest.net/item/driving-school-wordpress-theme/20616993" target="_blank" rel="noreferrer noopener">Driving School</a>: $149 (298 purchases)</li>



<li><a href="https://themeforest.net/item/education-world-wordpress-theme/19787236" target="_blank" rel="noreferrer noopener">Education World</a>: $129 (85 purchases)</li>



<li><a href="https://themeforest.net/item/eduvision-education-wordpress-theme/23178465" target="_blank" rel="noreferrer noopener">Eduvision</a>: $129 (41 purchases)</li>



<li><a href="https://themeforest.net/item/elms-educational-material-wordpress-theme/20829728" target="_blank" rel="noreferrer noopener">Elms</a>: $129 (35 purchases)</li>



<li><a href="https://themeforest.net/item/learnpro-education-wordpress-theme/22077614" target="_blank" rel="noreferrer noopener">LearnPro</a>: $129 (211 purchases)</li>



<li><a href="https://themeforest.net/item/elearn-onepage-bootstrap-education-wordpress-theme/15506200" target="_blank" rel="noreferrer noopener">e-Learn</a>: $129 (87 purchases)</li>



<li><a href="https://themeforest.net/item/nolez-education-wordpress-theme/25886275" target="_blank" rel="noreferrer noopener">Nolez</a>: $129 (14 purchases)</li>
</ol>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="2400" height="1600" src="https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-themeforest.jpg" alt="Most expensive WordPress education themes on ThemeForest" class="wp-image-7465" srcset="https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-themeforest.jpg 2400w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-themeforest-300x200.jpg 300w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-themeforest-1024x683.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-themeforest-768x512.jpg 768w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-themeforest-1536x1024.jpg 1536w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-themeforest-2048x1365.jpg 2048w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-themeforest-25x18.jpg 25w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-themeforest-864x576.jpg 864w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-themeforest-158x105.jpg 158w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-themeforest-473x315.jpg 473w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-themeforest-800x533.jpg 800w" sizes="auto, (max-width: 2400px) 100vw, 2400px" /><figcaption class="wp-element-caption"><a href="https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-themeforest.jpg" target="_blank" rel="noopener" title="">Most expensive WordPress education themes on ThemeForest</a></figcaption></figure>
</div>


<h4 class="wp-block-heading">The maximum price of education themes in TemplateMonster</h4>



<p>These themes are the top 10 most expensive WordPress education themes on TemplateMonster:</p>



<ol class="wp-block-list">
<li><a href="https://www.templatemonster.com/wordpress-themes/education-wordpress-theme-edme-242997.html" target="_blank" rel="noreferrer noopener">Education</a>: $109 (4 purchases)</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/55026.html" target="_blank" rel="noreferrer noopener">School District</a>: $89 (292 purchases)</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/50861.html" target="_blank" rel="noreferrer noopener">University</a>: $85 (103 purchases)</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/42116.html" target="_blank" rel="noreferrer noopener">Solid University</a>: $85 (23 purchases)</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/49141.html" target="_blank" rel="noreferrer noopener">Career &amp; Special Education</a>: $85 (45 purchases)</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/53676.html" target="_blank" rel="noreferrer noopener">Education Help</a>: $85 (97 purchases)</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/49081.html" target="_blank" rel="noreferrer noopener">Primary School Responsive</a>: $85 (58 purchases)</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/48547.html" target="_blank" rel="noreferrer noopener">Education Responsive</a>: $85 (31 purchases)</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/53988.html" target="_blank" rel="noreferrer noopener">Language School Responsive</a>: $85 (72 purchases)</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/52553.html" target="_blank" rel="noreferrer noopener">Translation Bureau</a>: $85 (18 purchases)</li>
</ol>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="2400" height="1600" src="https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-templatemonster.jpg" alt="Most expensive WordPress education themes on TemplateMonster" class="wp-image-7475" srcset="https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-templatemonster.jpg 2400w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-templatemonster-300x200.jpg 300w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-templatemonster-1024x683.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-templatemonster-768x512.jpg 768w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-templatemonster-1536x1024.jpg 1536w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-templatemonster-2048x1365.jpg 2048w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-templatemonster-25x18.jpg 25w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-templatemonster-864x576.jpg 864w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-templatemonster-158x105.jpg 158w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-templatemonster-473x315.jpg 473w, https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-templatemonster-800x533.jpg 800w" sizes="auto, (max-width: 2400px) 100vw, 2400px" /><figcaption class="wp-element-caption"><a href="https://mehdinazari.com/wp-content/uploads/2023/06/most-expensive-education-themes-templatemonster.jpg" target="_blank" rel="noopener" title="">Most expensive WordPress education themes on TemplateMonster</a></figcaption></figure>
</div>


<h3 class="wp-block-heading"><strong>The minimum price</strong> of premium WordPress education themes in 2023</h3>



<p><strong>Only with $17, you can buy a premium education theme</strong> for WordPress. But which theme? Read below to check the name.</p>



<h4 class="wp-block-heading">The minimum price of education themes in ThemeForest</h4>



<p>The <strong>lowest price for a WordPress education theme in Themeforest is $17</strong>. The <a href="https://themeforest.net/item/buntington-education-wp-theme/8509553" target="_blank" rel="noopener" title="">Buntington theme</a> is priced at 17 dollars and has 1.4K sales to this date (June 2023).</p>



<h4 class="wp-block-heading">The minimum price of education themes in TemplateMonster</h4>



<p>Cheapest education themes on TemplateMoster have $24 pricing tag. With $24 you have four options, <a href="https://www.templatemonster.com/wordpress-themes/daksh-hinduism-religious-wordpress-theme-329814.html" target="_blank" rel="noopener" title="Daksh">Daksh</a>, <a href="https://www.templatemonster.com/wordpress-themes/hindpray-religious-temple-wordpress-template-310706.html" target="_blank" rel="noopener" title="">HindPray</a>, <a href="https://www.templatemonster.com/wordpress-themes/edulab-global-education-and-learning-wordpress-theme-244262.html" target="_blank" rel="noopener" title="">Edulab</a>, and <a href="https://www.templatemonster.com/wordpress-themes/education-pro-lms-education-wordpress-theme-77372.html" target="_blank" rel="noopener" title="">Education Pro</a> are the cheapest education themes on TemplateMonster.</p>



<h3 class="wp-block-heading"><strong>The best-rated</strong> premium WordPress education theme</h3>



<p>Ratings on ThemeForest seem more legit and most of themes have reviews on them. And <strong>there are 60 education themes with no reviews on ThemeForest</strong> (around 20% of themes). On the other hand, <strong>TemplateMonster has 88 education themes with no reviews</strong> (around 48% of themes).</p>



<h4 class="wp-block-heading">The best-rated education theme in ThemeForest</h4>



<p>The <strong>weighted average rate for all education themes in ThemeForest is 4.62 out of 5</strong> from 12,253 customer reviews.</p>



<p>I excluded any theme with less than 50 reviews in the below list for a better result. Therefore, these themes are the top 10 best rated Education themes with over 50 reviews in ThemeForest:</p>



<ol class="wp-block-list">
<li><a href="https://themeforest.net/item/edubin-education-lms-wordpress-theme/24037792" target="_blank" rel="noreferrer noopener">Edubin</a>: Rated 4.97/5 from 177 Reviews</li>



<li><a href="https://themeforest.net/item/eshkool-education-lms-wordpress-theme/22458018" target="_blank" rel="noreferrer noopener">Eshkool</a>: Rated 4.9/5 from 67 Reviews</li>



<li><a href="https://themeforest.net/item/maxcoach-online-courses-education-wp-theme/26051639" target="_blank" rel="noreferrer noopener">MaxCoach</a>: Rated 4.86/5 from 98 Reviews</li>



<li><a href="https://themeforest.net/item/education-wordpress-theme-education-wp/14058034" target="_blank" rel="noreferrer noopener">Eduma</a>: Rated 4.86/5 from 2027 Reviews</li>



<li><a href="https://themeforest.net/item/speaker-and-life-coach-wordpress-theme-coaching-wp/17097658" target="_blank" rel="noreferrer noopener">Coaching</a>: Rated 4.85/5 from 219 Reviews</li>



<li><a href="https://themeforest.net/item/edumall-lms-education-wordpress-theme/29240444" target="_blank" rel="noreferrer noopener">EduMall</a>: Rated 4.84/5 from 117 Reviews</li>



<li><a href="https://themeforest.net/item/enfant-school-and-kindergarten-wordpress-theme/20121401" target="_blank" rel="noreferrer noopener">Enfant</a>: Rated 4.84/5 from 97 Reviews</li>



<li><a href="https://themeforest.net/item/kiddy-children-wordpress-theme/13025968" target="_blank" rel="noreferrer noopener">Kiddy</a>: Rated 4.83/5 from 71 Reviews</li>



<li><a href="https://themeforest.net/item/eikra-education-wordpress-theme/20950897" target="_blank" rel="noreferrer noopener">Eikra</a>: Rated 4.82/5 from 90 Reviews</li>



<li><a href="https://themeforest.net/item/kingster-education-wordpress-theme-for-university-college-and-school/22473937" target="_blank" rel="noreferrer noopener">Kingster</a>: Rated 4.82/5 from 142 Reviews</li>
</ol>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="2400" height="1600" src="https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-themeforest.jpg" alt="Top 10 best-rated WordPress education themes on ThemeForest (over 50 reviews)" class="wp-image-7464" srcset="https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-themeforest.jpg 2400w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-themeforest-300x200.jpg 300w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-themeforest-1024x683.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-themeforest-768x512.jpg 768w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-themeforest-1536x1024.jpg 1536w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-themeforest-2048x1365.jpg 2048w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-themeforest-25x18.jpg 25w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-themeforest-864x576.jpg 864w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-themeforest-158x105.jpg 158w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-themeforest-473x315.jpg 473w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-themeforest-800x533.jpg 800w" sizes="auto, (max-width: 2400px) 100vw, 2400px" /><figcaption class="wp-element-caption"><a href="https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-themeforest.jpg" target="_blank" rel="noopener" title="">Top 10 best-rated WordPress education themes on ThemeForest (over 50 reviews)</a></figcaption></figure>
</div>


<h4 class="wp-block-heading">The best-rated education theme in TemplateMonster</h4>



<p><strong>Average customer rate</strong> for education themes on TemplateMonster is <strong>4.66 out of 5 from 456 ratings</strong>.</p>



<p>These themes are the top 10 best-rated education themes on Template monster (with 10+ reviews only):</p>



<ol class="wp-block-list">
<li><a href="https://www.templatemonster.com/wordpress-themes/poket-business-and-multipurpose-responsive-wordpress-theme-220512.html" target="_blank" rel="noreferrer noopener">Poket</a>: Rated 5.00/5 from 15 Reviews</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/rainbow-colleges-e-course-wordpress-theme-66265.html" target="_blank" rel="noreferrer noopener">Rainbow Colleges</a>: Rated 4.93/5 from 15 Reviews</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/54991.html" target="_blank" rel="noreferrer noopener">Englot</a>: Rated 4.92/5 from 24 Reviews</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/81170.html" target="_blank" rel="noreferrer noopener">Innomerce</a>: Rated 4.90/5 from 31 Reviews</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/varsity-educational-wordpress-theme-99612.html" target="_blank" rel="noreferrer noopener">Varsity</a>: Rated 4.82/5 from 11 Reviews</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/64869.html" target="_blank" rel="noreferrer noopener">Jack Baker</a>: Rated 4.75/5 from 12 Reviews</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/62312.html" target="_blank" rel="noreferrer noopener">Emanuella</a>: Rated 4.75/5 from 12 Reviews</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/51770.html" target="_blank" rel="noreferrer noopener">High School</a>: Rated 4.65/5 from 23 Reviews</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/ecoursify-lms-for-online-courses-wordpress-theme-66906.html" target="_blank" rel="noreferrer noopener">ECoursify</a>: Rated 4.30/5 from 10 Reviews</li>



<li><a href="https://www.templatemonster.com/wordpress-themes/55026.html" target="_blank" rel="noreferrer noopener">School District</a>: Rated 4.07/5 from 14 Reviews</li>
</ol>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="2400" height="1600" src="https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-templatemonster.jpg" alt="Top 10 best-rated WordPress education themes on TemplateMonster (over 10 reviews)" class="wp-image-7474" srcset="https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-templatemonster.jpg 2400w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-templatemonster-300x200.jpg 300w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-templatemonster-1024x683.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-templatemonster-768x512.jpg 768w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-templatemonster-1536x1024.jpg 1536w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-templatemonster-2048x1365.jpg 2048w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-templatemonster-25x18.jpg 25w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-templatemonster-864x576.jpg 864w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-templatemonster-158x105.jpg 158w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-templatemonster-473x315.jpg 473w, https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-templatemonster-800x533.jpg 800w" sizes="auto, (max-width: 2400px) 100vw, 2400px" /><figcaption class="wp-element-caption"><a href="https://mehdinazari.com/wp-content/uploads/2023/06/best-rated-education-themes-templatemonster.jpg" target="_blank" rel="noopener" title="">Top 10 best-rated WordPress education themes on TemplateMonster (over 10 reviews)</a></figcaption></figure>
</div>


<h2 class="wp-block-heading"><strong>Other Options </strong>for Educational WordPress Websites</h2>



<p>If you don&#8217;t want to purchase an education theme for WordPress, You have three other options:</p>



<h3 class="wp-block-heading"><strong>Using customizable multi-purpose themes</strong> to build an educational website</h3>



<p>Multi-purpose purpose themes are designed to be versatile and can be customized to fit the needs of any website, including educational ones. These themes offer a variety of features that help create a user-friendly experience for visitors.</p>



<p>For instance, <a href="https://www.elegantthemes.com/gallery/divi/" target="_blank" rel="noopener" title=""><strong>Divi is a multi-purpose theme</strong></a> that is super popular nowadays. This theme has a built-in page builder that allows you to design your pages with its easy-to-use interface. But it&#8217;s not free. <strong>Divi costs $89 for a one-year subscription</strong>, which gives you access to the theme, support, and updates. Or a <strong>$249 one-time payment</strong> for a lifetime.</p>



<p><strong>Another example of a multi-propose theme is <a href="https://wpastra.com/" target="_blank" rel="noopener" title="">Astra</a></strong>, which is compatible with many third-party website builders like <a href="https://elementor.com/" target="_blank" rel="noopener" title="">Elementor</a>. Also, this theme <strong>offers a free version</strong> too.</p>



<h3 class="wp-block-heading"><strong>Hiring a WordPress Developer</strong> to build a custom education theme</h3>



<p>Hiring a WordPress developer to build a custom education theme can be beneficial in many ways.</p>



<p>Firstly, they have the expertise to create a <strong>theme that meets your needs</strong>. They will work with you closely throughout developing your theme, ensuring it is tailored precisely to your requirements.</p>



<p>Furthermore, hiring a professional WordPress <strong>developer can save you time and money</strong> in the long run. Because you may find a user-friendly theme, but if you want to extend your website features, you may find it difficult.</p>



<h4 class="wp-block-heading">How much does a custom WordPress theme cost for an educational website?</h4>



<p>When it comes to creating an educational website, the design of your site is crucial. A well-designed website attracts more visitors, increases engagement, and promotes learning.</p>



<p>However, many educational institutions struggle to decide how much they should pay for a custom WordPress theme. The cost of a custom WordPress theme can vary depending on factors such as the complexity of required features, search engine optimization, and the developer&#8217;s experience.</p>



<p>A custom WordPress theme can range <strong>from $4K to $100K or sometimes more</strong>. This wide range is due to the different levels of customization needed for each website.</p>



<p><strong>Factors like functionality, design elements, and development time</strong> are crucial in determining the final price.</p>



<p>For instance, if you want complex features like e-commerce functionality added to your site, you&#8217;ll likely pay more than someone who wants basic features like contact forms and image galleries added to their site.</p>



<p>Developing a simple education website <strong>will take 100 hours on average</strong>, so if an experienced developer&#8217;s hourly rate is $40/hr, his quote will be around $4k. But typically, experienced developers will multiply the cost by 1.5x, to be careful.</p>



<h4 class="wp-block-heading">Where to find a WordPress developer for building an educational website?</h4>



<p>Consider using <strong>freelance platforms such as Upwork or Freelancer.com</strong> for the first option. These websites allow you to post your project requirements and receive proposals from numerous developers. You can also check their portfolios and ratings from previous clients before hiring them.</p>



<p>For the second option, look for <strong>WordPress development agencies</strong> specializing in building educational websites.</p>



<p>These agencies have teams of developers with extensive experience in creating websites specifically tailored for schools, colleges, or other educational institutions. But the cost of their services is usually higher than a freelancer.</p>



<p>If the two first options don&#8217;t work for you, <strong>attend WordCamps or WordPress meetups</strong> to network with experienced developers or get recommendations on who to hire.</p>



<h4 class="wp-block-heading">Custom WordPress themes pros</h4>



<ol class="wp-block-list">
<li><strong>Unique design:</strong> Custom WordPress themes uniquely align with a website&#8217;s brand and business goals.</li>



<li><strong>Flexibility:</strong> With custom themes, users have more control over the functionality and layout of their website.</li>



<li><strong>Improved performance:</strong> Custom themes are optimized for speed, efficiency, and search engine optimization (SEO).</li>



<li><strong>Reliable support:</strong> Users can rely on a team of developers for ongoing maintenance, updates, and technical support.</li>



<li><strong>Scalability:</strong> Custom themes can quickly scale as businesses grow and expand.</li>
</ol>



<h4 class="wp-block-heading">Custom WordPress themes cons</h4>



<ol class="wp-block-list">
<li><strong>Costly:</strong> Custom WordPress themes can be expensive to develop compared with pre-made templates.</li>



<li><strong>Time-consuming:</strong> Developing custom WordPress themes takes more time than pre-made templates.</li>



<li><strong>Need for a </strong>developer: Finding a good developer is not easy as you think. You may spend lots of time finding an available developer, not only at the start of the project but also to extend the features and fix bugs.</li>
</ol>



<h3 class="wp-block-heading"><strong>Learning how to build a theme</strong> for educational websites</h3>



<p>If you&#8217;re an educator or someone passionate about education, learning how to build a theme for educational websites can be a valuable skill. <strong>Not only will it enhance your web development skills, but it can also help you create a more engaging and effective online learning experience for your students</strong>.</p>



<p>Building a theme for educational websites allows you to design and customize the layout of your website according to your needs. This means <strong>you can create unique templates that fit your branding, course structure, and teaching style</strong>.</p>



<p>Additionally, learning how to personalize themes <strong>enables you to experiment with designs</strong> that keep learners engaged while effectively conveying important information.</p>



<p>Moreover, <strong>building a theme is cost-effective</strong> in the long run because no ongoing fees are attached.</p>



<p>If you want to develop features for your educational website, read my tutorial on <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/" title="How to Create a Hello World Plugin for WordPress [2023]">starting plugin development for WordPress</a>.</p><p>The post <a href="https://mehdinazari.com/wordpress-education-themes/">983 WordPress Education Themes | June 2023 Compare</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/wordpress-education-themes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Add One Custom Field for Many Posts in WordPress</title>
		<link>https://mehdinazari.com/add-custom-field-multiple-posts-wordpress/</link>
					<comments>https://mehdinazari.com/add-custom-field-multiple-posts-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Fri, 24 Feb 2023 23:50:36 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<category><![CDATA[Advanced WordPress Tutorials]]></category>
		<category><![CDATA[Extend WordPress Functionalities]]></category>
		<category><![CDATA[Using Meta Data in WordPress]]></category>
		<category><![CDATA[WordPress Custom Field Development]]></category>
		<category><![CDATA[WordPress plugin development for beginners]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=6702</guid>

					<description><![CDATA[<p>Use this code snippet to add the same meta data value for multiple WordPress posts at once. Here I provided solutions that save one custom field in many posts. I recently encountered a situation requiring adding one custom field in multiple WordPress posts simultaneously. So, I developed a solution that inserts the same meta data [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/add-custom-field-multiple-posts-wordpress/">How to Add One Custom Field for Many Posts in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Use this code snippet to add the same meta data value for multiple WordPress posts at once. Here I provided solutions that save one custom field in many posts.</p>



<span id="more-6702"></span>



<p>I recently encountered a situation requiring adding one custom field in multiple WordPress posts simultaneously.</p>



<p>So, I developed a solution that inserts the same meta data for multiple posts.</p>



<p>At this time, I am sharing my code with you here.</p>



<h2 class="wp-block-heading">Solutions to Add the Same Custom Field for Multiple Posts</h2>



<p>If you want to add the same meta data for many posts when developing WordPress, You have two options:</p>



<ul class="wp-block-list">
<li><strong><a href="#solution-1" title="">The first option</a></strong>, with better performance, uses a single database query to add multiple records to the WordPress <code>postmeta</code> table.</li>



<li><strong><a href="#solution-2" title="">The second option</a></strong> iterates posts and uses <code>add_posts_meta</code> for each item separately.</li>
</ul>



<h3 class="wp-block-heading" id="solution-1">1- Add one custom field for multiple posts with a single query</h3>



<p><strong>Using a single SQL query</strong>, this new custom function simultaneously adds multiple meta data for all post ids.</p>



<pre><code class="language-php">function add_multiple_posts_meta( $post_ids, $meta_key, $meta_value, $unique = false ){

	// if meta key or post ids are not set, do not continue
	if( !$meta_key || !absint( $post_ids ) ){
		return false;
	}

	//fallback to WordPress default add_post_meta if single post id passed
	if( is_numeric( $post_ids ) || ( is_array( $post_ids ) &amp;&amp; count( $post_ids ) == 1 ) ){
		return add_post_meta(
			is_array( $post_ids ) ? $post_ids[ 0 ] : $post_ids,
			$meta_key,
			$meta_value,
			$unique
		);
	}

	global $wpdb;

	$valid_post_ids = array_unique(
		array_filter( $post_ids, function( $post_id ) use ( $wpdb, $meta_key, $unique ){
			//check if the post id exists
			return $post_id &amp;&amp;
				is_numeric( $post_id ) &amp;&amp;
				get_post_status( $post_id ) &amp;&amp;
				(
					!$unique ||
					$wpdb-&gt;get_var( $wpdb-&gt;prepare(
						"SELECT COUNT(*) FROM $wpdb-&gt;postmeta WHERE post_id = %d AND meta_key = %s",
						$meta_key,
						$post_id )
					)
				);
		} )
	);

	//if all post ids had problem, there is no reason to continue
	if( !count( $valid_post_ids ) ){
		return false;
	}

	//sanitize meta key &amp; value
	$meta_key   = wp_unslash( $meta_key );
	$meta_value = sanitize_meta( wp_unslash( $meta_value ), $meta_value, 'post' );

	//create an array of data to be inserted
	$insert_data    = array();
	$insert_formats = array();

	foreach( $valid_post_ids as $post_id ){
		//insert id, key, value in data array (order is important)
		array_push( $insert_data, $post_id, $meta_key, $meta_value );

		//we have one format for all records
		$insert_formats[] = '(%d, %s, %s)';
	}

	//query string with (%d, %s, %s) as value
	$sql_string = "INSERT INTO $wpdb-&gt;postmeta (`post_id`, `meta_key`, `meta_value`) VALUES "
		. implode( ', ', $insert_formats );

	//replace (%d, %s, %s) with actual data
	$sql_query = $wpdb-&gt;prepare( $sql_string, $insert_data );

	//returns true if succeeded, otherwise false
	return $wpdb-&gt;query( $sql_query );

}</code></pre>



<p>It should be noted you better check if this function exists before declaring it.</p>



<p>To do this, our new function will wrap inside an <code>if</code> condition like the below:</p>



<pre><code class="language-php">if( !function_exists( 'add_multiple_posts_meta' ) ){
    copy above codes here...
}</code></pre>



<p>Do the same when defining a custom WordPress function to avoid future conflicts.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>If third-party plugins define this custom function with same name or the WP team decides to add it in the future, You&#8217;ll get a PHP error that says this function was defined before.</p>
</blockquote>



<h4 class="wp-block-heading">How to use this custom function</h4>



<p>The <code>add_multiple_posts_meta</code> function works with an array of post IDs. Then, I defined an array of <code>1, 2, 3</code> post IDs to set a meta value for:</p>



<pre><code class="language-php">$post_ids = array( 1, 2, 3 );
$meta_key = 'your_meta_key';
$meta_value = 'your desired value';
$dont_add_if_key_exists = false;
add_multiple_posts_meta( $post_ids, $meta_key, $meta_value, $dont_add_if_key_exists );</code></pre>



<h4 class="wp-block-heading">Explain for this custom function</h4>



<p>Our new <code>add_multiple_posts_meta</code> function has a similar syntax to the <code>add_post_meta</code> in WordPress.</p>



<p>The only difference is <strong>this function accepts an array of post IDs or a single post ID</strong> if you wish.</p>



<p>As a result, It <strong>falls back to <code>add_post_meta</code> if you pass a single post ID</strong> to it (integer or array with one element).</p>



<p>See your second option if you want core WordPress functions to handle this situation.</p>



<h3 class="wp-block-heading" id="solution-2">2- Iterate post IDs to add the custom field for each post</h3>



<p>This solution is easy because you can <strong>use <code>add_post_meta</code> and leave it all to this function</strong>.</p>



<pre><code class="language-php">$post_ids = array( 1, 2, 3 );
$meta_key = 'your_meta_key';
$meta_value = 'your desired value';
$dont_add_if_key_exists = false;

foreach( $post_ids as $post_id ){
	add_post_meta( $post_id, $meta_key, $meta_value, $dont_add_if_key_exists );
}</code></pre>



<p>The <code>add_post_meta</code> is responsible for <a href="https://mehdinazari.com/set-get-custom-field-of-post-wordpress/" target="_blank" rel="noopener" title="How to Set or Get a Custom Field for a Post in WP">adding a single custom field for one post</a>, and it does not support adding meta data to multiple post items.</p>



<p>Thus, you have no choice but to <strong>use a PHP loop</strong> (foreach, for, while, do while) to iterate an array of post IDs. Then using <code>add_post_meta</code> on each one of IDs you have in that array.</p>



<p>To make this solution work, I used <a href="https://www.php.net/manual/en/control-structures.foreach.php" target="_blank" rel="noopener" title="">PHP&#8217;s foreach loop</a> to add meta data for every post ID stored in the <code>$post_ids</code> array.</p>



<h2 class="wp-block-heading">More Information on WordPress Custom Fields</h2>



<p>WordPress custom fields hold all the extra information you need to add features to your WordPress website.</p>



<p>Whether you’re looking for a way to store post view numbers, filterable keyword tags, or other extra content pieces, custom fields are a great way to do it.</p>



<p>Fortunately, many sources are available online to learn more about custom fields and how they work in WordPress.</p>



<h4 class="wp-block-heading">Resources for developing WordPress custom fields</h4>



<p>First, The WordPress official website is an excellent place to start, providing detailed information about <a href="https://wordpress.com/support/posts/" target="_blank" rel="noopener" title="">how the posts work</a> and <a href="https://developer.wordpress.org/?s=meta+data" target="_blank" rel="noopener" title="">how meta data can be added or modified</a>.</p>



<p>Second, StackOverflow contains many <a href="https://wordpress.stackexchange.com/questions/tagged/custom-field" target="_blank" rel="noopener" title="">questions about WordPress’s custom fields feature</a> and related topics.</p>



<p>Last, you may also want to read my tutorial on <a href="https://mehdinazari.com/set-get-custom-field-of-post-wordpress/" target="_blank" rel="noopener" title="">managing WordPress custom fields through the admin panel or using PHP codes</a>.</p>



<p>With the right guidance from these sources, one can easily use this useful feature in your WordPress site to make it feature-rich.</p><p>The post <a href="https://mehdinazari.com/add-custom-field-multiple-posts-wordpress/">How to Add One Custom Field for Many Posts in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/add-custom-field-multiple-posts-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Switch Theme in WordPress Programmatically</title>
		<link>https://mehdinazari.com/switch-theme-wordpress-programmatically/</link>
					<comments>https://mehdinazari.com/switch-theme-wordpress-programmatically/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Sun, 12 Feb 2023 18:03:24 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<category><![CDATA[Advanced WordPress Tutorials]]></category>
		<category><![CDATA[WordPress Filters]]></category>
		<category><![CDATA[WordPress Hooks]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=4953</guid>

					<description><![CDATA[<p>Here I shared a code that you can use to switch the WordPress theme to your custom theme. Only the name of the theme is required in this code to make your theme always the selected one for visitors. function set_my_custom_theme() { //replace your theme name return 'your-theme-name'; } add_filter( 'template', 'set_my_custom_theme' ); add_filter( 'stylesheet', [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/switch-theme-wordpress-programmatically/">How to Switch Theme in WordPress Programmatically</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Here I shared a code that you can use to switch the WordPress theme to your custom theme. Only the name of the theme is required in this code to make your theme always the selected one for visitors.</p>



<span id="more-4953"></span>



<pre><code class="language-php">function set_my_custom_theme() {
    //replace your theme name
    return 'your-theme-name';
}
add_filter( 'template', 'set_my_custom_theme' );
add_filter( 'stylesheet', 'set_my_custom_theme' );</code></pre>



<h2 class="wp-block-heading">Above code explain</h2>



<p>the <a href="https://developer.wordpress.org/reference/hooks/template/" target="_blank" rel="noopener" title="">template</a> and <a href="https://developer.wordpress.org/reference/hooks/stylesheet/" title="">stylesheet</a> filters are responsible to select the activated theme for the visitors.</p>



<p>In line 3 of the above code, we set the returning theme name for visitors to <code>your-theme-name</code> which you can change to your desired theme name.</p>



<p>Copy this code to the PHP file of your <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/" title="How to create a Hello World plugin for WordPress in 3 Steps">custom WordPress plugin</a> to use it.</p>



<h2 class="wp-block-heading">Why would I want to Switch the Active WordPress Theme?</h2>



<p>This function will be useful if you desire to display different themes to different types of users.</p>



<p>For example, if you want to change the displaying theme for <a href="https://mehdinazari.com/check-if-user-is-logged-in-wordpress/" title="How to Check if the Current User is logged in WordPress?">logged-in users</a>. Or maybe each <a href="https://mehdinazari.com/get-the-current-user-id-wordpress/" title="How to Get the ID of Current Logged in User from WordPress!">WordPress user</a> or user role needs different functionalities available in another theme. You can use this function to switch the WordPress theme for them.</p><p>The post <a href="https://mehdinazari.com/switch-theme-wordpress-programmatically/">How to Switch Theme in WordPress Programmatically</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/switch-theme-wordpress-programmatically/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get Category Names by Post ID in WordPress!</title>
		<link>https://mehdinazari.com/get-category-names-post-id-wordpress/</link>
					<comments>https://mehdinazari.com/get-category-names-post-id-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Fri, 10 Feb 2023 19:23:09 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=6536</guid>

					<description><![CDATA[<p>List all Category Names of a Post in WordPress with this simple PHP code I&#8217;ve provided in this tutorial. If you have a post ID, it&#8217;s easy to get associated Category Names to that post after reading this short WordPress Tutorial. $postId = 1; //note: if you code in single.php, do not need to pass [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/get-category-names-post-id-wordpress/">How to Get Category Names by Post ID in WordPress!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>List all Category Names of a Post in WordPress with this simple PHP code I&#8217;ve provided in this tutorial. If you have a post ID, it&#8217;s easy to get associated Category Names to that post after reading this short WordPress Tutorial.</p>



<span id="more-6536"></span>



<pre><code class="language-php">$postId = 1;
//note: if you code in single.php, do not need to pass the id
$categories = get_the_category($postId);

//iterate categories and print $category-&gt;cat_name
foreach($categories as $category){
    echo '&lt;a href="' . get_category_link($category) . '"&gt;' . $category-&gt;cat_name . '&lt;/a&gt;';
}</code></pre>



<h2 class="wp-block-heading">Explaining the above code</h2>



<p>In the first line, we specified <code>$postId</code> as the post with an ID of 1. But you do not need to specify the post id if you are coding inside the single.php file.</p>



<p>the <code>get_the_category()</code> function will use the global $post object to return categories if you do not pass the post id.</p>



<p>Then in line 3, we retrieved categories using the <code>get_the_category()</code> function.</p>



<p><code><a href="https://developer.wordpress.org/reference/functions/get_the_category/" target="_blank" rel="noopener" title="">get_the_category()</a></code> will return an array of category objects containing the <code>cat_name</code> field, which we are looking for.</p>



<p>We used <code>foreach</code> loop from line 6 to iterate categories and print the <code>$category-&gt;cat_name</code> wrapped inside <code>&lt;a&gt;</code> tag.</p>



<p>If you do not need to link the category name to its page, then remove the link tag, like the below example:</p>



<pre><code class="language-php">$postId = 1;
//note: if you code in single.php, do not need to pass the id
$categories = get_the_category($postId);

//iterate categories and print $category-&gt;cat_name
foreach($categories as $category){
    echo $category-&gt;cat_name . ',';
}</code></pre>



<p>If you need category names inside an array to use inside custom functions or <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/" target="_blank" rel="noopener" title="How to create a Hello World plugin for WordPress in 3 Steps">WordPress plugin development</a>, try the below code:</p>



<pre><code class="language-php">$postId = get_the_ID();

//retrieve categories for this post
$categories = get_the_category($postId);

//create an array of category names
$categoryNames = array_map( function($category){ return $category-&gt;cat_name; }, $categories );</code></pre>



<p>In the above example, we&#8217;ve used the <a href="https://www.php.net/manual/en/function.array-map.php" target="_blank" rel="noopener" title="">PHP array_map function</a> to create an array of category names.</p>



<p>If you are interested in more details about categories in WordPress, I recommend reading my tutorial on <a href="https://mehdinazari.com/query-wordpress-categories-tags-taxonomies/" title="">Query WordPress Categories</a>.</p><p>The post <a href="https://mehdinazari.com/get-category-names-post-id-wordpress/">How to Get Category Names by Post ID in WordPress!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/get-category-names-post-id-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Add a New Field to WordPress Admin Settings!</title>
		<link>https://mehdinazari.com/add-settings-field-wordpress/</link>
					<comments>https://mehdinazari.com/add-settings-field-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Fri, 10 Feb 2023 12:39:24 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Admin Panel]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Hooks]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">http://localhost/mehdinazari/?p=2590</guid>

					<description><![CDATA[<p>WP Developers can use the add_settings_field function to add a custom field to a specified WordPress setting page. If you want to add your desired fields to WordPress settings, read this comprehensive tutorial about the add_settings_field function. Skip to Copy/Past part, by clicking here. add_settings_field Function Introduction Since WordPress V2.7.0, the add_settings_field function in WordPress [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/add-settings-field-wordpress/">How to Add a New Field to WordPress Admin Settings!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>WP Developers can use the add_settings_field function to add a custom field to a specified WordPress setting page. If you want to add your desired fields to WordPress settings, read this comprehensive tutorial about the add_settings_field function.</p>



<span id="more-2590"></span>



<p><a href="#example" title="">Skip to Copy/Past part, by clicking here</a>.</p>



<h2 class="wp-block-heading" id="intro"><a href="#intro" title=""><code>add_settings_field</code> Function Introduction</a></h2>



<p>Since WordPress V2.7.0, the <a href="https://developer.wordpress.org/reference/functions/add_settings_field/" target="_blank" rel="noopener" title="">add_settings_field function</a> in WordPress is responsible for adding a new field to a section in a setting page of the WP admin panel.</p>



<p>add_settings_field() accepts four required and two optional parameters.</p>



<p>Required parameters are for the unique ID of the field, title, name of the callback function to print the field, and the name of the specific settings page you want to put the field in (default pages: <strong>general</strong>, <strong>reading</strong>, <strong>writing</strong>, <strong>discussion</strong>, and <strong>media</strong>).</p>



<p>Optional parameters specify the exact section in the setting page and an array of arguments to customize your field (we&#8217;ll get into it in <a href="#parameters" title="">the parameters part of this tutorial</a>).</p>



<h2 class="wp-block-heading" id="syntax"><a href="#syntax" title=""><code>add_settings_field</code> Function Syntax</a></h2>



<p>Look at the syntax carefully; the parameters without <code>=</code> are required.</p>



<pre><code class="language-php">add_settings_field( string&nbsp;$id,  string&nbsp;$title,  callable&nbsp;$callback,  string&nbsp;$page,  string&nbsp;$section&nbsp;=&nbsp;'default',  array&nbsp;$args&nbsp;=&nbsp;array()&nbsp;)</code></pre>



<h2 class="wp-block-heading" id="parameters"><a href="#parameters" title=""><code>add_settings_field</code> Function Parameters</a></h2>



<ul class="wp-block-list">
<li><b><code>$id</code></b>:  Unique ID to set of the field. This id will be the value for the id=&#8217;your-id&#8217; in the HTML. </li>



<li><b><code>$title</code></b>:  The label to print for this field in settings form.</li>



<li><b><code>$callback</code></b>:  Name of your custom function that you want to print the field in it.</li>



<li><b><code>$page</code></b>:  Slug of the exact setting page you want to print this field in. Default options are <strong>general</strong>, <strong>reading</strong>, <strong>writing</strong>, <strong>discussion</strong>, and <strong>media</strong>. If you added a custom settings page, you can use its slug here. </li>



<li><b><code>$section</code></b>: Slug of the exact section you want to print this field in. The default value for the section is &#8216;default&#8217;.</li>



<li><b><code>$args</code></b>:  Optional array of arguments to customize your output with these keys:
<ul class="wp-block-list">
<li><b><code>label_for</code></b>: Value of HTML attribute <code>for="your-label_for"</code> of <code>&lt;label&gt;</code> around your input and title.</li>



<li><b><code>class</code></b>: Class names for your field.</li>
</ul>
</li>
</ul>



<h2 class="wp-block-heading" id="example"><a href="#example" title=""><code>add_settings_field</code> Function Example</a></h2>



<p>In this example, we&#8217;ll use <code>add_settings_field</code> with <a href="https://mehdinazari.com/add_settings_section-wordpress-function/" target="_blank" rel="noopener" title=""><code>add_settings_section</code> function</a> to print a section with a field in it.</p>



<p>To save our data, we need to use the <code>register_setting()</code> function of WordPress; otherwise, it will not be saved automatically (the saving code is included below).</p>



<p>To get our Data, We need to use <code>get_option()</code> function (included below on the value attribute of <code>&lt;input&gt;</code> tag).</p>



<pre><code class="language-php">//callback to print a simple section in general page
function my_custom_section_callback(){
	echo 'This text is inside the callback!';
}

//callback to print a simple input field
function my_custom_field_callback(){
	echo '&lt;input name="my_id_for_setting_field" value="'. get_option('my_id_for_setting_field') .'" /&gt;';
}

function add_my_custom_section_to_settings(){

    //register setting to save the data
	register_setting( 'general', 'my_id_for_setting_field' );

	//add the section to general page in admin panel
	add_settings_section(
		'my_id_for_settings_section',
		'A custom title to show',
		'my_custom_section_callback',
		'general',
		array(
			'before_section' =&gt; 'Text Before the Section', //html for before the section
			'after_section' =&gt; 'Text After the Section', //html for after the section
		)
	);

	//add a sample field to this section.
	add_settings_field(
		'my_id_for_setting_field',
		'A custom field',
		'my_custom_field_callback',
		'general',
		//put the id of custom section here:
		'my_id_for_settings_section'
	);

}
add_action('admin_init', 'add_my_custom_section_to_settings');</code></pre>



<p>After using this code in your <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/" target="_blank" rel="noopener" title="How to create a Hello World plugin for WordPress in 3 Steps">WordPress custom plugin</a> or <code>functions.php</code> of the active theme, You can open this URL to see the section:</p>



<p><strong>http://siteurl.com/wp-admin/options-general.php</strong></p>



<p>Look for something like this screenshot:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="336" src="https://mehdinazari.com/wp-content/uploads/2023/01/custom-section-wp-general-settings-1024x336.png" alt="" class="wp-image-6386" srcset="https://mehdinazari.com/wp-content/uploads/2023/01/custom-section-wp-general-settings-1024x336.png 1024w, https://mehdinazari.com/wp-content/uploads/2023/01/custom-section-wp-general-settings-300x99.png 300w, https://mehdinazari.com/wp-content/uploads/2023/01/custom-section-wp-general-settings-768x252.png 768w, https://mehdinazari.com/wp-content/uploads/2023/01/custom-section-wp-general-settings-1536x505.png 1536w, https://mehdinazari.com/wp-content/uploads/2023/01/custom-section-wp-general-settings-800x263.png 800w, https://mehdinazari.com/wp-content/uploads/2023/01/custom-section-wp-general-settings.png 1686w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Custom Section in WordPress General Settings</figcaption></figure>



<p>If you enter a text and hit the <strong>Save Changes</strong> button, the value will be saved in the database.</p><p>The post <a href="https://mehdinazari.com/add-settings-field-wordpress/">How to Add a New Field to WordPress Admin Settings!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/add-settings-field-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Add New Shortcode to WordPress! [+2 Examples]</title>
		<link>https://mehdinazari.com/add-shortcode-wordpress/</link>
					<comments>https://mehdinazari.com/add-shortcode-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Fri, 10 Feb 2023 12:30:53 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">http://localhost/mehdinazari/?p=2592</guid>

					<description><![CDATA[<p>add_shortcode function registers a custom shortcode in WordPress. Visit this tutorial to see how to use this function to add your desired shortcodes to WP easily. add_shortcode Function Introduction WordPress introduced the add_shortcode function to let developers register custom shortcodes when developing new features. When adding a new shortcode, you must specify a tag which [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/add-shortcode-wordpress/">How to Add New Shortcode to WordPress! [+2 Examples]</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>add_shortcode function registers a custom shortcode in WordPress. Visit this tutorial to see how to use this function to add your desired shortcodes to WP easily.</p>



<span id="more-2592"></span>



<h2 class="wp-block-heading" id="intro"><a href="#intro" title=""><code>add_shortcode</code> Function Introduction</a></h2>



<p>WordPress introduced the <a href="https://developer.wordpress.org/reference/functions/add_shortcode/" target="_blank" rel="noopener" title=""><code>add_shortcode</code> function</a> to let developers register custom shortcodes when developing new features.</p>



<p>When adding a new shortcode, you must specify a tag which is the name of your shortcode, and a callback function to give WordPress your desired content.</p>



<p>Your callback function receives three parameters. First, an array of attributes; second, the user content; and finally, the tag you set when registering this shortcode. (order: 1- attributes, 2- content, 3- tag)</p>



<p>Example of adding a new shortcode that prints &#8220;Hello World!&#8221; text:</p>



<pre><code class="language-php">//callback for the shortcode
function hello_world_shortcode_callback( $attributes, $content, $tag ){
	return 'Hello World!';
}

//register the hello world shortcode
function hello_world_shortcode(){
	add_shortcode( 'hello-world', 'hello_world_shortcode_callback' );
}

add_action( 'init', 'hello_world_shortcode' );</code></pre>



<p>Now you can use this shortcode by typing <code>[hello-world]</code> inside the WordPress post editor to try it.</p>



<p>Notice the return in the above code? You must return the value you want to print. So do not echo the value.</p>



<p>If you use echo instead of return, the &#8220;Hello World!&#8221; text will be printed before the surrounding content.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Note: as <a href="https://developer.wordpress.org/reference/functions/add_shortcode/#comment-3473" target="_blank" rel="noopener" title="">a developer mentioned on WordPress.org</a>, you better add your custom shortcodes in a function that is hooked to the WP <code>init</code> hook. This helps WP to have time to initiate your new shortcodes properly.</p>
</blockquote>



<h2 class="wp-block-heading"><code>add_shortcode</code> Function Syntax</h2>



<pre><code class="language-php">add_shortcode( string&nbsp;$tag,  callable&nbsp;$callback&nbsp;)</code></pre>



<h2 class="wp-block-heading"><code>add_shortcode</code> Function Parameters</h2>



<ul class="wp-block-list">
<li><b><code>$tag</code></b>: Name tag for this shortcode. If duplicated, the lastly defined will override others (you can use a prefix to prevent this).</li>



<li><b><code>$callback</code></b>: Name of the function that returns the value you want to print.</li>
</ul>



<h2 class="wp-block-heading">How to Use Shortcodes in the WordPress Post Editor?</h2>



<p>To use a shortcode in the WordPress editor (Gutenberg or Classic editor), you must use it inside a bracket.</p>



<p>In our <a href="#intro" title="">example of adding a &#8216;hello world!&#8217; text using a custom shortcode</a>, we defined the hello-world shortcode. To use it, we must type <code>[hello-world]</code> in the post editor.</p>



<p>Another option is to write shortcode in complete form, like this:</p>



<p><code>[hello-world][/hello-world]</code></p>



<h2 class="wp-block-heading">How to Use a WordPress Shortcodes in PHP?</h2>



<p>You can call shortcodes in PHP codes with the <code>do_shortcode()</code> function of WordPress. Here is an example of the <code>do_shortcode()</code> function using our hello-world shortcode:</p>



<pre><code class="language-php">do_shortcode( '[hello-world]' )</code></pre>



<h2 class="wp-block-heading">How to Pass Data from Shortcode to Callback Function?</h2>



<h3 class="wp-block-heading">Option 1: pass data between start and close tag of the shortcode</h3>



<p>You can pass a text to the callback function in between of shortcode start and close tag. For example:</p>



<p><code>[hello-world]from me to[/hello-world]</code></p>



<p>To use this data, we can do something like this:</p>



<pre><code class="language-php">//callback for the shortcode
function hello_world_shortcode_callback( $attributes, $content, $tag ){
	return 'Hello '. $content .' World!';
}

//register the hello world shortcode
function hello_world_shortcode(){
	add_shortcode( 'hello-world', 'hello_world_shortcode_callback' );
}

add_action( 'init', 'hello_world_shortcode' );</code></pre>



<p>Now if you type <code>[hello-world]from me to[/hello-world]</code> in WordPress editor, it will print &#8220;<strong>Hello from me to World!</strong>&#8220;.</p>



<h3 class="wp-block-heading">Option 2: pass data as an attribute</h3>



<p>Another option is to set attributes in the shortcode and get them in the callback function, for example:</p>



<p><code>[hello-world from="me" to="world"][/hello-world]</code></p>



<p>To get the <code>from</code> and <code>to</code> in the callback function, we can use the first parameter in our callback function:</p>



<pre><code class="language-php">//callback for the shortcode
function hello_world_shortcode_callback( $attributes, $content, $tag ){
	return 'Hello from '. $attributes['from'] . ' to ' . $attributes['to'] . '!';
}

//register the hello world shortcode
function hello_world_shortcode(){
	add_shortcode( 'hello-world', 'hello_world_shortcode_callback' );
}

add_action( 'init', 'hello_world_shortcode' );</code></pre>



<p>Now if you type test <code>[hello-world from="me" to="the world"][/hello-world]</code> inside the WordPress editor, it will print &#8220;<strong>Hello from me to the world!</strong>&#8221; for you.</p>



<h2 class="wp-block-heading">Examples of Adding Custom Shortcodes to WordPress</h2>



<p>Here I provided two examples of adding a new shortcode to WordPress. You can use them in the WP post editor to print useful texts when you write a post.</p>



<h3 class="wp-block-heading">1- New Shortcode for printing the current year</h3>



<p>To print current year that will change over time, we will define the <code>current-year</code> shortcode in WordPress, using this code:</p>



<pre><code class="language-php">//callback for current year the shortcode
function current_year_shortcode_callback( $attributes, $content, $tag ){
	return date('Y');
}

//register the current year shortcode
function current_year_shortcode(){
	add_shortcode( 'current-year', 'current_year_shortcode_callback' );
}

add_action( 'init', 'current_year_shortcode' );</code></pre>



<p>Now you can type [current-year] in WordPress editor to print the current year between your content.</p>



<h3 class="wp-block-heading">2- New Shortcode for printing list of users</h3>



<p>To print list of registered users in WordPress, we will define the <code>users-list</code> shortcode, using this code:</p>



<pre><code class="language-php">// function that runs when shortcode is called
function my_custom_users_list() {
	$args = array(); //define arguments if you need
	$users = get_users($args);

	$listHtml = '&lt;ul&gt;';
	foreach($users as $user){
		$listHtml .= '&lt;li&gt;' . $user-&gt;data-&gt;display_name . '&lt;/li&gt;';
	}
	$listHtml .= '&lt;/ul&gt;';
	return $listHtml;
}

//register my-users-list shortcode
function register_my_users_list_shortcode(){
	add_shortcode('users-list', 'my_custom_users_list');
}
add_action( 'init', 'register_my_users_list_shortcode' );</code></pre>



<p>After defining this in the <code>functions.php</code> file of the active theme, or maybe your <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/" target="_blank" rel="noopener" title="">custom WordPress plugin</a>, you can open the WordPress post editor to type [users-list] and print all registered users&#8217; names with bullet points.</p><p>The post <a href="https://mehdinazari.com/add-shortcode-wordpress/">How to Add New Shortcode to WordPress! [+2 Examples]</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/add-shortcode-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>2 Simple Ways to Get WordPress Root Path</title>
		<link>https://mehdinazari.com/get-wordpress-root-path/</link>
					<comments>https://mehdinazari.com/get-wordpress-root-path/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 09 Feb 2023 16:02:43 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=6473</guid>

					<description><![CDATA[<p>Here we introduce two easy solutions for retrieving WordPress Root Path using a PHP function and a constant: get_home_path WP function and ABSPATH constant. In this tutorial, I introduced two examples of getting WordPress root Path in PHP. These simple codes will retrieve the absolute path to the WordPress home directory when needed. Getting WP [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/get-wordpress-root-path/">2 Simple Ways to Get WordPress Root Path</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Here we introduce two easy solutions for retrieving WordPress Root Path using a PHP function and a constant: get_home_path WP function and ABSPATH constant.</p>



<span id="more-6473"></span>



<p>In this tutorial, I introduced two examples of getting WordPress root Path in PHP. These simple codes will retrieve the absolute path to the WordPress home directory when needed.</p>



<p>Getting WP full home directory path is useful when referencing files in PHP.</p>



<p>For example, when you want to use <code>require</code>, <code>require_once</code>, <code>include</code>, and <code>include_once</code> in PHP, The <code>get_home_path</code> function and the <code>ABSPATH</code> constant can be useful for referencing a PHP file.</p>



<h2 class="wp-block-heading">1- Get WordPress Root Directory Path with get_home_path Function</h2>



<p><a href="https://developer.wordpress.org/reference/functions/get_home_path/" target="_blank" rel="noopener" title=""><code>get_home_path</code> function</a> retrieves the absolute path to the WordPress root directory.</p>



<p>Example of using the <code>get_home_path</code> function:</p>



<pre><code class="language-php">//example: including update.php file from /wp-admin/ folder:
require_once( get_home_path() . 'wp-admin/update.php' );
</code></pre>



<p>The returned string is the absolute path to the WordPress home directory; for example, <code>/var/www/html/</code> or <code>/home/username/domain.com/public_html/</code>.</p>



<p>If you installed WordPress in a subfolder, it would be like <code>/var/www/html/wordpress/</code>. It depends on your installation.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Note: the trailing slash <strong><code>/</code> is included</strong> in the returning string by the <code>get_home_path</code> function of WordPress.</p>
</blockquote>



<h2 class="wp-block-heading">2- Get WordPress Root Directory Path with ABSPATH Constant</h2>



<p>There is a constant defined in the <code>wp-config.php</code> file that contains the absolute path to the WordPress home.</p>



<p><code>ABSPATH</code> is the name of this constant that you can use everywhere you need the absolute path of WordPress.</p>



<p>Example of using ABSPATH contact:</p>



<pre><code class="language-php">$rootPath = ABSPATH;
//example: including update.php file from /wp-admin/ folder:
require_once( ABSPATH . 'wp-admin/update.php' );</code></pre>



<p>Same as in the previous example, <code>ABSPATH</code> returns the absolute path to the WordPress home directory.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Note: the trailing slash <strong><code>/</code> is included</strong> in the returning string by the <code>ABSPATH</code> constant of WordPress.</p>
</blockquote>



<p>For instance, this constant will return a string like <code>/var/www/html/</code> or <code>/home/username/domain.com/public_html</code>/. or the subfolder you&#8217;ve used to install WordPress.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Note: Do NOT confuse the WordPress root path with the <a href="https://mehdinazari.com/get-home-url-wordpress/" target="_blank" rel="noopener" title="">WordPress home URL</a>. Also you can <a href="https://mehdinazari.com/get-wordpress-root-path/" target="_blank" rel="noopener" title="">get the plugin directory path in WordPress</a> using <code>plugin_dir_path</code> function.</p>
</blockquote><p>The post <a href="https://mehdinazari.com/get-wordpress-root-path/">2 Simple Ways to Get WordPress Root Path</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/get-wordpress-root-path/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>53 Uncommon Words You Need Insanely in Unique Post Titles!</title>
		<link>https://mehdinazari.com/uncommon-words-for-post-titles/</link>
					<comments>https://mehdinazari.com/uncommon-words-for-post-titles/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Sun, 05 Feb 2023 15:21:14 +0000</pubDate>
				<category><![CDATA[SEO]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=5122</guid>

					<description><![CDATA[<p>Looking for a complete list of Uncommon Words to write perfect SEO headlines? then visit this page. Here we have a list of 53 Uncommon Words for SEO-concerned post titles. I have provided a list of valid words to help your SEO strategy by making your titles more noticeable in search results. Try to use [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/uncommon-words-for-post-titles/">53 Uncommon Words You Need Insanely in Unique Post Titles!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Looking for a complete list of Uncommon Words to write perfect SEO headlines? then visit this page. Here we have a list of 53 Uncommon Words for SEO-concerned post titles.</p>



<span id="more-5122"></span>



<p>I have provided a list of valid words to help your SEO strategy by making your titles more noticeable in search results.</p>



<p>Try to use these words <strong>between 10% to 20%</strong> of your headlines. This means <strong>one or two per 10 words</strong> in your post titles.</p>



<h2 class="wp-block-heading">List of 53 Uncommon Words to Use in Post Titles</h2>



<figure id="result" class="wp-block-table"><table><tbody><tr><td>actually</td></tr><tr><td>awesome</td></tr><tr><td>beautiful</td></tr><tr><td>being</td></tr><tr><td>best</td></tr><tr><td>better</td></tr><tr><td>boy</td></tr><tr><td>dog</td></tr><tr><td>down</td></tr><tr><td>first</td></tr><tr><td>found</td></tr><tr><td>girl</td></tr><tr><td>good</td></tr><tr><td>happened</td></tr><tr><td>heart</td></tr><tr><td>know</td></tr><tr><td>life</td></tr><tr><td>little</td></tr><tr><td>look</td></tr><tr><td>love</td></tr><tr><td>made</td></tr><tr><td>make</td></tr><tr><td>makes</td></tr><tr><td>man</td></tr><tr><td>media</td></tr><tr><td>mind</td></tr><tr><td>more</td></tr><tr><td>need</td></tr><tr><td>never</td></tr><tr><td>new</td></tr><tr><td>now</td></tr><tr><td>old</td></tr><tr><td>one</td></tr><tr><td>people</td></tr><tr><td>photos</td></tr><tr><td>really</td></tr><tr><td>reasons</td></tr><tr><td>right</td></tr><tr><td>see</td></tr><tr><td>seen</td></tr><tr><td>social</td></tr><tr><td>something</td></tr><tr><td>thing</td></tr><tr><td>think</td></tr><tr><td>time</td></tr><tr><td>video</td></tr><tr><td>want</td></tr><tr><td>watch</td></tr><tr><td>way</td></tr><tr><td>ways</td></tr><tr><td>world</td></tr><tr><td>year</td></tr></tbody></table></figure>



<h2 class="wp-block-heading">Complete List of Words to Use in Post Titles</h2>



<p>I provided three lists of words (4 with this one) for you to use in your headlines. The other 3 lists contain <a href="https://mehdinazari.com/common-words-for-post-titles/" title="59 Common Words You Want in the Attractive Post Titles!">Common Words</a>, <a href="https://mehdinazari.com/power-words-for-post-titles/" title="171 Power Words You See in the Innovative Post Titles!">Power Words</a>, and <a href="https://mehdinazari.com/emotional-words-for-post-titles/" target="_blank" rel="noopener" title="">Emotional Words</a>.</p>



<p>Each list contains valuable words that can drive more visitors to your posts from google and other search engines.</p>



<p>But remember, there is an optimum usage percentage for each word category that I wrote on the top of their pages. So, do NOT overuse these words.</p><p>The post <a href="https://mehdinazari.com/uncommon-words-for-post-titles/">53 Uncommon Words You Need Insanely in Unique Post Titles!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/uncommon-words-for-post-titles/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>59 Common Words You Want in the Attractive Post Titles!</title>
		<link>https://mehdinazari.com/common-words-for-post-titles/</link>
					<comments>https://mehdinazari.com/common-words-for-post-titles/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Sun, 05 Feb 2023 15:21:10 +0000</pubDate>
				<category><![CDATA[SEO]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=5142</guid>

					<description><![CDATA[<p>Common words help your blog post titles to look more natural to readers. Here is a helpful list of common words for your next post&#8217;s headline. Post headlines with between 20% to 30% common words are more likely to get clicks by searchers. These common words are stop words that should NOT be included in [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/common-words-for-post-titles/">59 Common Words You Want in the Attractive Post Titles!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Common words help your blog post titles to look more natural to readers. Here is a helpful list of common words for your next post&#8217;s headline.</p>



<span id="more-5142"></span>



<p>Post headlines with <strong>between 20% to 30% common words</strong> are more likely to get clicks by searchers.</p>



<p>These common words are <strong>stop words</strong> that should NOT be included in your post URL.</p>



<p>Common words will increase your headline&#8217;s readability, but they are not meaningful themselves.</p>



<h2 class="wp-block-heading">List of 59 Power Words to Use in Post Titles</h2>



<figure id="result" class="wp-block-table is-style-stripes"><table><tbody><tr><td>about</td></tr><tr><td>after</td></tr><tr><td>all</td></tr><tr><td>and</td></tr><tr><td>are</td></tr><tr><td>as</td></tr><tr><td>at</td></tr><tr><td>be</td></tr><tr><td>but</td></tr><tr><td>by</td></tr><tr><td>can</td></tr><tr><td>did</td></tr><tr><td>do</td></tr><tr><td>ever</td></tr><tr><td>for</td></tr><tr><td>from</td></tr><tr><td>get</td></tr><tr><td>has</td></tr><tr><td>have</td></tr><tr><td>he</td></tr><tr><td>her</td></tr><tr><td>his</td></tr><tr><td>how</td></tr><tr><td>I</td></tr><tr><td>if</td></tr><tr><td>in</td></tr><tr><td>is</td></tr><tr><td>it</td></tr><tr><td>just</td></tr><tr><td>like</td></tr><tr><td>ll</td></tr><tr><td>me</td></tr><tr><td>most</td></tr><tr><td>my</td></tr><tr><td>no</td></tr><tr><td>not</td></tr><tr><td>of</td></tr><tr><td>on</td></tr><tr><td>re</td></tr><tr><td>she</td></tr><tr><td>should</td></tr><tr><td>so</td></tr><tr><td>that</td></tr><tr><td>the</td></tr><tr><td>their</td></tr><tr><td>there</td></tr><tr><td>these</td></tr><tr><td>they</td></tr><tr><td>things</td></tr><tr><td>this</td></tr><tr><td>to</td></tr><tr><td>up</td></tr><tr><td>was</td></tr><tr><td>what</td></tr><tr><td>when</td></tr><tr><td>who</td></tr><tr><td>why</td></tr><tr><td>will</td></tr><tr><td>with</td></tr><tr><td>you</td></tr><tr><td>your</td></tr></tbody></table></figure>



<h2 class="wp-block-heading">More Words to Use in Headlines</h2>



<p>I provided three other word lists for <a href="https://mehdinazari.com/uncommon-words-for-post-titles/" title="53 Uncommon Words You Need Insanely in Unique Post Titles!">Uncommon Words</a>, <a href="https://mehdinazari.com/power-words-for-post-titles/" title="171 Power Words You See in the Innovative Post Titles!">Power Words</a>, and <a href="https://mehdinazari.com/emotional-words-for-post-titles/" target="_blank" rel="noopener" title="">Emotional Words</a>.</p>



<p>Each of these lists contains useful words to drive more visitors to your posts from search engines. Especially, power words are the most useful for SEO post titles.</p><p>The post <a href="https://mehdinazari.com/common-words-for-post-titles/">59 Common Words You Want in the Attractive Post Titles!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/common-words-for-post-titles/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>171 Power Words You See in the Innovative Post Titles!</title>
		<link>https://mehdinazari.com/power-words-for-post-titles/</link>
					<comments>https://mehdinazari.com/power-words-for-post-titles/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Sun, 05 Feb 2023 15:21:07 +0000</pubDate>
				<category><![CDATA[SEO]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=5128</guid>

					<description><![CDATA[<p>Looking for a list of Power Words to use in your post headline? Here is a complete list of power words to help your SEO and make your post titles engaging. You need at least one power word in your post headline. You can use more, but you may want to reserve the place for [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/power-words-for-post-titles/">171 Power Words You See in the Innovative Post Titles!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Looking for a list of Power Words to use in your post headline? Here is a complete list of power words to help your SEO and make your post titles engaging.</p>



<span id="more-5128"></span>



<p>You need <strong>at least one power word in your post headline</strong>.</p>



<p>You can use more, but you may want to reserve the place for common, uncommon, and emotional words.</p>



<h2 class="wp-block-heading">What are Power Words, and How Can They Help My SEO?</h2>



<p>A &#8220;<strong>power word</strong>&#8221; is interesting enough to attract the user&#8217;s attention between other results on the search page.</p>



<p>Users constantly scroll from top to bottom of the search page and look for an eye-catching title that matches their needs.</p>



<h3 class="wp-block-heading">So what makes a page worthy enough to click on it?</h3>



<p><strong>First</strong>, the title must be <strong>relevant to the search query</strong>.</p>



<p><strong>Then</strong>, there must be something, like <strong>a Hook</strong>, that grabs them and makes them stay and read more.</p>



<p><strong>Power Words are the Hook for the eyes</strong> that forces them to read the title at least.</p>



<h3 class="wp-block-heading">How are power words relevant to SEO?</h3>



<p><strong>Power words can increase your CTR</strong> by attracting users to read your post title. They shine like an invitation between your words.</p>



<h4 class="wp-block-heading">What is CTR?</h4>



<p>It stands for <strong>Click Through Rate</strong>, a metric demonstrating how many clicked on your post per 100 searchers. </p>



<p>For example, if you got <strong>4 clicks</strong> when there were <strong>100 impressions</strong> of your post in searches, your <strong>CTR will be 4%</strong>.</p>



<h4 class="wp-block-heading">What is a good CTR?</h4>



<p>It&#8217;s an interesting question that does not have a simple answer.</p>



<p>Because a good CTR can vary from position to position.</p>



<p>But I can say that anything above <strong>30% for general topics is above average if you ranked #1</strong> in search results.</p>



<p>CTR expectations will decrease if you are not on the list.</p>



<p>For the page with a <strong>30% CTR in the #1 position</strong>, we can expect a <strong>3% CTR</strong> if it is in the <strong>#10 position</strong>.</p>



<p>There is an <a href="https://backlinko.com/google-ctr-stats" target="_blank" rel="noopener" title="">article published on backlinko.com about this subject</a> that can answer your question with details, have a look at that.</p>



<p>Now if you are interested in words that can help you increase your CTR, look at my list of power words.</p>



<h2 class="wp-block-heading">List of 171 Power Words to Use in Post Titles</h2>



<figure id="result" class="wp-block-table is-style-stripes"><table><tbody><tr><td>absolutely lowest</td></tr><tr><td>advice</td></tr><tr><td>affordable</td></tr><tr><td>alert famous</td></tr><tr><td>amazing</td></tr><tr><td>announcing</td></tr><tr><td>approved</td></tr><tr><td>astonishing</td></tr><tr><td>attractive</td></tr><tr><td>authentic</td></tr><tr><td>bargain</td></tr><tr><td>beautiful</td></tr><tr><td>better</td></tr><tr><td>big</td></tr><tr><td>bonanza</td></tr><tr><td>bottom line</td></tr><tr><td>breakthrough</td></tr><tr><td>challenge</td></tr><tr><td>colorful</td></tr><tr><td>colossal</td></tr><tr><td>compare</td></tr><tr><td>competitive</td></tr><tr><td>complete</td></tr><tr><td>compromise</td></tr><tr><td>confidential</td></tr><tr><td>crammed</td></tr><tr><td>daring</td></tr><tr><td>delighted</td></tr><tr><td>delivered</td></tr><tr><td>destiny</td></tr><tr><td>direct</td></tr><tr><td>discount</td></tr><tr><td>download</td></tr><tr><td>easily</td></tr><tr><td>easy</td></tr><tr><td>edge</td></tr><tr><td>emerging</td></tr><tr><td>endorsed</td></tr><tr><td>energy</td></tr><tr><td>enormous</td></tr><tr><td>excellent</td></tr><tr><td>exciting</td></tr><tr><td>exclusive</td></tr><tr><td>expert</td></tr><tr><td>exploit</td></tr><tr><td>fascinating</td></tr><tr><td>focus</td></tr><tr><td>fortune</td></tr><tr><td>free</td></tr><tr><td>full</td></tr><tr><td>fundamentals</td></tr><tr><td>genuine</td></tr><tr><td>gigantic</td></tr><tr><td>great</td></tr><tr><td>greatest</td></tr><tr><td>growth</td></tr><tr><td>guaranteed</td></tr><tr><td>helpful</td></tr><tr><td>high tech</td></tr><tr><td>highest</td></tr><tr><td>how to</td></tr><tr><td>huge gift</td></tr><tr><td>hurry</td></tr><tr><td>imagination</td></tr><tr><td>immediately</td></tr><tr><td>important</td></tr><tr><td>improved</td></tr><tr><td>informative</td></tr><tr><td>innovative</td></tr><tr><td>insider</td></tr><tr><td>instructive</td></tr><tr><td>interesting</td></tr><tr><td>introducing</td></tr><tr><td>just arrived</td></tr><tr><td>largest</td></tr><tr><td>last chance</td></tr><tr><td>last minute</td></tr><tr><td>latest</td></tr><tr><td>launching</td></tr><tr><td>lavishly</td></tr><tr><td>liberal</td></tr><tr><td>lifetime</td></tr><tr><td>limited</td></tr><tr><td>love</td></tr><tr><td>luxury</td></tr><tr><td>magic</td></tr><tr><td>mainstream</td></tr><tr><td>mammoth</td></tr><tr><td>miracle</td></tr><tr><td>monumental</td></tr><tr><td>new</td></tr><tr><td>noted</td></tr><tr><td>now</td></tr><tr><td>obsession</td></tr><tr><td>odd</td></tr><tr><td>opportunities</td></tr><tr><td>outstanding</td></tr><tr><td>perspective</td></tr><tr><td>pioneering</td></tr><tr><td>popular</td></tr><tr><td>portfolio</td></tr><tr><td>powerful</td></tr><tr><td>practical</td></tr><tr><td>professional</td></tr><tr><td>profitable</td></tr><tr><td>promising</td></tr><tr><td>proven</td></tr><tr><td>quality</td></tr><tr><td>quick</td></tr><tr><td>quickly</td></tr><tr><td>rare</td></tr><tr><td>reduced</td></tr><tr><td>refundable</td></tr><tr><td>reliable</td></tr><tr><td>remarkable</td></tr><tr><td>revealing</td></tr><tr><td>revisited</td></tr><tr><td>revolutionary</td></tr><tr><td>reward</td></tr><tr><td>sale</td></tr><tr><td>sampler</td></tr><tr><td>scarce</td></tr><tr><td>secrets</td></tr><tr><td>security</td></tr><tr><td>selected</td></tr><tr><td>sensational</td></tr><tr><td>shrewd</td></tr><tr><td>simple</td></tr><tr><td>simplified</td></tr><tr><td>simplistic</td></tr><tr><td>sizable</td></tr><tr><td>skill</td></tr><tr><td>soar</td></tr><tr><td>special</td></tr><tr><td>special offer</td></tr><tr><td>spotlight</td></tr><tr><td>startling</td></tr><tr><td>strange</td></tr><tr><td>strong</td></tr><tr><td>sturdy</td></tr><tr><td>successful</td></tr><tr><td>suddenly</td></tr><tr><td>superior</td></tr><tr><td>surging</td></tr><tr><td>surprise</td></tr><tr><td>survival</td></tr><tr><td>technology</td></tr><tr><td>terrific</td></tr><tr><td>test</td></tr><tr><td>the truth about</td></tr><tr><td>timely</td></tr><tr><td>tremendous</td></tr><tr><td>ultimate</td></tr><tr><td>unconditional</td></tr><tr><td>underpriced</td></tr><tr><td>unique</td></tr><tr><td>unlimited</td></tr><tr><td>unlock</td></tr><tr><td>unparalleled</td></tr><tr><td>unsurpassed</td></tr><tr><td>unusual</td></tr><tr><td>urgent</td></tr><tr><td>useful</td></tr><tr><td>valuable</td></tr><tr><td>value</td></tr><tr><td>wanted</td></tr><tr><td>wealth</td></tr><tr><td>weird</td></tr><tr><td>willpower</td></tr><tr><td>wonderful</td></tr><tr><td>zinger</td></tr></tbody></table></figure>



<h2 class="wp-block-heading">Are you Looking for More Words that Can Help your SEO?</h2>



<p>After this long list, If you are reading this, it&#8217;s a huge chance that you do!</p>



<p>To find more words helpful for SEO-concerned post titles, you may look at the list of <a href="https://mehdinazari.com/common-words-for-post-titles/" target="_blank" rel="noopener" title="">Common Words</a>, <a href="https://mehdinazari.com/uncommon-words-for-post-titles/" target="_blank" rel="noopener" title="">Uncommon Words</a>, and <a href="https://mehdinazari.com/emotional-words-for-post-titles/" target="_blank" rel="noopener" title="">Emotional Words</a> after this one.</p><p>The post <a href="https://mehdinazari.com/power-words-for-post-titles/">171 Power Words You See in the Innovative Post Titles!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/power-words-for-post-titles/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>267 Emotional Words You See in the Popular Post Titles!</title>
		<link>https://mehdinazari.com/emotional-words-for-post-titles/</link>
					<comments>https://mehdinazari.com/emotional-words-for-post-titles/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Sun, 05 Feb 2023 15:21:04 +0000</pubDate>
				<category><![CDATA[SEO]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=5097</guid>

					<description><![CDATA[<p>Here is a sorted list of the best emotional words for SEO to drive visitors to your blog posts from search results. You must use emotional words between 10% to 15% of your headline. Use at least one of these 267 emotional words I provided in this list when writing your next post&#8217;s title. List [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/emotional-words-for-post-titles/">267 Emotional Words You See in the Popular Post Titles!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Here is a sorted list of the best emotional words for SEO to drive visitors to your blog posts from search results. You must use emotional words between 10% to 15% of your headline.</p>



<span id="more-5097"></span>



<p>Use at least one of these 267 emotional words I provided in this list when writing your next post&#8217;s title.</p>



<h2 class="wp-block-heading">List of 267 Emotional Words to Use in Post Titles</h2>



<figure id="result" class="wp-block-table is-style-stripes"><table><tbody><tr><td>destroy</td></tr><tr><td>devastating</td></tr><tr><td>devoted</td></tr><tr><td>dirty</td></tr><tr><td>disastrous</td></tr><tr><td>disgusting</td></tr><tr><td>disinformation</td></tr><tr><td>dollar</td></tr><tr><td>double</td></tr><tr><td>drowning</td></tr><tr><td>dumb</td></tr><tr><td>embarrass</td></tr><tr><td>empower</td></tr><tr><td>energize</td></tr><tr><td>epic</td></tr><tr><td>evil</td></tr><tr><td>excited</td></tr><tr><td>explode</td></tr><tr><td>exposed</td></tr><tr><td>extra</td></tr><tr><td>eye-opening</td></tr><tr><td>fail</td></tr><tr><td>faith</td></tr><tr><td>famous</td></tr><tr><td>fantastic</td></tr><tr><td>fearless</td></tr><tr><td>feast</td></tr><tr><td>feeble</td></tr><tr><td>fire</td></tr><tr><td>fleece</td></tr><tr><td>floundering</td></tr><tr><td>flush</td></tr><tr><td>fool</td></tr><tr><td>for the first time</td></tr><tr><td>forbidden</td></tr><tr><td>forgotten</td></tr><tr><td>foul</td></tr><tr><td>frantic</td></tr><tr><td>freebie</td></tr><tr><td>frenzy</td></tr><tr><td>fresh on the mind</td></tr><tr><td>frightening</td></tr><tr><td>frugal</td></tr><tr><td>fulfill</td></tr><tr><td>gift</td></tr><tr><td>grateful</td></tr><tr><td>greed</td></tr><tr><td>grit</td></tr><tr><td>gullible</td></tr><tr><td>hack</td></tr><tr><td>had enough</td></tr><tr><td>happy</td></tr><tr><td>hate</td></tr><tr><td>hazardous</td></tr><tr><td>helpless</td></tr><tr><td>hidden</td></tr><tr><td>high</td></tr><tr><td>hoax</td></tr><tr><td>hope</td></tr><tr><td>horrific</td></tr><tr><td>how to make</td></tr><tr><td>hurricane</td></tr><tr><td>hypnotic</td></tr><tr><td>illegal</td></tr><tr><td>in the</td></tr><tr><td>in the world</td></tr><tr><td>inexpensive</td></tr><tr><td>insanely</td></tr><tr><td>insidious</td></tr><tr><td>invasion</td></tr><tr><td>ironclad</td></tr><tr><td>irresistibly</td></tr><tr><td>is the</td></tr><tr><td>is what happens when</td></tr><tr><td>it looks like a</td></tr><tr><td>jackpot</td></tr><tr><td>jail</td></tr><tr><td>jaw-dropping</td></tr><tr><td>jeopardy</td></tr><tr><td>jubilant</td></tr><tr><td>killer</td></tr><tr><td>know it all</td></tr><tr><td>lawsuit</td></tr><tr><td>lies</td></tr><tr><td>like a normal</td></tr><tr><td>line</td></tr><tr><td>loathsome</td></tr><tr><td>lonely</td></tr><tr><td>looks like a</td></tr><tr><td>looming</td></tr><tr><td>lost</td></tr><tr><td>lowest</td></tr><tr><td>lunatic</td></tr><tr><td>lurking</td></tr><tr><td>lust</td></tr><tr><td>luxurious</td></tr><tr><td>lying</td></tr><tr><td>marked down</td></tr><tr><td>massive</td></tr><tr><td>meltdown</td></tr><tr><td>mind-blowing</td></tr><tr><td>minute</td></tr><tr><td>mired</td></tr><tr><td>mistakes</td></tr><tr><td>money</td></tr><tr><td>moneyback</td></tr><tr><td>money-grubbing</td></tr><tr><td>myths</td></tr><tr><td>never again</td></tr><tr><td>nightmare</td></tr><tr><td>no good</td></tr><tr><td>no questions asked</td></tr><tr><td>obnoxious</td></tr><tr><td>of the</td></tr><tr><td>offer</td></tr><tr><td>official</td></tr><tr><td>off-limits</td></tr><tr><td>on the</td></tr><tr><td>outlawed</td></tr><tr><td>overcome</td></tr><tr><td>painful</td></tr><tr><td>pale</td></tr><tr><td>panic</td></tr><tr><td>pay zero</td></tr><tr><td>payback</td></tr><tr><td>peril</td></tr><tr><td>piranha</td></tr><tr><td>pitfall</td></tr><tr><td>plague</td></tr><tr><td>played</td></tr><tr><td>pluck</td></tr><tr><td>plummet</td></tr><tr><td>plunge</td></tr><tr><td>pointless</td></tr><tr><td>poor</td></tr><tr><td>pound</td></tr><tr><td>preposterous</td></tr><tr><td>priced</td></tr><tr><td>prison</td></tr><tr><td>privacy</td></tr><tr><td>private</td></tr><tr><td>prize</td></tr><tr><td>profit</td></tr><tr><td>protected</td></tr><tr><td>provocative</td></tr><tr><td>pummel</td></tr><tr><td>punish</td></tr><tr><td>quadruple</td></tr><tr><td>reckoning</td></tr><tr><td>reclaim</td></tr><tr><td>refugee</td></tr><tr><td>refund</td></tr><tr><td>remarkably</td></tr><tr><td>research</td></tr><tr><td>results</td></tr><tr><td>revenge</td></tr><tr><td>revolting</td></tr><tr><td>rich</td></tr><tr><td>risky</td></tr><tr><td>ruthless</td></tr><tr><td>scary</td></tr><tr><td>scream</td></tr><tr><td>searing</td></tr><tr><td>secure</td></tr><tr><td>seductively</td></tr><tr><td>seize</td></tr><tr><td>shameless</td></tr><tr><td>shatter</td></tr><tr><td>shellacking</td></tr><tr><td>sick and tired</td></tr><tr><td>silly</td></tr><tr><td>sinful</td></tr><tr><td>six-figure</td></tr><tr><td>skyrocket</td></tr><tr><td>slaughter</td></tr><tr><td>sleazy</td></tr><tr><td>smash</td></tr><tr><td>smug</td></tr><tr><td>smuggled</td></tr><tr><td>sniveling</td></tr><tr><td>snob</td></tr><tr><td>soaring</td></tr><tr><td>spectacular</td></tr><tr><td>spine</td></tr><tr><td>spirit</td></tr><tr><td>staggering</td></tr><tr><td>strangle</td></tr><tr><td>stuck up</td></tr><tr><td>stunning</td></tr><tr><td>stupid</td></tr><tr><td>sure</td></tr><tr><td>surge</td></tr><tr><td>surprising</td></tr><tr><td>surprisingly</td></tr><tr><td>surrender</td></tr><tr><td>swindle</td></tr><tr><td>tank</td></tr><tr><td>tantalizing</td></tr><tr><td>targeted</td></tr><tr><td>tawdry</td></tr><tr><td>tech</td></tr><tr><td>teetering</td></tr><tr><td>temporary fix</td></tr><tr><td>tempting</td></tr><tr><td>terror</td></tr><tr><td>that will</td></tr><tr><td>that will make</td></tr><tr><td>that will make you</td></tr><tr><td>the best</td></tr><tr><td>the most</td></tr><tr><td>the ranking of</td></tr><tr><td>the reason why is</td></tr><tr><td>this is</td></tr><tr><td>this is the</td></tr><tr><td>this is what</td></tr><tr><td>this is what happens</td></tr><tr><td>thrilled</td></tr><tr><td>thrilling</td></tr><tr><td>tired</td></tr><tr><td>to be</td></tr><tr><td>to the</td></tr><tr><td>toxic</td></tr><tr><td>trap</td></tr><tr><td>treasure</td></tr><tr><td>triple</td></tr><tr><td>triumph</td></tr><tr><td>truth</td></tr><tr><td>try before you buy</td></tr><tr><td>turn the tables</td></tr><tr><td>unauthorized</td></tr><tr><td>unbelievably</td></tr><tr><td>uncommonly</td></tr><tr><td>under</td></tr><tr><td>underhanded</td></tr><tr><td>unexpected</td></tr><tr><td>unscrupulous</td></tr><tr><td>unusually</td></tr><tr><td>uplifting</td></tr><tr><td>valor</td></tr><tr><td>vaporize</td></tr><tr><td>verify</td></tr><tr><td>vibrant</td></tr><tr><td>victim</td></tr><tr><td>victory</td></tr><tr><td>vindication</td></tr><tr><td>viral</td></tr><tr><td>volatile</td></tr><tr><td>vulnerable</td></tr><tr><td>wanton</td></tr><tr><td>warning</td></tr><tr><td>what happened</td></tr><tr><td>what happens</td></tr><tr><td>what happens when</td></tr><tr><td>what this</td></tr><tr><td>when you</td></tr><tr><td>whip</td></tr><tr><td>whopping</td></tr><tr><td>wicked</td></tr><tr><td>will make you</td></tr><tr><td>withheld</td></tr><tr><td>wondrous</td></tr><tr><td>worry</td></tr><tr><td>wounded</td></tr><tr><td>you need to</td></tr><tr><td>you need to know</td></tr><tr><td>you see</td></tr><tr><td>you see what</td></tr></tbody></table></figure>



<h2 class="wp-block-heading">Learn 300 More Words that Can Help Your SEO</h2>



<p>There are more than 300 words in 3 articles in my blog; you may look at them in <a href="https://mehdinazari.com/common-words-for-post-titles/" target="_blank" rel="noopener" title="">Common Words</a>, <a href="https://mehdinazari.com/uncommon-words-for-post-titles/" target="_blank" rel="noopener" title="">Uncommon Words</a>, and <a href="https://mehdinazari.com/power-words-for-post-titles/" target="_blank" rel="noopener" title="171 Power Words You See in the Innovative Post Titles!">Power Words</a> to read the complete list of these words.</p><p>The post <a href="https://mehdinazari.com/emotional-words-for-post-titles/">267 Emotional Words You See in the Popular Post Titles!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/emotional-words-for-post-titles/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Add Thumbnail Support to the WordPress Theme</title>
		<link>https://mehdinazari.com/how-to-add-thumbnail-support-to-the-wordpress-theme/</link>
					<comments>https://mehdinazari.com/how-to-add-thumbnail-support-to-the-wordpress-theme/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 05 Jan 2023 10:34:50 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<category><![CDATA[Advanced WordPress Tutorials]]></category>
		<category><![CDATA[Extend WordPress Functionalities]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress plugin development for beginners]]></category>
		<category><![CDATA[WordPress tutorials for beginners]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=6249</guid>

					<description><![CDATA[<p>If you do not see the set featured image box beside the post editor in the WordPress admin panel to set the featured image of posts, your solution is here. Just copy/paste this code snippet to the function.php file of your theme. Code to Fix the No Thumbnail Support Problem There is a common problem [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/how-to-add-thumbnail-support-to-the-wordpress-theme/">How to Add Thumbnail Support to the WordPress Theme</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>If you do not see the set featured image box beside the post editor in the WordPress admin panel to set the featured image of posts, your solution is here. Just copy/paste this code snippet to the function.php file of your theme.</p>



<span id="more-6249"></span>



<h2 class="wp-block-heading">Code to Fix the No Thumbnail Support Problem</h2>



<p>There is a common problem for beginner developers when developing a new theme for WordPress.<br />You need to <a href="https://mehdinazari.com/add_theme_support-wordpress-function/" target="_blank" rel="noopener" title="">register some features for your theme</a> to use them in your theme. One of them is post thumbnail support which can be added using the below code in the <code>function.php</code> file:</p>



<pre><code class="language-php">function my_theme_register_post_thumnails(){
    add_theme_support( 'post-thumbnails' );
}
add_action( 'after_setup_theme', 'my_theme_register_post_thumnails' );</code></pre>



<p>After copying the above code to the <code>functions.php</code> file of your custom theme, you can visit the post editor to see the <strong>Set featured image</strong> box in the sidebar under the <strong>Featured image</strong> headline.</p>



<h2 class="wp-block-heading">Why did this problem happen?</h2>



<p>Not all WordPress features are usable directly in custom themes. You may need to register some features for themes to use them.</p>



<p>Here is the list of features you must register before using them in your custom theme:</p>



<ul class="wp-block-list">
<li><code>admin-bar</code></li>



<li><code>align-wide</code></li>



<li><code>automatic-feed-links</code></li>



<li><code>core-block-patterns</code></li>



<li><code>custom-background</code></li>



<li><code>custom-header</code></li>



<li><code>custom-line-height</code></li>



<li><code>custom-logo</code></li>



<li><code>customize-selective-refresh-widgets</code></li>



<li><code>custom-spacing</code></li>



<li><code>custom-units</code></li>



<li><code>dark-editor-style</code></li>



<li><code>disable-custom-colors</code></li>



<li><code>disable-custom-font-sizes</code></li>



<li><code>editor-color-palette</code></li>



<li><code>editor-gradient-presets</code></li>



<li><code>editor-font-sizes</code></li>



<li><code>editor-styles</code></li>



<li><code>featured-content</code></li>



<li><code>html5</code></li>



<li><code>menus</code></li>



<li><code>post-formats</code></li>



<li><code>post-thumbnails</code></li>



<li><code>responsive-embeds</code></li>



<li><code>starter-content</code></li>



<li><code>title-tag</code></li>



<li><code>wp-block-styles</code></li>



<li><code>widgets</code></li>



<li><code>widgets-block-editor</code></li>
</ul><p>The post <a href="https://mehdinazari.com/how-to-add-thumbnail-support-to-the-wordpress-theme/">How to Add Thumbnail Support to the WordPress Theme</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/how-to-add-thumbnail-support-to-the-wordpress-theme/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Use add_theme_support Function in WordPress</title>
		<link>https://mehdinazari.com/add_theme_support-wordpress-function/</link>
					<comments>https://mehdinazari.com/add_theme_support-wordpress-function/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 05 Jan 2023 09:29:31 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[Advanced WordPress Tutorials]]></category>
		<category><![CDATA[Extend WordPress Functionalities]]></category>
		<category><![CDATA[WordPress tutorials for beginners]]></category>
		<guid isPermaLink="false">http://localhost/mehdinazari/?p=2598</guid>

					<description><![CDATA[<p>add_theme_support function in WP will register a feature for the specified theme. Here are a few examples of using the add_theme_support() function in WordPress development. add_theme_support Function Introduction WordPress asks developers to register features for their custom theme in the function.php if they want to use them. add_theme_support function in WordPress is responsible for registering [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/add_theme_support-wordpress-function/">How to Use add_theme_support Function in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>add_theme_support function in WP will register a feature for the specified theme. Here are a few examples of using the add_theme_support() function in WordPress development.</p>



<span id="more-2598"></span>



<h2 class="wp-block-heading"><code>add_theme_support</code> Function Introduction</h2>



<p>WordPress asks developers to register features for their custom theme in the <code>function.php</code> if they want to use them.</p>



<p><a href="https://developer.wordpress.org/reference/functions/add_theme_support/" target="_blank" rel="noopener" title=""><code>add_theme_support</code> function in WordPress</a> is responsible for registering features in themes.</p>



<p>For example, using thumbnails in a theme requires registering the <code>post-thumbnails</code> feature for that theme with this code:</p>



<pre><code class="language-php">function my_theme_register_post_thumnails(){
    add_theme_support( 'post-thumbnails' );
}
add_action( 'after_setup_theme', 'my_theme_register_post_thumnails' );</code></pre>



<p>Did you notice the after_setup_theme hook in the above code? I used it because It&#8217;s important to register the feature at the right time (hook).</p>



<p>In my examples at the end of this article, you can see a few features registered for a custom theme using the after_setup_theme hook.</p>



<p>Features that a custom theme needs to register before using them are listed below:</p>



<ul class="wp-block-list">
<li><code>admin-bar</code></li>



<li><code>align-wide</code></li>



<li><code>automatic-feed-links</code></li>



<li><code>core-block-patterns</code></li>



<li><code>custom-background</code></li>



<li><code>custom-header</code></li>



<li><code>custom-line-height</code></li>



<li><code>custom-logo</code></li>



<li><code>customize-selective-refresh-widgets</code></li>



<li><code>custom-spacing</code></li>



<li><code>custom-units</code></li>



<li><code>dark-editor-style</code></li>



<li><code>disable-custom-colors</code></li>



<li><code>disable-custom-font-sizes</code></li>



<li><code>editor-color-palette</code></li>



<li><code>editor-gradient-presets</code></li>



<li><code>editor-font-sizes</code></li>



<li><code>editor-styles</code></li>



<li><code>featured-content</code></li>



<li><code>html5</code></li>



<li><code>menus</code></li>



<li><code>post-formats</code></li>



<li><code>post-thumbnails</code></li>



<li><code>responsive-embeds</code></li>



<li><code>starter-content</code></li>



<li><code>title-tag</code></li>



<li><code>wp-block-styles</code></li>



<li><code>widgets</code></li>



<li><code>widgets-block-editor</code></li>
</ul>



<p>The most useful features inside the list, in my opinion, are post-thumbnails, post-formats, widgets, title-tag, and menus. But if you want to develop a theme with visual page builder support, you will use it much more!</p>



<h2 class="wp-block-heading"><code>add_theme_support</code> Function Syntax</h2>



<pre><code class="language-php">add_theme_support( string&nbsp;$feature,  mixed&nbsp;$args&nbsp;)</code></pre>



<h2 class="wp-block-heading"><code>add_theme_support</code> Function Parameters</h2>



<ul class="wp-block-list">
<li><b><code>$feature</code></b>: Name of the feature you want to add to the theme.</li>



<li><b><code>$args</code></b>:  Some features can be customized using this argument. </li>
</ul>



<h2 class="wp-block-heading"><code>add_theme_support</code> Function Result</h2>



<p>If there is a problem in adding the requested feature to the theme, <code>add_theme_support</code> function will return false. Otherwise, there is no return.</p>



<h2 class="wp-block-heading"><code>add_theme_support</code> Function Examples</h2>



<p>Here are three examples of using the <code>add_theme_support</code> function to register features for your custom theme:</p>



<h3 class="wp-block-heading">1- Add support for post thumbnails to your custom theme</h3>



<pre><code class="language-php">function my_theme_register_post_thumnails(){
    add_theme_support( 'post-thumbnails' );
}
add_action( 'after_setup_theme', 'my_theme_register_post_thumnails' );</code></pre>



<p>After putting the above code in your theme or <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/" target="_blank" rel="noopener" title="How to create a Hello World plugin for WordPress in 3 Steps">custom plugin</a>, you can see the Featured Image box in the post editor of the WordPress admin panel.</p>



<p>To get the URL of your thumbnails, Use this code:</p>



<pre><code class="language-php">$postId = 1; //or get_the_ID() for current post
$thumbnailSize = 'thumbnail';
$thumbnailUrl = get_the_post_thumbnail_url( $postId, $thumbnailSize );</code></pre>



<h3 class="wp-block-heading">2- Add support for uploading a custom logo to your theme</h3>



<p>To add support for a custom logo with defined width of 400px and height of 100px, use this code:</p>



<pre><code class="language-php">function my_theme_register_custom_logo(){
    $logoOptions = array(
        'height'               =&gt; 100,
        'width'                =&gt; 400,
        'flex-height'          =&gt; true,
        'flex-width'           =&gt; true,
        'header-text'          =&gt; array( 'site-title', 'site-description' ),
        'unlink-homepage-logo' =&gt; true,
    );
    add_theme_support( 'custom-logo', $logoOptions );
}
add_action( 'after_setup_theme', 'my_theme_register_custom_logo' );</code></pre>



<p>Now you can upload the logo from <code>Admin Panel -&gt; Appearance -&gt; Customize -&gt; Site Identity -&gt; Logo</code>.</p>



<p>To print the logo in your theme, use <code>the_custom_logo()</code> function. This function has its HTML markup implemented.</p>



<p>If you want only the logo URL without any additional markup, use this code:</p>



<pre><code class="language-php">$customLogoId = get_theme_mod( 'custom_logo' );
$logo = wp_get_attachment_image_src( $customLogoId, 'full' );
$logoUrl = 'put your default logo url here';
if( !is_empty( $logo ) )
    $logoUrl = $logo[0];</code></pre>



<h3 class="wp-block-heading">3- Add support for a custom background for your theme</h3>



<p>To register support for a custom background color and image, you must use the <code>add_theme_support('custom-background')</code> code. Like below:</p>



<pre><code class="language-php">function my_theme_register_custom_background(){
    $customBackgroundOptions = array(
        //default color for custom background (this is black)
        'default-color' =&gt; '000000',
        //default image url (this is the background.jpg image 
        'default-image' =&gt; '%1$s/assets/images/background.jpg',
    );
    add_theme_support( 'custom-background', $customBackgroundOptions );
}
add_action( 'after_setup_theme', 'my_theme_register_custom_background' );</code></pre>



<p>Now you can change the background color from <code>Admin Panel -&gt; Appearance -&gt; Customize -&gt; Colors</code>.</p>



<p>And upload the background image from <code>Admin Panel -&gt; Appearance -&gt; Customize -&gt; Background Image</code>.</p>



<p>To use this background option, make sure you have the <code>body_class()</code> function in <code>&lt;body&gt;</code> tag of your theme:</p>



<pre><code class="language-php">&lt;body &lt;?php body_class(); ?&gt;&gt;</code></pre>



<p>If you still do not see the background (not even in the codes), it&#8217;s maybe because you did not include the <code>wp_head()</code> function in <code>&lt;head&gt;</code> tag of your theme.</p><p>The post <a href="https://mehdinazari.com/add_theme_support-wordpress-function/">How to Use add_theme_support Function in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/add_theme_support-wordpress-function/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Add a Custom Section to Settings Page in WordPress</title>
		<link>https://mehdinazari.com/add_settings_section-wordpress-function/</link>
					<comments>https://mehdinazari.com/add_settings_section-wordpress-function/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Wed, 04 Jan 2023 17:05:42 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<category><![CDATA[Advanced WordPress Tutorials]]></category>
		<category><![CDATA[Extend WordPress Functionalities]]></category>
		<category><![CDATA[WordPress plugin development for beginners]]></category>
		<category><![CDATA[WordPress tutorials for beginners]]></category>
		<guid isPermaLink="false">http://localhost/mehdinazari/?p=2591</guid>

					<description><![CDATA[<p>Learn how to add a new section to the settings page of the WordPress admin panel with examples. In this WordPress tutorial, we&#8217;ll introduce the WordPress add_settings_section function and review its usage with examples. add_settings_section Function Introduction Since WordPress V2.7.0 The add_settings_section Function is responsible for adding a new section to the settings page inside [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/add_settings_section-wordpress-function/">How to Add a Custom Section to Settings Page in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Learn how to add a new section to the settings page of the WordPress admin panel with examples. In this WordPress tutorial, we&#8217;ll introduce the WordPress add_settings_section function and review its usage with examples.</p>



<span id="more-2591"></span>



<h2 class="wp-block-heading" id="introduction"><a href="#introduction" title=""><code>add_settings_section</code> Function Introduction</a></h2>



<p>Since WordPress V2.7.0 The <a href="https://developer.wordpress.org/reference/functions/add_settings_section/" target="_blank" rel="noopener" title=""><code>add_settings_section</code> Function</a> is responsible for adding a new section to the settings page inside the WordPress admin panel.</p>



<p>To add a new section to the settings page, you need to give this function an ID to set on the section, a title to display for the admin, a callback function to print what you need in this section, and the slug of the settings page.</p>



<p>The last parameter in the add_settings_section is an optional array you can use to customize your settings section. This array was introduced in WordPress V.6.1.0.</p>



<h3 class="wp-block-heading" id="usage"><a href="#usage" title="">Basic usage of add_settings_section function:</a></h3>



<pre><code class="language-php">add_settings_section(
	'id_for_settings_section',
	'A custom title to show',
	'my_custom_section_callback',
	'general',
	//since V6.1.0
	array(
		//prints before the section
		'before_section' =&gt; '&lt;div class="before-section"&gt;',
		//prints after the section (does not print in empty section)
		'after_section' =&gt; '&lt;/div&gt;', //html for after the section
	)
);</code></pre>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Note: please update WordPress to the latest version before using this function. Because there was a major change in the <code>add_settings_section()</code> since WordPress V.6.1.0.</p>
</blockquote>



<h2 class="wp-block-heading" id="syntax"><a href="#syntax" title=""><code>add_settings_section</code> Function Syntax</a></h2>



<p>Look at the syntax below; there are four required string parameters and an optional array accepted by the add_settings_section function:</p>



<pre><code class="language-php">add_settings_section( string&nbsp;$id,  string&nbsp;$title,  callable&nbsp;$callback,  string&nbsp;$page, array&nbsp;$args&nbsp;)</code></pre>



<h2 class="wp-block-heading" id="parameters"><a href="#parameters" title=""><code>add_settings_section</code> Function Parameters</a></h2>



<ul class="wp-block-list">
<li><b><code>$id</code></b>: ID string to set for this section. Use a hyphenated string (slug).</li>



<li><b><code>$title</code></b>: this string is used to show a heading title for the new section.</li>



<li><b><code>$callback</code></b>:  to print the content of this section. (Not the form fields. They are added using the <code>add_settings_fields</code> function)</li>



<li><b><code>$page</code></b>: default options are: <strong>general</strong>, <strong>reading</strong>, <strong>writing</strong>, <strong>discussion</strong>, and <strong>media</strong>. If you added a custom settings page, you can use its slug here to add a section. (add new page using <code>add_options_page()</code>)</li>



<li><code><strong>$args</strong></code>: This array was recently introduced (since WordPress V6.1.0) to add HTML codes before or after the section by these array keys:
<ul class="wp-block-list">
<li><code><strong>before_section</strong></code>: HTML code to put before the section content</li>



<li><code><strong>after_section</strong></code>: HTML code to put after the section content. (does not print for empty sections)</li>
</ul>
</li>
</ul>



<h2 class="wp-block-heading" id="example"><a href="#parameters" title=""><code>add_settings_section</code> Function Example</a></h2>



<p>In this example, we&#8217;ll use add_settings_section with add_settings_field to print a section with sample fields.</p>



<pre><code class="language-php">//callback to print a simple section in general page
function my_custom_section_callback(){
	echo '<p>This text is inside the callback!</p>';
}

//callback to print a simple input field
function my_custom_field_callback(){
	echo '<input name="custom-field-name"/>';
}

function add_my_custom_section_to_settings(){

	//add the section to general page in admin panel
	add_settings_section(
		'id_for_settings_section',
		'A custom title to show',
		'my_custom_section_callback',
		'general',
		array(
			'before_section' =&gt; 'Text Before the Section', //html for before the section
			'after_section' =&gt; 'Text After the Section', //html for after the section
		)
	);

	//add a sample field to this section.
	add_settings_field(
		'id_for_setting_field',
		'A custom field',
		'my_custom_field_callback',
		'general',
		//put the id of custom section here:
		'id_for_settings_section'
	);

}
add_action('admin_init', 'add_my_custom_section_to_settings');</code></pre>



<p>After using this code in your <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/" target="_blank" rel="noopener" title="How to create a Hello World plugin for WordPress in 3 Steps">WordPress custom plugin</a> or functions.php of the active theme, You can open this URL to see the section:</p>



<p>http://siteurl.com/wp-admin/options-general.php</p>



<p>Look for something like this screenshot:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="336" src="https://mehdinazari.com/wp-content/uploads/2023/01/custom-section-wp-general-settings-1024x336.png" alt="" class="wp-image-6386" srcset="https://mehdinazari.com/wp-content/uploads/2023/01/custom-section-wp-general-settings-1024x336.png 1024w, https://mehdinazari.com/wp-content/uploads/2023/01/custom-section-wp-general-settings-300x99.png 300w, https://mehdinazari.com/wp-content/uploads/2023/01/custom-section-wp-general-settings-768x252.png 768w, https://mehdinazari.com/wp-content/uploads/2023/01/custom-section-wp-general-settings-1536x505.png 1536w, https://mehdinazari.com/wp-content/uploads/2023/01/custom-section-wp-general-settings-800x263.png 800w, https://mehdinazari.com/wp-content/uploads/2023/01/custom-section-wp-general-settings.png 1686w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Custom Section in WordPress General Settings</figcaption></figure><p>The post <a href="https://mehdinazari.com/add_settings_section-wordpress-function/">How to Add a Custom Section to Settings Page in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/add_settings_section-wordpress-function/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Programmatically Activate a Plugin in WordPress</title>
		<link>https://mehdinazari.com/activate_plugin-wordpress-function/</link>
					<comments>https://mehdinazari.com/activate_plugin-wordpress-function/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Fri, 30 Dec 2022 08:35:11 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[Advanced WordPress Tutorials]]></category>
		<category><![CDATA[WordPress plugin development for beginners]]></category>
		<category><![CDATA[WordPress tutorials for beginners]]></category>
		<guid isPermaLink="false">http://localhost/mehdinazari/?p=2546</guid>

					<description><![CDATA[<p>Learn how to activate a plugin in WP using the activate_plugin function programmatically. Here we provided an example of using this function to activate a WP plugin. Scroll to the bottom of the tutorial to see examples (or click here). In this WordPress tutorial, we&#8217;ll review the activate_plugin function and teach you how to activate [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/activate_plugin-wordpress-function/">How to Programmatically Activate a Plugin in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Learn how to activate a plugin in WP using the activate_plugin function programmatically. Here we provided an example of using this function to activate a WP plugin.</p>



<span id="more-2546"></span>



<p>Scroll to the bottom of the tutorial to see examples (or <a href="#examples" title="">click here</a>).</p>



<p>In this WordPress tutorial, we&#8217;ll review the <code>activate_plugin</code> function and teach you how to activate a plugin in WordPress using PHP, not the admin panel.</p>



<h2 class="wp-block-heading" id="introduction">activate_plugin Function: Activates a Plugin in WordPress</h2>



<p>This function is useful when activating a plugin using PHP codes when developing WordPress.</p>



<p>The <a href="https://developer.wordpress.org/reference/functions/activate_plugin/" target="_blank" rel="noopener" title=""><code>activate_plugin</code> function in WordPress</a> accepts one required parameter and three optional parameters.</p>



<p>The required parameter is the <a href="https://mehdinazari.com/get-plugin-directory-path-wordpress/" title="How to get Plugin Directory Path in WordPress (+Example)">path to the main file of the plugin</a>.&nbsp; the other three are just for customizing your activation request.</p>



<p>Nothing would be returned if there were no errors in the plugin activation. If you specify a redirection URL, this function will redirect the browser to the URL on success.</p>



<p>In case of failure, the <code>activate_plugin</code> will return <code>WP_Error</code>.</p>



<p>This is the basic usage if you want to activate &#8216;my-custom-plugin&#8217; from the plugins directory:</p>



<pre><code class="language-php">activate_plugin( 'my-custom-plugin/my-custom-plugin.php' );</code></pre>



<p>Keep reading for the complete usage guide if you need more information about the optional parameters and use cases.</p>



<p>If you do not know how to create a WP plugin, read my <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/" title="">creating a WordPress plugin</a> tutorial.</p>



<h3 class="wp-block-heading" id="syntax">activate_plugin Function Syntax</h3>



<p>As I mentioned above, activate_plugins accepts one required parameter, which is the path to the main PHP file of your plugin. The other three parameters are optional:</p>



<pre><code class="language-php">activate_plugin( string&nbsp;$plugin,  string&nbsp;$redirect&nbsp;=&nbsp;'',  bool&nbsp;$network_wide&nbsp;=&nbsp;false,  bool&nbsp;$silent&nbsp;=&nbsp;false&nbsp;)</code></pre>



<h3 class="wp-block-heading" id="parameters">activate_plugin Function Parameters</h3>



<ul class="wp-block-list">
<li><b><code>$plugin</code></b>: The relative or full path to the plugin&#8217;s main file. </li>



<li><b><code>$redirect</code></b>:  The URL you want to redirect to on success. Do not specify or set <code>''</code> if no redirection is needed.</li>



<li><b><code>$network_wide</code></b>:  Activate the plugin for the current website or all websites in WP multisite installation. Do not specify in a normal WP or set <code>false</code>.</li>



<li><b><code>$silent</code></b>: If set to <code>true</code>, activation hooks will not fire. The default value is <code>false</code>.</li>
</ul>



<h3 class="wp-block-heading" id="result">activate_plugin Function Result</h3>



<p>In case of failure, the <code>WP_Error</code> object will return. This way, you can detect failure using the <code>is_wp_error()</code> function of WordPress.</p>



<p>Do NOT use the result of the activation_plugin function solely in a condition because there is no return if the process is successful.</p>



<p>Use <code>is_wp_error( activate_plugin( $plugin ) )</code> to check if there was any problem in the activation process.</p>



<h2 class="wp-block-heading" id="examples">Examples of Activating Plugins in WordPress Programmatically</h2>



<p>I have two examples for you:</p>



<h3 class="wp-block-heading" id="example-1">A basic example of using activate_plugin to activate a plugin in WordPress</h3>



<pre><code class="language-php">//if you try activate_plugin() outside of function.php or activation hooks, you need to include these fule before.
	if ( ! function_exists( 'activate_plugin' ) ) {
		include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
	}

	//you may get error that wp_redirect does not exist (which activate_plugin relies on)
	if ( ! function_exists( 'wp_redirect' ) ) {
		include_once( ABSPATH . 'wp-includes/pluggable.php' );
	}

	//use the relative or full path to the plugin's main php file (not only plugin name!)
	$pluginToActivate = 'my-custom-plugin/my-custom-plugin.php';

	//set the url for redirection (no need to set it if you do not want to redirect)
	//calling activate_plugin() from register_activation_hook of another plugin will not redirect.
	$redirectUrlOnSuccess = site_url( '/my-success-url' );

	//useful for WP multisite. set true if you are using WP multisite (i guess you're not!).
	//if you set true for normal WP, activate_plugin() will not work.
	$networkWide = false;

	//prevents execution of activate_plugin hook for this plugin.
	$silentActivation = false;

	//try to activate the plugin
	$tryToActivate = activate_plugin( $pluginToActivate, $redirectUrlOnSuccess, $networkWide, $silentActivation );

	//catch errors if activation failed
	if ( is_wp_error( $tryToActivate ) ) {
		var_dump( $tryToActivate );
	}</code></pre>



<h3 class="wp-block-heading" id="example-2">Activating another plugin programmatically when activating a plugin in the admin panel</h3>



<p>Scenario: you have two plugins, <code>my-first-plugin</code> and <code>my-second-plugin</code>. You want to <code>activate my-second-plugin</code> when the <code>my-first-plugin</code> is getting activated through the admin panel.</p>



<p>Pu the below codes inside the <code>plugins/my-first-plugin/my-first-plugin.php</code> file (first plugin&#8217;s main file).</p>



<pre><code class="language-php">//my-first-plugin activation callback.
//plugins/my-first-plugin/my-first-plugin.php
function myFirstPluginActivationCallback(){
	
	//activate my-second-plugin 
	$tryToActivate = activate_plugin( 'my-second-plugin/my-second-plugin.php' );

	//catch errors if activation failed
	if ( is_wp_error( $tryToActivate ) ) {
		var_dump( $tryToActivate );
	}
	
}

register_activation_hook( __FILE__, 'myFirstPluginActivationCallback' );</code></pre>



<p>Now, if you activate my-first-plugin inside the WordPress admin panel, the my-second-plugin is getting activated automatically.</p><p>The post <a href="https://mehdinazari.com/activate_plugin-wordpress-function/">How to Programmatically Activate a Plugin in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/activate_plugin-wordpress-function/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Use absint Function in WordPress [7 Examples]</title>
		<link>https://mehdinazari.com/absint-wordpress-function/</link>
					<comments>https://mehdinazari.com/absint-wordpress-function/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Tue, 27 Dec 2022 22:54:11 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress plugin development for beginners]]></category>
		<category><![CDATA[WordPress tutorials for beginners]]></category>
		<guid isPermaLink="false">http://localhost/mehdinazari/?p=2545</guid>

					<description><![CDATA[<p>The absint function in WordPress accepts a number and converts it to a positive integer. This function also converts a float number to a positive integer value. But what is the return if you pass Boolean or Array instead? Find the answer in my 7 examples of using absint() in WordPress development. absint Function Introduction [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/absint-wordpress-function/">How to Use absint Function in WordPress [7 Examples]</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>The absint function in WordPress accepts a number and converts it to a positive integer. This function also converts a float number to a positive integer value. But what is the return if you pass Boolean or Array instead? Find the answer in my 7 examples of using absint() in WordPress development.</p>



<span id="more-2545"></span>



<h2 class="wp-block-heading"><code>absint</code> Function Introduction</h2>



<p>The absint() function in WordPress accepts a number and returns the absolute value for that number. The number can be negative or positive, defined as an integer, float, or string.</p>



<p>There is also the possibility of passing an array, boolean or null to this function. In such cases, <code>absint()</code> somehow manages to return a legitimate value in return (keep reading for the examples).</p>



<h3 class="wp-block-heading">How does the <code>absint</code> function work in WordPress?</h3>



<p>Since WordPress V2.5.0, The <a href="https://developer.wordpress.org/reference/functions/absint/" title="">absint function</a> is declared in <code>wp-includes/function.php</code> file, so it&#8217;s available everywhere when developing the front end or admin panel of WordPress.</p>



<p>This function uses the <a href="https://www.php.net/manual/en/function.abs.php" target="_blank" rel="noopener" title="">PHP <code>abs()</code> function</a> under the hood. But before passing the number to PHP <code>abs()</code>, WordPress <code>absint()</code> converts the given value to an integer.</p>



<p>Because of this conversion, there is no possibility of getting a float value in return. Only returning an Integer is expected from the <code>absint()</code> function.</p>



<p>Another important thing to note is that only the integer part of a giving decimal is considered by <code>absint()</code>. And it does <strong>NOT</strong> round your number to the nearest integer.</p>



<p>For example, -3.99 is treated the same as -3.33; both will be considered -3, the integer part of both decimals.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="576" src="https://mehdinazari.com/wp-content/uploads/2022/12/wordpress-absint-function-1024x576.jpg" alt="WordPress absint function" class="wp-image-6171" srcset="https://mehdinazari.com/wp-content/uploads/2022/12/wordpress-absint-function-1024x576.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2022/12/wordpress-absint-function-300x169.jpg 300w, https://mehdinazari.com/wp-content/uploads/2022/12/wordpress-absint-function-768x432.jpg 768w, https://mehdinazari.com/wp-content/uploads/2022/12/wordpress-absint-function-400x225.jpg 400w, https://mehdinazari.com/wp-content/uploads/2022/12/wordpress-absint-function-800x450.jpg 800w, https://mehdinazari.com/wp-content/uploads/2022/12/wordpress-absint-function.jpg 1280w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">What is the <code>absint</code> function use case in WordPress development?</h3>



<p>If you have a number with the possibility of wrongly being declared negative, it&#8217;s wise to use <code>absint()</code> to ensure it will be positive regardless.</p>



<p>But this function also returns legitimate values if you pass non-integers.</p>



<p>If you know the returning possibilities, you can use the <code>absint()</code> function in other scenarios.</p>



<p>One good thing about using the <code>absint</code> function is that the return value is always an integer.</p>



<p>Also, if your giving data type is String (containing only a number), you do not need to worry about converting it to an actual numerical type before passing it to the function.</p>



<h2 class="wp-block-heading"><code>absint</code> Function Syntax</h2>



<p>The syntax is clear. <code>absint()</code> only accepts one parameter, which can be an integer or not. So they&#8217;ve called it <code>$maybeint</code>, because it may be an integer, or maybe not!</p>



<pre><code class="language-php">absint( mixed&nbsp;$maybeint&nbsp;)</code></pre>



<h2 class="wp-block-heading"><code>absint</code> Function Parameter</h2>



<p><b><code>$maybeint</code></b> <strong>parameter is required</strong> by the <code>absint</code> function to calculate the returning value based on it.</p>



<p>You can pass a negative or positive integer, a negative or positive float, a string containing a number (or not), an array, a boolean, etc.</p>



<p>But maybe, in some cases, the <code>absint()</code> does not return value you expect if you pass non-numerical data types.</p>



<p>Here are the possibilities of return value based on the passed data type:</p>



<h2 class="wp-block-heading"><code>absint</code> Function Result</h2>



<p>If you pass one of the below data types to the <code>absint</code> function, you&#8217;ll get:</p>



<ul class="wp-block-list">
<li><strong>Integer:</strong>
<ul class="wp-block-list">
<li><strong>Positive integer</strong> &nbsp; -&gt; the same passed number.</li>



<li><strong>Negative integer</strong> -&gt; the passed number converted to positive.</li>
</ul>
</li>



<li><strong>Float:</strong> integer part of the passed number (ex: 3 from 3.99), converted to positive if negative.</li>



<li><strong>String</strong>:
<ul class="wp-block-list">
<li><strong>Numerical only string</strong> -&gt; the same as passing integer or float.</li>



<li><strong>Non-Numerical string</strong> -&gt; 0.</li>



<li><strong>String starting with a number</strong> -&gt; the starting number will be used as passed value.</li>



<li><strong>String with number in between characters</strong> -&gt; 0.</li>



<li><strong>Math operation strings</strong> -&gt; not supported, then 0.</li>
</ul>
</li>



<li><strong>Array:</strong>
<ul class="wp-block-list">
<li><strong>Array with elements</strong> -&gt; 1.</li>



<li><strong>Empty array</strong> -&gt; 0.</li>
</ul>
</li>



<li><strong>Boolean:</strong>
<ul class="wp-block-list">
<li><strong>True</strong> -&gt; 1</li>



<li><strong>False</strong> -&gt; 0</li>
</ul>
</li>



<li><strong>Null:</strong> returns 0.</li>



<li><strong>Object</strong>: PHP warning with the text &#8216;Warning: Object of class &#8230;&#8230;.. could not be converted to int&#8217;.</li>
</ul>



<p>I tried passing all these data types to the WordPress <code>absint</code> function and analyzing the return value in each case.</p>



<p>Continue reading for the result I got from each test (I have surprises for you!).</p>



<p>If you want to try the examples yourself, you better create a plugin and copy these PHP codes inside it. Check out my tutorial on <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/" title="">how to create a hello world plugin for WordPress</a>. </p>



<h2 class="wp-block-heading"><code>absint</code> Function Examples in WordPress Development</h2>



<p>Here are seven examples (actually a lot more!) of using <code>absint</code> function in WordPress development, with each data type:</p>



<h3 class="wp-block-heading">Integer value for <code>absint</code> function</h3>



<p>In case of passing a positive integer to WordPress&#8217; <code>absint()</code>, You&#8217;ll get the same integer you passed as a return. But a negative integer will be converted to a positive in return.</p>



<p>So this way <code>absint()</code> enforces integer numbers to be positive regardless of their original definition. Example:</p>



<pre><code class="language-php">//defining a negative integer
$negative = -5;

//defining a positive integer
$positive = 7;

//defining a zero integer
$zero = 0;

//defining a variable based on math operation
$multiply = $negative * $positive;


/*now we check above variables in absint():*/

//prints 5
echo absint($negative) .'&lt;br&gt;';

//prints 7
echo absint($positive) .'&lt;br&gt;';

//prints 0
echo absint($zero) .'&lt;br&gt;';

//prints 35
echo absint($multiply);</code></pre>



<h3 class="wp-block-heading">Float value for <code>absint</code> function</h3>



<p><code>absint()</code> function will convert the given float number to an integer and return it as a non-negative.</p>



<p>The below example is important. Especially because of unexpected behavior <a href="https://developer.wordpress.org/reference/functions/absint/#comment-3310" title="">reported in absint by Joel James</a>.</p>



<pre><code class="language-php">//defining a negative float
$negative = -5.99;

//defining a positive float
$positive = 7.99;

//defining a variable based on math operation
$multiply = $negative * $positive;


/*now we check above variables in absint():*/

//prints 5
//-5 is the integer part of -5.99, then it converts to positive
echo absint($negative) .'&lt;br&gt;';

//prints 7
//7 is the integer part of 7.99
echo absint($positive) .'&lt;br&gt;';

//prints 47
//-5.99 x 7.99 = -47.8601 -&gt; -47 converts to 47
echo absint($multiply).'&lt;br&gt;';

//&#x1f447;
//****unexpected behaviour****//
//reported by Joel James: https://developer.wordpress.org/reference/functions/absint/#comment-3310
//because of percision settings, below example returns 1998 instead of 1999
echo absint(-19.99 * 100);

//&#x1f447;
//But if you increase float data percision, problem will be fixed (if it is a problem for you!)
//example below prints 1999
echo absint(-19.999 * 100);</code></pre>



<p>One thing to remember is that there is no exact 1, 2, 3, 4, &#8230; in float numbers. Instead, there is 1.9999999999999, then it goes to 2.0000000000001 (the &#8216;2&#8217; number is not in between).</p>



<p>Note that the precision needed to go to the next integer differs based on operating systems and PHP settings.</p>



<p>You can try this in below example (it&#8217;s fun :)):</p>



<pre><code class="language-php">//prints 1
echo (int) 1.999.'&lt;br&gt;';

//again prints 1
echo (int) 1.999999.'&lt;br&gt;';

//still prints 1
echo (int) 1.999999999.'&lt;br&gt;';

//now prints 2 (you may need different precision)
echo (int) 1.9999999999999999.'&lt;br&gt;';

//prints 1 again!
echo (int) 1.9999999999999998.'&lt;br&gt;';</code></pre>



<h3 class="wp-block-heading">String value for <code>absint</code> function (This one can be surprising!)</h3>



<p>If the string contains only a number, integer, or float, it will be treated the same as int or float.</p>



<p>But if you pass a character-based string without numbers, <code>absint()</code> will return 0.</p>



<p>What if a number is presented in the string, mixed with non-numerical characters? well&#8230; it depends on the position of that number!</p>



<p>If a number is at the beginning of the passed string (ex: &#8216;-123 text text&#8217;), <code>absint()</code> will consider the starting number as the passed number (in our example, 123 will be returned.</p>



<p>On the other hand, If a number is mixed in between the passed string (ex: &#8216;text -123 text&#8217;), <code>absint()</code> will return 0. same result for a number appending at the end of the string (ex: &#8216;text text -123).</p>



<pre><code class="language-php">//defining a string value
$stringOnly = 'this is a test';

//defining a string value mixed with a number in between
$stringWithNumberInBetween = 'this 123 is a test';

//defining a string value mixed with a number at beginning
$stringWithNumberAtBeginning = '-123 is a test';

//defining a string value mixed with a number at the end
$stringWithNumberAtTheEnd = 'this is a 123';

//defining a string of negative integer
$negativeIntegerString = '-123';

//defining a string of positive integer
$positiveIntegerString = '123';

//defining a string of negative float
$negativeFloatingString = '-5.99';

//defining a string of positive float
$positiveFloatingString = '7.99';

//defining a string containing a math operation
$mathOperationString = '-5 * 7';

//defining a string containing a math operation with Parenthesis
$mathOperationStringWithParenthesis = '(-5 * 7)';


/*now we check above variables in absint():*/

//prints 0
echo absint($stringOnly) . '&lt;br&gt;';

//prints 0
echo absint($stringWithNumberInBetween) . '&lt;br&gt;';

//prints 123
echo absint($stringWithNumberAtBeginning) . '&lt;br&gt;';

//prints 0
echo absint($stringWithNumberAtTheEnd) . '&lt;br&gt;';

//prints 123
echo absint($negativeIntegerString) . '&lt;br&gt;';

//prints 123
echo absint($positiveIntegerString) . '&lt;br&gt;';

//prints 5
echo absint($negativeFloatingString) . '&lt;br&gt;';

//prints 7
echo absint($positiveFloatingString) . '&lt;br&gt;';

//prints 5 (you expected 35, didn't you? &#x1f606;)
//it seems that absint() does not handle math operations inside string!
echo absint($mathOperationString) . '&lt;br&gt;';

//prints 0 (still waiting for 35? &#x1f602;)
//absint() does not handle math operations inside string even with parenthesis (now its 0!)
echo absint($mathOperationStringWithParenthesis) . '&lt;br&gt;';</code></pre>



<h3 class="wp-block-heading">Array value for <code>absint</code> function</h3>



<p>If you pass an array with elements inside it, <code>absint()</code> will return 1. But passing an empty array will get 0 in return. Example:</p>



<pre><code class="language-php">//defining an empty array
$emptyArray = array();

//defining an array containing numbers
//Note it does not matter! I just want to show you.
$arrayOfNumbers = array(-1, 0, 1, 2, 3);

//defining an array containing characters (not different anyway!)
$arrayOfStrings = array('test', 'another test');


/*now we check above variables in absint():*/

//prints 0
echo absint($emptyArray) .'&lt;br&gt;';

//prints 1
echo absint($arrayOfNumbers) .'&lt;br&gt;';

//prints 1
echo absint($arrayOfStrings);</code></pre>



<h3 class="wp-block-heading">Boolean value for <code>absint</code> function</h3>



<pre><code class="language-php">//prints 0
echo absint(false) . '&lt;br&gt;';

//prints 1
echo absint(true);</code></pre>



<h3 class="wp-block-heading">Null value for <code>absint</code> function</h3>



<pre><code class="language-php">//prints 0
echo absint(null);</code></pre>



<h3 class="wp-block-heading">Object value for <code>absint</code> function</h3>



<pre><code class="language-php">//defining the object to be tested if absint()
$object = new stdClass();
$object-&gt;test = -6.99;

//passing the object itself throws PHP warning:
//Warning: Object of class stdChjlass could not be converted to int in ...
echo absint($object);

//note that if you pass test field of $object to absint(), it will not throw warning
//it will be converted to positive integer (6 in this example)
echo absint($object-&gt;test);</code></pre><p>The post <a href="https://mehdinazari.com/absint-wordpress-function/">How to Use absint Function in WordPress [7 Examples]</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/absint-wordpress-function/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>10+ Powerful Tools for WP Developers in the Year 2023!</title>
		<link>https://mehdinazari.com/tools-for-wordpress-developers-designers/</link>
					<comments>https://mehdinazari.com/tools-for-wordpress-developers-designers/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Sat, 24 Dec 2022 22:34:06 +0000</pubDate>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tips]]></category>
		<category><![CDATA[WordPress plugin development for beginners]]></category>
		<category><![CDATA[WordPress tutorials for beginners]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=4853</guid>

					<description><![CDATA[<p>Do you want to be a professional WordPress developer? Prepare yourself with the Top 10 Software to design astonishing WordPress Themes and develop useful plugins. Some of these tools are free to use for developers. Also, This article includes 10+ extra tips for beginner WordPress developers in the end. This article does not contain any [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/tools-for-wordpress-developers-designers/">10+ Powerful Tools for WP Developers in the Year 2023!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Do you want to be a professional WordPress developer? Prepare yourself with the Top 10 Software to design astonishing WordPress Themes and develop useful plugins. Some of these tools are free to use for developers. Also, This article includes 10+ extra tips for beginner WordPress developers in the end.</p>



<span id="more-4853"></span>



<p>This article does not contain any affiliate links. Thus, this is an honest review for my developer friends.</p>



<p>To be clear, I split the tools into two types, coding and UX/UI tools.</p>



<h2 class="wp-block-heading" id="coding-tools"><a href="#coding-tools">Top 6 Coding Tools for WordPress Developers and Designers</a></h2>



<p>Here are the leading six software that can help your coding efficiency and accuracy.</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="800" height="450" src="https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-coding-800x450.jpg" alt="Coding Tools for WordPress" class="wp-image-5166" srcset="https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-coding-800x450.jpg 800w, https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-coding-300x169.jpg 300w, https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-coding-1024x576.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-coding-768x432.jpg 768w, https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-coding-400x225.jpg 400w, https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-coding.jpg 1280w" sizes="auto, (max-width: 800px) 100vw, 800px" /></figure>
</div>


<h3 class="wp-block-heading" id="phpstorm"><a href="#phpstorm">1- PhpStorm: the most helpful tool overall</a></h3>



<p>PhpStorm is an integrated development environment, in short, IDE.</p>



<p>If you are not aware, IDE is software that helps developers code faster and more accurately.</p>



<p>IDE provides an easy-to-use coding environment with shortcuts, auto-complete, etc. Thus, if you want to code faster, you must use an IDE.</p>



<p>I chose PhpStorm, the most popular IDE among PHP developers, for my daily coding.</p>



<p>With a long history of creating IDE, JetBrains, the creator of PhpStorm, is this market leader.</p>



<p>Unfortunately, the PhpStorm awesomeness comes with a price. and it is not that cheap!</p>



<p>The pricing, after 30 days trial, for individuals is $89 in the first year. After that, the price drops to $71 for the second year. Finally, $53 is the price for the third year. Hence, PhpStorm is regarded as a pricey product.</p>



<p>It&#8217;s important to know that JetBrains gives the product with a discount to those who fit into <a href="https://www.jetbrains.com/phpstorm/buy/#discounts?billing=yearly" target="_blank" rel="noreferrer noopener">discount plans</a>. For more details, visit the <a href="https://www.jetbrains.com/phpstorm/buy" target="_blank" rel="noreferrer noopener">Pricing page on the official JetBrain website</a>.</p>



<p>JetBrains knows how many WordPress developers are using the PhpStorm. Hence, they provided a specific WordPress-friendly environment for WP projects. This environment can assist you in <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">developing WordPress plugins</a> and themes faster.</p>



<p>Another awesome thing about PhpStorm is the plugin marketplace section. Marketplace offers you a hand full of plugins that make PHP development faster.</p>



<p>However, for those interested, other options are Visual Studio Code, Eclipse, Apache NetBeans, etc.</p>



<h3 class="wp-block-heading" id="webstorm"><a href="#webstorm">2- WebStorm: JavaScript development environment</a></h3>



<p>WebStorm is another JetBrains product that is useful when coding JavaScript functionalities.</p>



<p>This software is also an IDE. But this one is designed primarily for JavaScript coders.</p>



<p>Because WebStorm offers fewer functionalities than PhpStorm, it has a cheaper price tag.</p>



<p>In the first year, after 30 days trial, pricing for individuals is $59. then the price drops, just like PhpStorm, to $55 for the second year. finally, $41 is the price for the third year.</p>



<p>Like PhpStorm, JetBrains has discount plans for WebStorm too. Those who fit into the <a href="https://www.jetbrains.com/webstorm/buy/#discounts?billing=yearly">discount plans</a> can download WebStorm free or half-priced. For more details about the pricing plan, visit the <a href="https://www.jetbrains.com/webstorm/buy" target="_blank" rel="noreferrer noopener">WebStorm Pricing page on the official JetBrain website</a>.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Note: PhpStorm offers all WebStorm capabilities, PHP assistance, and Database management.</p>
</blockquote>



<p>While creating themes, there are times when UI needs complex JavaScript coding. If you did not buy PHPStorm, WebStorm is your friend.</p>



<p>Especially if you are building a JavaScript library, this IDE can make your job easier. Automating tasks and auto-complete options are parts of the aid you get.</p>



<p>Note that, WebStorm can detect JavaScript functions and objects better than PhpStorm.</p>



<p>Also, the WebStorm marketplace has JavaScript coding plugins to help you enhance efficiency.</p>



<h3 class="wp-block-heading" id="vs-code"><a href="#vs-code">3- Visual Studio Code: the free option for IDE</a></h3>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="384" src="https://mehdinazari.com/wp-content/uploads/2022/12/vs-code-1024x384.jpg" alt="" class="wp-image-6118" srcset="https://mehdinazari.com/wp-content/uploads/2022/12/vs-code-1024x384.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2022/12/vs-code-300x113.jpg 300w, https://mehdinazari.com/wp-content/uploads/2022/12/vs-code-768x288.jpg 768w, https://mehdinazari.com/wp-content/uploads/2022/12/vs-code-800x300.jpg 800w, https://mehdinazari.com/wp-content/uploads/2022/12/vs-code.jpg 1280w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>If you are shocked by JetBrain&#8217;s pricing, consider using Visual Studio Code, in short, VScode.</p>



<p>A free IDE is like a dream in this world of high prices. So, after JetBrains&#8217;s price, you can agree that VSCode is like a steal.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Visual Studio Code software is under Microsoft License. But the <a href="https://github.com/microsoft/vscode" title="">source code is free and available on GitHub</a> under the MIT license.</p>



<p>To use visual studio code for free, you can <a href="https://github.com/VSCodium/vscodium/releases" target="_blank" rel="noopener" title="">download the VSCodium binaries</a> or create a binary version of the source code yourself.</p>
</blockquote>



<p>Visual Studio Code offers the same features as PHPStorm (almost!). But there are differences between them.</p>



<p>First, VSCode is an IDE for many languages like C++, C#, Python, Java, etc. Not only PHP!</p>



<p>On the other hand, PHPStorm is famous for being easy to use with no time spent on configurations.</p>



<p>VSCode can perform better than PHPStorm if you install extensions and spend time making configurations based on your preferences. But it requires knowledge of what you are doing with the IDE.</p>



<h3 class="wp-block-heading" id="postman"><a href="#postman">4- Postman: API design and testing platform</a></h3>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="384" src="https://mehdinazari.com/wp-content/uploads/2022/12/postman-platform-1024x384.jpg" alt="" class="wp-image-6133" srcset="https://mehdinazari.com/wp-content/uploads/2022/12/postman-platform-1024x384.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2022/12/postman-platform-300x113.jpg 300w, https://mehdinazari.com/wp-content/uploads/2022/12/postman-platform-768x288.jpg 768w, https://mehdinazari.com/wp-content/uploads/2022/12/postman-platform-800x300.jpg 800w, https://mehdinazari.com/wp-content/uploads/2022/12/postman-platform.jpg 1280w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p>Postman is a feature-rich and powerful API testing tool I regularly use when creating a REST-based application or website.</p>



<p>This testing tool thought of every possible situation that you may encounter when testing your API endpoints.</p>



<p>Postman supports any authentication methods you may use in an API communication with the server.</p>



<p>To give you full control of the testing flow, Postman provides the ability to write JS scripts to manipulate the process.</p>



<p>Postman is the standard tool for API testing, and many resources are available to find the solution to your issues with the tool.</p>



<h3 class="wp-block-heading" id="chrome-developer-tools"><a href="#chrome-developer-tools">5- Chrome DevTools: built-in chrome tools for developers</a></h3>



<p>Chrome is the most popular browser, with nearly 66% market share. Hence, Chrome Developer Tools is the most popular option for web developers.</p>



<p>The chrome DevTools is a set of useful tools built-in chrome browser when installing it. So, you do not need to install the plugin separately.</p>



<p>To use Chrom DevTools, right-click on the page and select Inspect. This will open up a box on the bottom of your chrome browser window (if you did not change its settings).</p>



<p>Another way to access the DevTools is to press <code>ctrl+shift+i</code> or <code>F12</code> (win), <code>cmd+opt+i</code> or <code>fn+F12</code> (mac) on your keyboard. This will open up your last activated tab on DevTools.</p>



<p>You may want to use <code>ctrl+shift+c</code> (win), <code>cmd+opt+c</code> (mac) to open the Elements tab. or <code>ctrl+shift+j</code> (win), <code>cmd+opt+j</code> (mac) to open the Console tab of the DevTools.</p>



<p>Using the chrome browser&#8217;s menu to open up the DevTools box is also an option. To do this, click on the three vertical dots on the top right of the Chrome window, then hover over More tools. from the submenu, choose Developer Tools.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1024" height="761" src="https://mehdinazari.com/wp-content/uploads/2022/12/chrome-devtools.jpg" alt="" class="wp-image-6114" srcset="https://mehdinazari.com/wp-content/uploads/2022/12/chrome-devtools.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2022/12/chrome-devtools-300x223.jpg 300w, https://mehdinazari.com/wp-content/uploads/2022/12/chrome-devtools-768x571.jpg 768w, https://mehdinazari.com/wp-content/uploads/2022/12/chrome-devtools-25x18.jpg 25w, https://mehdinazari.com/wp-content/uploads/2022/12/chrome-devtools-775x576.jpg 775w, https://mehdinazari.com/wp-content/uploads/2022/12/chrome-devtools-800x595.jpg 800w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Open Chrome DevTools</figcaption></figure>
</div>


<p>From the opened box, you can use the web development features implemented for developers.</p>



<p>In the Elements tab, you can see the website&#8217;s HTML code on the left side and CSS properties on the right.</p>



<p>Each tab in the DevTools box contains a useful feature for developers. as you can see, many tabs are available. And you can add to them by clicking the three vertical dots on the top right side of the DevTools box, then hovering over the <strong>More tools</strong> option.</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="261" src="https://mehdinazari.com/wp-content/uploads/2022/12/chrome-devtools-more-options-1024x261.jpg" alt="" class="wp-image-6116" srcset="https://mehdinazari.com/wp-content/uploads/2022/12/chrome-devtools-more-options-1024x261.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2022/12/chrome-devtools-more-options-300x76.jpg 300w, https://mehdinazari.com/wp-content/uploads/2022/12/chrome-devtools-more-options-768x196.jpg 768w, https://mehdinazari.com/wp-content/uploads/2022/12/chrome-devtools-more-options-1536x391.jpg 1536w, https://mehdinazari.com/wp-content/uploads/2022/12/chrome-devtools-more-options-800x204.jpg 800w, https://mehdinazari.com/wp-content/uploads/2022/12/chrome-devtools-more-options.jpg 1920w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">More tools option in Chrome DevTools</figcaption></figure>
</div>


<p>There is the ability to change the box&#8217;s position in the DevTools panel. To do that, you must click on three vertical dots on the top right corner of the box and use the Dock side options as you desire. </p>



<p>Find <a href="https://developer.chrome.com/docs/devtools/" target="_blank" rel="noopener" title="">more information about Chrome DevTools</a> on the official Chrome website.</p>



<h3 class="wp-block-heading" id="firefox-developer-tools"><a href="#firefox-developer-tools">6- Firefox DevTools: built-in firefox tools for developers</a></h3>



<p>I prefer the firefox developer tools over google chrome. That&#8217;s because of firefox DevTools&#8217; simplicity.</p>



<p>Previously known as firebug (discontinued from firefox v57), the Firefox DevTools has an engaging UI with needed features.</p>



<p>You can access the Firefox DevTools by pressing F12 on the keyboard or right-clicking on the page and selecting <code>Inspect (Q)</code> option from the context menu.</p>



<p>Other options to access Firefox Devtools are pressing the <code>ctrl+shift+i</code> (windows) <code>cmd+opt+i</code> (mac) shortcut on the keyboard or using the top menu to select <code>Tools -&gt; Browser Tools -&gt; Web Developer Tools</code>.</p>



<p>Like the chrome developer tools, the default tab is the Inspector, which shows the HTML codes on the left side and CSS properties on the right.</p>



<p>The UI is completely customizable with mouse clicks and pressing <code>F1</code> on the keyboard for other possible UI improvement options.</p>



<p>More or less, the features of Firefox DevTools are the same as Chrome Developer Tools. But the ease of use in Firefox DevTools is the main reason behind my preference.</p>



<p>Also, when developing a Theme, you must always check all major browsers to find design issues and incompatibilities. So it is important to work with Firefox and Chrome tools simultaneously.</p>



<p>Find <a href="https://firefox-source-docs.mozilla.org/devtools-user/" target="_blank" rel="noopener" title="">more information about Firefox DevTools</a> on the official Firefox website.</p>



<h2 class="wp-block-heading" id="ux-ui-tools"><a href="#ux-ui-tools">Top 4 UX/UI Tools for WordPress Theme Designers</a></h2>



<p>UX/UI designers can empower themself with these four special products of Adobe:</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="800" height="450" src="https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-designing-800x450.jpg" alt="UX UI Tools for WordPress" class="wp-image-5169" srcset="https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-designing-800x450.jpg 800w, https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-designing-300x169.jpg 300w, https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-designing-1024x576.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-designing-768x432.jpg 768w, https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-designing-400x225.jpg 400w, https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-designing.jpg 1280w" sizes="auto, (max-width: 800px) 100vw, 800px" /></figure>
</div>


<h3 class="wp-block-heading" id="adobe-dreamweaver"><a href="#adobe-dreamweaver">1- Adobe Dreamweaver: UI-based website creation tool</a></h3>



<p>With over 25 years of being in the market, <a href="https://www.adobe.com/products/dreamweaver.html" target="_blank" rel="noopener" title="">Dreamweaver</a> is one of the oldest web development software available.</p>



<p>Adobe acquired the owner company of Dreamweaver, Macromedia, in 2005. and since then, Dreamweaver has been a product of Adobe.</p>



<p>Dreamweaver has a set of useful tools for developers who prefer using visual handlers over coding. But PHP, JavaScript, ASP.net, HTML, CSS, and many other languages are still available in Dreamweaver.</p>



<p>I do not use this tool myself, but I know some developers use it and are satisfied with the features.</p>



<p>One of the most useful features of Dreamweaver for web development is that this software has a real-time preview. This feature saves you time because you do not need to switch to another software to check the results.</p>



<p>Dreamweaver, like other Adobe software, is not free. The subscription price for this tool is $20.99 per month if you want an annual subscription (paid monthly). It hikes to $31.49 per month if you need it for less than a year. And $35.99 per month for businesses.</p>



<p>You can also get the Dreamweaver as an <a href="https://www.adobe.com/creativecloud/plans.html" target="_blank" rel="noopener" title="">Adobe Creative Cloud subscription</a> which costs $59.99 monthly for over 20 adobe apps.</p>



<h3 class="wp-block-heading" id="adobe-xd"><a href="#adobe-xd">2- Adobe XD: rapid prototyping tool for designers</a></h3>



<p><a href="https://www.adobe.com/products/xd/" target="_blank" rel="noopener" title="">Adobe XD app</a> helps you to preview your work for customers and team members as fast as possible.</p>



<p>For example, displaying the user&#8217;s interaction with your design is possible with Adobe XD before the actual product is available.</p>



<p>This is a good tool for website or mobile application development teams, especially when the designer wants to specify the user interactions with the design elements for the coder.</p>



<p>This way, the coder will have a much better understanding of user experience before coding the actions and elements.</p>



<p>The price to get the Adobe XD is $9.99 per month for individuals if prepaid for an annual subscription. This product is also a part of the Adobe Creative Cloud subscription.</p>



<h3 class="wp-block-heading" id="adobe-photoshop"><a href="#adobe-photoshop">3- Adobe Photoshop: powerful photo editor</a></h3>



<p><a href="https://www.adobe.com/products/photoshop.html" target="_blank" rel="noopener" title="">Photoshop</a> is Adobe&#8217;s most known software among people, Not just photographers or designers.</p>



<p>Adobe Photoshop has a set of features that is useful for graphic and web designs as well as photo editing and retouching.</p>



<p>Images are one of the main elements on every web page. And editing images in photoshop is easy and fun.</p>



<p>So if you are a web designer and do not know how to work with photoshop, you better start now! This software also has useful features that can help you preview your design before making it a reality.</p>



<p>The stand-alone Photoshop app pricing plan for individuals is $20.99 monthly (annual subscription, paid monthly). But if you get the <a href="https://www.adobe.com/creativecloud/photography.html" target="_blank" rel="noopener" title="">Photography subscription</a>, it costs $9.99 per month! (it&#8217;s a crazy way of pricing, right?). A Photography subscription also includes the <a href="https://www.adobe.com/products/photoshop-lightroom.html" target="_blank" rel="noopener" title="">Adobe Lightroom</a> app.</p>



<p>Adobe Photoshop is also a part of the Adobe Creative Cloud subscription.</p>



<h3 class="wp-block-heading" id="adobe-illustrator"><a href="#adobe-illustrator">4- Adobe Illustrator: vector designing and illustrations</a></h3>



<p><a href="https://www.adobe.com/products/illustrator.html" target="_blank" rel="noopener" title="">Illustrator</a> is the most useful Adobe app for web designers.</p>



<p>Adobe Illustrator is used widely in the industry as a tool for creating vectors, icons, and even characters of a custom font!</p>



<p>This software has the ability to save graphic elements in SVG format, which is widely used in web development these days.</p>



<p>Learning Adobe Illustrator can empower your web design skills and also makes a bridge for you to other graphic fields like animation and font design.</p>



<p>Illustrator&#8217;s pricing starts at $20.99 monthly for individuals in an annual subscription (paid monthly). If you prepay for the whole year, it will get to $19.99 monthly ($239.88 in total payment). </p>



<p>With a subscription, You&#8217;ll get the illustrator app for Desktop and iPad + 100G cloud storage to save your work.</p>



<p>Like the other 3 in the list, Adobe Illustrator is also included in the Adobe Creative Cloud subscription.</p>



<h2 class="wp-block-heading" id="tips"><a href="#tips">10 Extra tips for those who want to choose tools for web development and designing</a></h2>



<p>Now that you made it down here continue reading for ten extra tips to select the best tool for your job.</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="800" height="450" src="https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-tips-800x450.jpg" alt="Selecting The Best Tool for WordPress" class="wp-image-5174" srcset="https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-tips-800x450.jpg 800w, https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-tips-300x169.jpg 300w, https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-tips-1024x576.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-tips-768x432.jpg 768w, https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-tips-400x225.jpg 400w, https://mehdinazari.com/wp-content/uploads/2022/10/top-tools-tips.jpg 1280w" sizes="auto, (max-width: 800px) 100vw, 800px" /></figure>
</div>


<ol class="wp-block-list">
<li>Compare the pricing, but higher prices always do not mean more features</li>



<li>Free options attract developers, so it means a crowded community to support you and answer your questions</li>



<li>Adobe creative cloud subscription is more suitable than a license per Adobe apps</li>



<li>A free trial is essential if you are using premium software for the first time</li>



<li>Black Friday is the best time to purchase subscriptions for any tools</li>



<li>Good tools can save you time, which means more money</li>



<li>Read the copyright policy of software and tools carefully</li>



<li>Stay updated; new products coming to market every year</li>



<li>Search Youtube for software reviews</li>



<li>Check if additional plugins are available for your selected tool or not</li>
</ol><p>The post <a href="https://mehdinazari.com/tools-for-wordpress-developers-designers/">10+ Powerful Tools for WP Developers in the Year 2023!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/tools-for-wordpress-developers-designers/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WordPress vs. Laravel: The Most Promising in the Year 2023!</title>
		<link>https://mehdinazari.com/wordpress-laravel-compare-2023/</link>
					<comments>https://mehdinazari.com/wordpress-laravel-compare-2023/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Wed, 19 Oct 2022 07:28:37 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Facts]]></category>
		<category><![CDATA[WordPress Tips]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=4747</guid>

					<description><![CDATA[<p>Are you choosing between WordPress and Laravel for your following website? Read this in-depth article to understand the difference between WordPress and Laravel. This article includes WP and Laravel statistics, use cases, predictions, other competitors, and much more! With the year 2023 getting closer and closer, many developers are wondering about the state of web [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/wordpress-laravel-compare-2023/">WordPress vs. Laravel: The Most Promising in the Year 2023!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Are you choosing between WordPress and Laravel for your following website? Read this in-depth article to understand the difference between WordPress and Laravel. This article includes WP and Laravel statistics, use cases, predictions, other competitors, and much more!</p>



<span id="more-4747"></span>



<p>With the year 2023 getting closer and closer, many developers are wondering about the state of web frameworks for the following year.</p>



<p>The two giants in the war of PHP frameworks, WordPress and Laravel, are the main focus regarding comparison.</p>



<p>What is the outcome of this war in 2023? Will we see one of them lose, or will new competitors join the fight in the end?</p>



<p>That&#8217;s what I&#8217;m going to review in this article.</p>



<p>But do not think of me as a biased WordPress developer because I love Laravel and have used it in many projects.</p>



<p>I love Laravel as much as WordPress, if not more. But today, I&#8217;m going to review both of these friends of mine to see which one is more useful in 2023.</p>



<h2 class="wp-block-heading" id="wordpress-laravel-uses"><a href="#wordpress-laravel-uses">When to Use WordPress and Laravel in your Web Development Projects?</a></h2>



<p>WordPress CMS is simple, and it has an admin panel. Besides, thousands of plugins and themes are ready to install with a single click.</p>



<p>On the other hand, Laravel is better structured for developers. Also, It does not limit you in any way and has a massive community of helpful developers ready to help beginners.</p>



<p>From my point of view, If you want an effortless website ready to go, you better choose WordPress.</p>



<p>But, If you have the time and knowledge to develop a feature-rich website, Laravel can utilize you.</p>



<p>To sum up, when you want just a blog or a simple website, do not waste your time with Laravel. Choose WordPress for its cost efficiency.</p>



<p>On the contrary, when you have too many features in your plan, do not limit your abilities with WordPress. Choose Laravel because of its scalable structure.</p>



<h2 class="wp-block-heading" id="wordpress-state-2023"><a href="#wordpress-state-2023">The State of WordPress CMS in 2023</a></h2>



<p>I started using WordPress for my websites in 2009 after losing belief in Joomla! CMS.</p>



<p>What is a CMS? It stands for <strong>Content Management System</strong>. in other words, CMS is a web-based software that controls a website&#8217;s content.</p>



<p>With this definition, WordPress is created for content managers to write and modify articles and other types of content.</p>



<p>Yet, WordPress has a great set of useful functions that can help developers to build any type of website they want, related or unrelated to content.</p>



<p>So, you can create a feature-rich website or web application using WordPress, even if it was initially a blogging platform.</p>



<p>Considering a WordPress website&#8217;s simplicity and cost efficiency, it&#8217;s no wonder this platform powers more than 43% of the global web today (<a href="https://w3techs.com/technologies/details/cm-wordpress" target="_blank" rel="noreferrer noopener">64.3% of websites with a CMS</a>).</p>



<p>Also, over 70,000 plugins are ready to install on WordPress with a single click. This enormous directory enables you to create an innovative website as fast as possible.</p>



<p>Moreover, WordPress has nearly 10,000 themes provided by creative designers in the wordpress.org directory until the last days of the year 2022.</p>



<p>It&#8217;s important to know there are over 60,000 themes available for free download or purchase in all directories.</p>



<p>With this in mind, we can guess that WordPress will still be super popular next year too.</p>


<figure class="wp-block-image"><img loading="lazy" decoding="async" class="wp-image-5189" src="https://mehdinazari.com/wp-content/uploads/2022/10/infographic-wordprss-winter-800x1875.jpg" sizes="auto, (max-width: 800px) 100vw, 800px" srcset="https://mehdinazari.com/wp-content/uploads/2022/10/infographic-wordprss-winter-800x1875.jpg 800w, https://mehdinazari.com/wp-content/uploads/2022/10/infographic-wordprss-winter-437x1024.jpg 300w" alt="WordPress Statistics in Winter 2022 Infographic" width="800" height="1875" /></figure>


<h3 class="wp-block-heading" id="wordpress-priorities-2023"><a href="#wordpress-priorities-2023">What are the priorities of the WordPress development team for the year 2023?</a></h3>



<p>In summary, the WordPress development team focused on implementing effortless visual tools, improving agility, encouraging creativity by pushing boundaries, and increasing security.</p>



<p>To get more information about WordPress&#8217;s development ideology, I recommend watching this awesome video on youtube:</p>



<p><a href="https://www.youtube.com/watch?v=Yg6TySdbnmI" target="_blank" rel="noreferrer noopener">Matt Mullenweg on How WordPress Continues to Thrive</a></p>



<p>In this video, Matt Mullenweg, founder of WordPress, talks on the &#8220;<a href="https://twit.tv/shows/this-week-in-google" target="_blank" rel="noreferrer noopener">This Week in Google</a>&#8221; podcast about WordPress visionaries and other subjects unrelated to WP.</p>



<p>So, before watching the video (If you did not already!), let&#8217;s review WordPress priorities for 2023 with details:</p>



<h4 class="wp-block-heading" id="wordpress-priorities-1"><a href="#wordpress-priorities-1">1- Implementing easy to use web design interface with visual blocks, handlers, and drag &amp; drop ability</a></h4>



<p>The WordPress development team and the CEO, <a href="https://ma.tt/" target="_blank" rel="noreferrer noopener">Matt Mullenweg</a>, are focused on implementing an effortless visual builder for the platform.</p>



<p>Considering the popularity of the Elementor plugin, you can guess WordPress itself lacks a helpful tool for creating a customized page using visual handlers.</p>



<p>Still, we can credit the WordPress developers for introducing Gutenburg, a block-based editor that can help you create pages in a more manageable approach.</p>



<p>Yet, a WordPress admin will feel limited when using WordPress&#8217;s page editor with zero coding knowledge.</p>



<p>To overcome this, Matt Mullenweg suggested revising how WordPress&#8217;s default page builder works for future updates.</p>



<h4 class="wp-block-heading" id="wordpress-priorities-2"><a href="#wordpress-priorities-2">2- Improving agility by providing more ready-to-use functionalities</a></h4>



<p>It&#8217;s noticeable that WordPress developers are concerned about the agility of creating a website and being ready for competition without wasting time on development.</p>



<p>They created <a href="https://wpvip.com/" target="_blank" rel="noreferrer noopener">WPVIP</a>, a premium CMS for enterprises based on open-source WordPress.</p>



<p>While WordPress is easy to install and ready to use, It looks simple after a fresh installation.</p>



<p>As a matter of fact, after installation, a WordPress developer must add essential plugins, design a theme, and do the SEO configuration.</p>



<p>Now you can guess why a WP website takes more time than expected by clients.</p>



<p>The WordPress development team constantly works on ready-to-use features. For this reason, I guess there will be many more features after an installation next year.</p>



<h4 class="wp-block-heading" id="wordpress-priorities-3"><a href="#wordpress-priorities-3">3- Increasing security by implementing website protection features, releasing security patches, and forcing older version updates</a></h4>



<p>WordPress is an open-source platform, which makes it vulnerable. So, security updates are super crucial for such a system.</p>



<p>Hackers can do the same as long as developers can read WordPress core codes.</p>



<p>A developer reads the codes to implement new features, and a hacker reads them to find vulnerabilities.</p>



<p>WordPress, like other open-source platforms, had security issues fixed after platform updates. I can imagine there are more vulnerabilities available to use by hackers right now. </p>



<p>Also, Keep this in mind, with this CMS getting bigger and bigger, maintaining security will be much more challenging for the development team.</p>



<p>As a result, I guess I will receive security updates every once in a while, like in previous versions of WordPress.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Note: remember not to miss any WordPress updates. Equally important, update WP plugins as soon as possible. For the last tip, make sure automatic update feature is enabled on your website.</p></blockquote>



<h3 class="wp-block-heading" id="wordpress-prediction"><a href="#wordpress-prediction">What I predict for WordPress CMS in the year 2023</a></h3>



<p>Now with WordPress stats and development priorities in mind, I can state that WordPress is not standing any competition in the CMS war.</p>



<p>No other platform is that widely used, and no other competitors are this simple and popular at the same time.</p>



<p>But there are storms nearby, and WordPress developers must be ready to protect what they&#8217;ve built against it.</p>



<p>Cost efficiency comes with simplicity. On the other hand, agility requires more complexity. So I can guess this paradox will be a challenge for the WordPress development team in 2023.</p>



<p>I guess WordPress will still thrive in the CMS market. And we can expect to see WordPress taking bigger bites of the CMS market cake.</p>



<p>But in the whole global web market, considering frameworks like PHP Laravel, Javascript Node.js, Python Django, and JAVA Spring, I guess WordPress can lose a little bit of its share.</p>



<p>Smaller websites are using WordPress because of its simplicity and cost efficiency. But bigger fishes in the pond need much more utilization and scalability.</p>



<p>Thus, in the 100,000 top websites of the web, we can see a drop in interest for WordPress. In my opinion, this drop will continue in 2023.</p>



<h3 class="wp-block-heading" id="wordpress-pros"><a href="#wordpress-pros">WordPress pros</a></h3>



<ol class="wp-block-list"><li>WP is easy to install</li><li>Developers love WordPress</li><li>It has a painless admin interface</li><li>It provides default themes (but simple!)</li><li>It survived many winters and delivered stability</li><li>It has a vast directory of free and premium plugins and themes</li><li>and much more!</li></ol>



<h3 class="wp-block-heading" id="wordpress-cons"><a href="#wordpress-cons">WordPress cons</a></h3>



<ol class="wp-block-list"><li>WP standard development approach is not following the popular MVC</li><li>WordPress is not scalable as much as other frameworks like Laravel</li><li>WP has security risks due to encouraging third-party plugins</li><li>It lacks an effortless default page builder in the editor</li><li>Not all enterprises favorite WP as the CMS</li><li>WP is not that agile for enterprises</li></ol>



<h2 class="wp-block-heading" id="laravel-state-2023"><a href="#laravel-state-2023">The State of Laravel PHP Framework in 2023</a></h2>



<p>My history with the Laravel framework started in 2014.</p>



<p>Since then, I&#8217;ve used this framework in almost all of my web applications, except for websites &amp; blogs.</p>



<p>Why not websites and blogs? Because of WordPress&#8217;s rapid prototyping and its cost efficiency in small projects.</p>



<p>I think Laravel is the better option for implementing more complicated functionalities.</p>



<p>For example, I&#8217;ve successfully used Laravel as the central part of CRMs, Data Analysis, Reporting Dashboards, Financial Management Systems, and other feature-rich web applications.</p>



<p>Eather if Laravel was handling the UI or I used it as the API for dynamic UI frameworks, It worked as expected.</p>



<p>If it weren&#8217;t for Laravel, some of these projects would take much longer to complete. That means I would be a rich freelancer with unhappy clients if Laravel did not exist.</p>



<p>Laravel is still pushing forward by releasing newer versions, and some of the introduced features are still exciting.</p>



<p>Not to mention, upgrading an older version of Laravel is not a brainers.</p>



<p>The latest version of Laravel is v9, and the Laravel team will release version 10 is next year in the middle of spring.</p>



<p>The current market share for Laravel is around 8% in the last days of 2022, but the growth history promises more for the following year.</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" class="wp-image-5189" src="https://mehdinazari.com/wp-content/uploads/2022/10/infographic-laravel-winter-800x1688.jpg" sizes="auto, (max-width: 800px) 100vw, 800px" srcset="https://mehdinazari.com/wp-content/uploads/2022/10/infographic-laravel-winter-800x1688.jpg 800w, https://mehdinazari.com/wp-content/uploads/2022/10/infographic-laravel-winter-485x1024.jpg 300w" alt="Laravel Statistics in Winter 2022 Infographic" width="800" height="1688" /></figure>



<h3 class="wp-block-heading" id="why-laravel-is-amazing"><a href="#why-laravel-is-amazing">What makes Laravel a fantastic framework for web developers?</a></h3>



<p>First, the way you code in Laravel is much cleaner, rememberable, and understandable for teammates.</p>



<p>With the decoupling coding structure that Laravel provides, you can categorize your codes into different files and directories.</p>



<p>This way, you can always find what you need without scrolling through thousands of lines.</p>



<p>Second, this framework helps you connect with other developers to share codes and experiences. This feature promises a helpful community to grow among professionals.</p>



<p>When the community members help each other, projects get done rapidly, and issues vanish with just a google search.</p>



<p>Last but not least, Laravel handles the repeating functionalities of any project quickly.</p>



<p>For example, user authentication is a breeze in the Laravel development process.</p>



<p>This way, instead of spending time on recurring functionalities, you can focus on essential parts of your project.</p>



<h3 class="wp-block-heading" id="laravel-priorities"><a href="#laravel-priorities">What are the priorities of the Laravel development team for the year 2023?</a></h3>



<p>Considering the market share of around 8%, Laravel still has a long road to conquer territories of other frameworks. But it&#8217;s the goal of this fantastic developer-friendly framework.</p>



<p>I expect that in 2023, we&#8217;ll hear much more from the Laravel developer team&#8217;s accomplishments.</p>



<p>Here are the priorities of the Laravel development team for the year 2023:</p>



<h4 class="wp-block-heading" id="laravel-priorities-1"><a href="#laravel-priorities-1">1- Laravel 10, the foremost two-digits version of Laravel</a></h4>



<p>Laravel 10 is still under development today. As I mentioned, the Laravel team will release the v10 in February 2023.</p>



<p>Laravel 10 will be the main branch of the framework until August 2024. And it will receive security updates two years after the initial release of this version.</p>



<p>It&#8217;s important to mention that the Laravel team set February 2024 as the end-of-life date for version 9.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Note: January 2023 will be the Laravel 8 end of life date. Thus, if you are still using Laravel 8, and you are concerned about security, you must upgrade it quickly.</p></blockquote>



<p>Will the next version of the Laravel framework introduce a new cornerstone feature? Because of the almost perfect structure of the framework and what it has accomplished until today, I&#8217;m not that positive about that. But there is still a chance to experience significant changes in the framework&#8217;s next release.</p>



<p>Laravel 10 will require PHP 8 or higher to run, just like Laravel 9. But it&#8217;s set to drop PHP 8.0 in the Laravel 10 and rely on PHP 8.1 entirely.</p>



<p>According to <a href="https://github.com/laravel/framework/pulls/" target="_blank" rel="noreferrer noopener">Laravel&#8217;s GitHub pull requests</a>, version 10 will adapt more with PHP type declaration and other server-side technology updates.</p>



<h4 class="wp-block-heading" id="laravel-priorities-2"><a href="#laravel-priorities-2">2- Introducing more out-of-box functionalities to help developers get the job done faster</a></h4>



<p>Laravel makes the developer&#8217;s jobs more manageable; it has been the primary goal of Laravel development since the first initial release.</p>



<p>In almost all updates, the Laravel team replaced a few repeated codings with default options to make it faster for developers to implement functionalities.</p>



<p>As I witnessed in Laravel&#8217;s GitHub, the tradition is honored by making path parameters<a href="https://github.com/laravel/framework/pull/44395" target="_blank" rel="noreferrer noopener"> optional in Filesystem methods</a>.</p>



<p>From a developer&#8217;s point of view, It&#8217;s satisfying when you only focus on functionalities, not minor details, while implementing them.</p>



<p>I predict Laravel 10 will have much more to offer to make coding faster and more efficient. After all, we&#8217;re using frameworks to save time.</p>



<h4 class="wp-block-heading" id="laravel-priorities-3"><a href="#laravel-priorities-3">3- Implementing cleaner code structures and decoupling functionalities</a></h4>



<p>Professional developers always simplify classes and methods and decouple their codes to make them reusable. It&#8217;s a part of the <a href="https://en.wikipedia.org/wiki/SOLID" target="_blank" rel="noreferrer noopener">coding principles we know as SOLID</a>.</p>



<p>Not to mention, Laravel has a perfect coding structure that makes this framework perfect for attracting community-lover developers.</p>



<p>With a clean code base, Laravel developer can share their experience and make other developers&#8217; jobs easier.</p>



<p>As I mentioned, the purpose of using a framework is to save time. Therefore, sharing codes honor its spirit.</p>



<h4 class="wp-block-heading" id="laravel-priorities-4"><a href="#laravel-priorities-4">4- Providing security updates for previous releases</a></h4>



<p>Laravel 8 will stop receiving security updates from the 24th of January, 2023. But the Laravel team will still provide security updates for Laravel 9 until February 2024.</p>



<p>Thus, we will see a few updates in 2023 for Laravel v9 centered around security issues. Also, we can expect bug-fixing releases for this version until August 2023.</p>



<h4 class="wp-block-heading" id="laravel-priorities-5"><a href="#laravel-priorities-5">5- Energizing the Laravel community to stay fateful</a></h4>



<p>Laravel successfully attracted a large community of developers worldwide. Therefore Laravel&#8217;s team&#8217;s responsibility is to energize this community to stay there. And also attract more developers to make the community even more extensive.</p>



<p>I expect Laravel&#8217;s founders to manage news attracting official conferences in 2023 (Laracon).</p>



<p>For Indian developer friends, there is a <a href="https://laracon.in" target="_blank" rel="noreferrer noopener">Laracon event scheduled for 25-26 February 2023</a> at Ahmedabad, Gujrat (Unfortunately, I&#8217;m not an Indian, but I love you guys).</p>



<h3 class="wp-block-heading" id="laravel-prediction"><a href="#laravel-prediction">What I predict for Laravel Framework in the year 2023</a></h3>



<p>As the perfect PHP framework for many web projects, Laravel is so damn popular among developers.</p>



<p>If the Laravel development team becomes better at advertising the framework, I predict a larger market share for Laravel in 2023.</p>



<p>Why would anybody use other frameworks while Laravel does the job much faster and more securely? The answer is the advertisement of different frameworks.</p>



<p>As can be seen, Laravel needs more news attention and cornerstone features.</p>



<p>One of the primary issues with Laravel is that the framework lacks an easy-to-install user interface like WordPress offers. As a result, it will repel beginners or users with zero knowledge of web development.</p>



<p>What if non-developer users of the web could use Laravel? They could potentially become a developer at the end when they need to implement custom features.</p>



<p>It is not one of the developer team&#8217;s concerns right now. But in 2023, attracting non-developers can be the game changer for the Laravel framework.</p>



<h3 class="wp-block-heading" id="laravel-pros"><a href="#laravel-pros">Laravel pros</a></h3>



<ol class="wp-block-list"><li>Laravel&#8217;s decoupled structure makes it easier for developer team members to focus on their jobs without concern</li><li>Laravel framework makes coding faster by providing default values for recurring parameter initiations</li><li>Managing database functions using Laravel&#8217;s Eloquent is satisfying for developers</li><li>Thousand of packages are ready to include in development using composer</li><li>Laravel framework constantly adapts to the latest technologies of the web</li><li>The large community of Laravel developers is heartwarming</li><li>and much more!</li></ol>



<h3 class="wp-block-heading" id="laravel-cons"><a href="#laravel-cons">Laravel cons</a></h3>



<ol class="wp-block-list"><li>Laravel is concerned about developers and neglects users with zero web development knowledge.</li><li>The Laravel development team stops updating previous releases of the framework after 2-3 years.</li><li>It&#8217;s challenging for beginner developers to develop web applications using Laravel</li><li>Learning to develop the Laravel framework requires time and effort.</li></ol>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://mehdinazari.com/wp-content/uploads/2022/10/wordpress-laravel-compatitors-800x450.jpg" alt="WordPress and Laravel Compatitors"/></figure>
</div>


<h2 class="wp-block-heading" id="other-competitors"><a href="#other-competitors">Will Other Competitors Surprise WordPress and Laravel to Take a Big Bite of Market Share?</a></h2>



<p>I do not see this happening in 2023, at least in the PHP language. Yet, Considering the growth history of Node.js projects, the JavaScript world shows that it can be surprising anytime.</p>



<p>It&#8217;s important to mention, <a href="https://w3techs.com/technologies/details/pl-java" target="_blank" rel="noreferrer noopener">according to w3techs</a>, JAVA usage in server-side is surprisingly increased in 2022.</p>



<h3 class="wp-block-heading" id="wordpress-competitors"><a href="#wordpress-competitors">Who are the direct competitors to WordPress CMS right now?</a></h3>



<p>WordPress&#8217;s market share is enormous, but competitors are still alive.</p>



<p>Between frameworks, there are a bunch of CMSes that compete with WordPress right now:</p>



<ul class="wp-block-list"><li>Joomla!</li><li>Drupal</li><li>Magento (e-commerce)</li><li>Prestashop (e-commerce)</li><li>Shopify (Not open source)</li><li>Squarespace (Not open source)</li><li>WIX (Not open source)</li><li>Weebly (Not open source)</li><li>Ghost (JavaScript)</li></ul>



<h3 class="wp-block-heading" id="laravel-competitors"><a href="#laravel-competitors">Who are the direct competitors to Laravel Framework right now?</a></h3>



<p>Laravel is a backend framework with many competitors in different languages. Some of them are:</p>



<ul class="wp-block-list"><li>Symphony</li><li>CodeIgniter</li><li>Zend</li><li>CakePHP</li><li>Yii 2</li><li>Aura</li><li>Slim</li><li>Phalcon</li><li>Fuel PHP</li><li>FatFree</li><li>Django (Python)</li><li>Spring (JAVA)</li><li>Next.js (JavaScript)</li><li>Meteor (JavaScript)</li></ul>



<h3 class="wp-block-heading" id="reason-to-believe-competitors"><a href="#reason-to-believe-competitors">Is there a reason to believe in other competitors?</a></h3>



<p>In the PHP world, I must say NO!</p>



<p>But in other languages, due to differences in processing performances, there can be reasons to believe in the competitors.</p>



<p>For example, if we consider JavaScript&#8217;s ability to process functions Asynchronously, We can believe in a bright future for JavaScript platforms.</p>



<p>Same for JAVA, when we consider the user-friendliness of JAVA syntax, besides asynchronous processing, we can believe JAVA can be surprising regarding web development.</p>



<h3 class="wp-block-heading" id="safer-bet"><a href="#safer-bet">In case of a new competitor attacking the market, which one is a safer bet, WordPress or Laravel?</a></h3>



<p>I believe the tree with deeper roots is safer in storms.</p>



<p>I am considering the initial release date, market share, available plugins, community, etc. WordPress is the safer bet for developers who do not want to take the risk.</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://mehdinazari.com/wp-content/uploads/2022/10/wordpress-vs-laravel-2-800x450.jpg" alt="WordPress vs Laravel Fight"/></figure>
</div>


<h2 class="wp-block-heading" id="conclusion"><a href="#conclusion">Conclusion: the Summary of Comparing WordPress vs. Laravel for the Year 2023</a></h2>



<p>WordPress and Laravel are not direct competitors due to differences in functionality. Yet, they will clash with each other at some points.</p>



<p>Even though WordPress CMS is a PHP framework, considering the user interface and default database structure, It&#8217;s a CMS. In comparison, Laravel is only a PHP framework that can build a CMS.</p>



<p>WordPress will still be the best CMS out there in 2023. Yet, the platform needs a much better visual editor to compete with WIX, Weebly, and Squarespace and not lose market share.</p>



<p>To compete with Laravel as a PHP framework, WordPress needs a better developer-friendly structure, maybe MVC or other options.</p>



<p>On the other hand, Laravel needs a user interface and a better installation approach to compete with WordPress.</p>



<p>Also, to compete with other PHP frameworks for market share, Laravels needs more public events and not just implementing out-of-box features.</p>



<p>As a developer, if you want just a simple website, choose WordPress because of its cost-efficiency.<br />But if publishing a feature-rich website or web software is what you&#8217;ve planned, you better choose Laravel for that project.</p><p>The post <a href="https://mehdinazari.com/wordpress-laravel-compare-2023/">WordPress vs. Laravel: The Most Promising in the Year 2023!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/wordpress-laravel-compare-2023/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Extend WordPress Posts Query and Join New Tables</title>
		<link>https://mehdinazari.com/join-custom-tables-with-wordpress-posts-query/</link>
					<comments>https://mehdinazari.com/join-custom-tables-with-wordpress-posts-query/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Sat, 10 Sep 2022 05:49:30 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<category><![CDATA[Advanced WordPress Tutorials]]></category>
		<category><![CDATA[Extend WordPress Functionalities]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=327</guid>

					<description><![CDATA[<p>Learn Extending Posts Query in WP, Join Custom Tables and add new fields to Post Items In this advanced WordPress Development tutorial.</p>
<p>The post <a href="https://mehdinazari.com/join-custom-tables-with-wordpress-posts-query/">How to Extend WordPress Posts Query and Join New Tables</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Learn Extending Posts Query in WP, Join Custom Tables and add new fields to Post Items In this advanced WordPress Development tutorial. I&#8217;ll explain how to include data from Custom Tables into the MySQL query of WP Posts. For a practical example, We&#8217;ll try adding post views counter from a custom-made database table for visits to the WP default Posts Query.</p>



<span id="more-327"></span>



<p>Read this WordPress <strong>tutorial for experienced developers</strong> if you want to <strong>learn how to join data from a table that does not exist in the WP</strong> default database <strong>with posts query</strong>.</p>



<p>It&#8217;s a <strong>long article</strong> with <strong>four chapters</strong> covering all information about the Posts Query topic.</p>



<h2 class="toc-hidden wp-block-heading" id="roadmap"><a href="#roadmap"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f3af.png" alt="🎯" class="wp-smiley" style="height: 1em; max-height: 1em;" />Tutorial Roadmap:</strong> Head Straight to the Point!</a></h2>



<p>Here is the table of content; select a topic<strong> to begin</strong> with, while you can <strong>keep scrolling for the beginner&#8217;s starting point</strong>.</p>



<ul class="wp-block-list">
<li><a href="#chapter-1"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f947.png" alt="🥇" class="wp-smiley" style="height: 1em; max-height: 1em;" />Chapter 1:</strong> WP Way of Handling Post Storage in Database</a></li>



<li><a href="#chapter-2"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f948.png" alt="🥈" class="wp-smiley" style="height: 1em; max-height: 1em;" />Chapter 2: </strong>Extend and Modify Posts Query in WordPress</a></li>



<li><a href="#chapter-3"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f949.png" alt="🥉" class="wp-smiley" style="height: 1em; max-height: 1em;" />Chapter 3:</strong> Build a Post View Counter by Extending Posts Query</a></li>



<li><a href="#chapter-4"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f3c5.png" alt="🏅" class="wp-smiley" style="height: 1em; max-height: 1em;" />Chapter 4:</strong> Tips for Extending WordPress Posts Query</a></li>



<li><a href="#final-chapter"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f3c6.png" alt="🏆" class="wp-smiley" style="height: 1em; max-height: 1em;" />Final Chapter:</strong> Resources to Learn about the Posts Query</a></li>
</ul>



<h2 class="wp-block-heading" id="chapter-1"><a href="#chapter-1"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f947.png" alt="🥇" class="wp-smiley" style="height: 1em; max-height: 1em;" />Chapter 1:</strong> How does WordPress Store the Data for each Post in the Database?</a></h2>



<p><strong>Despite</strong> the fact that <strong>you can create your own tables</strong>, The <strong>WP development team planned</strong> a database <strong>table structure</strong> to store data <strong>for all the possible scenarios</strong>.</p>



<p>As you can witness on the database, WordPress has a <strong><code>posts</code> table that contains essential information</strong> about each post.</p>



<p>As well as a <strong><code>postmeta</code> table to store extra related information</strong>.</p>



<h3 class="wp-block-heading" id="chapter-1-part-1"><a href="#chapter-1-part-1"><strong>Part 1:</strong> WordPress table structure for post entity and post meta data</a></h3>



<p>WordPress has a <strong>main table to store post entities</strong> and <strong>another to store the related metadata</strong>.</p>



<p><code>posts</code> table (<code>wp_posts</code> with default prefix) is the main table of post entities in the WordPress database.</p>



<p><code>postmeta</code> table (<code>wp_postmeta</code> with default prefix) is the storage for the metadata related to posts.</p>



<p>What can&#8217;t store in the <code>posts</code> table, will store in <code>postmeta</code> table.</p>



<p>By &#8220;can&#8217;t be stored in the <code>posts</code> table&#8221; I meant we do not have columns for it on the <code>post</code> table.</p>



<h4 class="wp-block-heading" id="chapter-1-part-1-posts"><a href="#chapter-1-part-1-posts"><strong>Table #1:</strong> <code>posts</code> table in the WordPress database</a></h4>



<p>This screenshot shows columns in the <code>posts</code> table, however, you can check it from your database manager:</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1024" height="992" src="https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-posts-table.jpg" alt="posts table structure in WordPress" class="wp-image-3918" srcset="https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-posts-table.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-posts-table-300x291.jpg 300w, https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-posts-table-768x744.jpg 768w, https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-posts-table-25x25.jpg 25w, https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-posts-table-800x775.jpg 800w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption"><code>posts</code> table structure in WordPress</figcaption></figure>
</div>


<h4 class="wp-block-heading" id="chapter-1-part-1-postmeta"><a href="#chapter-1-part-1-postmeta"><strong>Table #2:</strong> <code>postmeta</code> table in the WordPress database</a></h4>



<p>WordPress stores <strong>Non-essential&nbsp;information</strong> for each post <strong>in <code>postmeta</code> table</strong>.</p>



<p>Therefore, information other than title, content, date, etc., goes into <strong><code>postmeta</code> table</strong>.</p>



<p>For example, all <strong>custom field data</strong> for each post are <strong>in <code>postmeta</code> table</strong> of your WordPress database.</p>



<p><code>postmeta</code> table in WordPress <strong>has four columns</strong> that you can see in below screenshot:</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="237" src="https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-postmeta-table-1024x237.jpg" alt="postmeta table structure in WordPress" class="wp-image-3920" srcset="https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-postmeta-table-1024x237.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-postmeta-table-300x70.jpg 300w, https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-postmeta-table-768x178.jpg 768w, https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-postmeta-table-800x185.jpg 800w, https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-postmeta-table.jpg 1467w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption"><code>postmeta</code> table structure in WordPress</figcaption></figure>
</div>


<h3 class="wp-block-heading" id="chapter-1-part-2"><a href="#chapter-1-part-2"><strong>Part 2:</strong> What if we have a custom table to join with the default WP Posts Query?</a></h3>



<p>Sometimes, a developer may need to include custom tables in the default WordPress database structure.</p>



<p>For example, <strong>when the data existed before installing WordPress</strong>.</p>



<p>Similarly, when the table is <strong>extracted from another database</strong> and <strong>cannot integrate into WordPress&#8217;s default database structure</strong>.</p>



<p>Of course, we have a <strong>solution to include information from the custom table</strong> in our posts query for each post.</p>



<h4 class="wp-block-heading" id="chapter-1-part-2-query-parts"><a href="#chapter-1-part-2-query-parts">How to modify Posts Query in WordPress to include information from a custom table?</a></h4>



<p>WordPress lets developers <strong>modify the actual MySQL query</strong> that will execute for posts.</p>



<p>Therefore, a few <strong>hooks</strong> are available for <strong>modifying each part of the posts query</strong>:</p>



<ol class="wp-block-list">
<li><code><a href="#chapter-2-part-1">posts_distinct</a></code></li>



<li><code><a href="#chapter-2-part-2">posts_fields</a></code></li>



<li><code><a href="#chapter-2-part-3">posts_where</a></code></li>



<li><code><a href="#chapter-2-part-4">posts_orderby</a></code></li>



<li><code><a href="#chapter-2-part-5">posts_groupby</a></code></li>



<li><code><a href="#chapter-2-part-6">post_limits</a></code></li>



<li><code><a href="#chapter-2-part-7">posts_join</a></code></li>
</ol>



<p>I listed <strong><code>post_join</code> as the last,</strong> because we <strong>must use other filters to see a meaningful result</strong> when joining a custom table to the query.</p>



<p>Likewise, our <strong>examples in this tutorial are in the same order</strong> to understand them better.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>If you are <strong>working on a caching plugin</strong>, read <a href="#chapter-4-tip-7">Tip #7 in the Chapter 4</a> of this tutorial for <strong>list of hooks</strong> available to <strong>use by caching plugins</strong>.</p>
</blockquote>



<p>The below SQL Query is the <strong>final query that executes</strong> to fetch posts in WordPress, so look at it before continuing:</p>



<pre><code class="language-sql" style="font-size: 13px;">SELECT $found_rows $distinct $fields FROM {$wpdb-&gt;posts} $join WHERE 1=1 $where $groupby $orderby $limits</code></pre>



<p><strong>Source:</strong> <code>wp-includes/class-wp-query.php</code></p>



<p>Did you notice these <strong>variables inside the query</strong> string?</p>



<p><code>$found_rows</code>, <code>$distinct</code>, <code>$fields</code>, <code>$join</code>, <code>$where</code>, <code>$groupby</code>, <code>$orderby</code>, <code>$limits</code></p>



<p>We have <strong>hooks</strong> in WordPress to use when we want <strong>to extend or modify each one</strong>.</p>



<p>Despite that, <code><strong>$found_rows</strong></code> <strong>can NOT be modified</strong>.</p>



<h2 class="wp-block-heading" id="chapter-2"><a href="#chapter-2"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f948.png" alt="🥈" class="wp-smiley" style="height: 1em; max-height: 1em;" />Chapter 2:</strong> Extend Posts Query in WordPress by Modifying All 7 Parts of the Query!</a></h2>



<p>First, look at the <strong>default executed MySQL query</strong> before modifying it:</p>



<pre><code class="language-sql">SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.post_date DESC LIMIT 0, 10;</code></pre>



<h3 class="wp-block-heading" id="chapter-2-part-1"><a href="#chapter-2-part-1"><strong>Part 1:</strong> Modify <code>DISTINCT</code> in Posts Query</a></h3>



<p><code>DISTINCT</code> is the <strong>keyword</strong> in MySQL queries responsible for <strong>filtering duplicated rows</strong>. thus, when we use <code>DISTINCT</code> in our queries, results will only <strong>contain unique values</strong>.</p>



<p><strong><code>posts_distinct</code> filter hook</strong> in WordPress will <strong>enable us to modify the <code>DISTINCT</code></strong> part of the wp posts query, In case of need for enabling DISTINCT.</p>



<h4 class="wp-block-heading" id="chapter-2-part-1-example"><a href="#chapter-2-part-1-example"><strong>Example:</strong> Enabling DISTINCT in posts query using <code>posts_distinct</code> filter hook</a></h4>



<p>The <strong>default posts query has no <code>DISTINCT</code> in it</strong>, But you can <strong>add it if you need</strong>, using the <strong><code>posts_distinct</code> filter hook</strong>.</p>



<pre><code class="language-php">// add DISTINCT to eliminate duplicated rows
if(!function_exists('my_added_distinct_to_posts_query')) {

	add_filter( 'posts_distinct', 'my_added_distinct_to_posts_query', 10, 2 );

	function my_added_distinct_to_posts_query($distinct, $wp_query) {
		return "DISTINCT";
	}

}</code></pre>



<h4 class="wp-block-heading" id="chapter-2-part-1-result"><a href="#chapter-2-part-1-result"><strong>Result:</strong> MySQL query after modifying <code>DISTINCT</code> with <code>posts_distinct</code> filter hook</a></h4>



<pre><code class="language-sql">SELECT SQL_CALC_FOUND_ROWS DISTINCT wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.post_date DESC LIMIT 0, 10;</code></pre>



<p>The <strong><code>DISTINCT</code> keyword presents</strong> after <code>SQL_CALC_FOUND_ROWS</code> keyword.</p>



<h3 class="wp-block-heading" id="chapter-2-part-2"><a href="#chapter-2-part-2"><strong>Part 2:</strong> Modify <code>SELECT</code> in Posts Query (filter data and add extra fields)</a></h3>



<p>When we need to <strong>filter the selected columns</strong> or <strong>request new fields</strong> in MySQL query, we can <strong>use <code>posts_fields</code> filter hook</strong> in WordPress.</p>



<h4 class="wp-block-heading" id="chapter-2-part-2-example"><a href="#chapter-2-part-2-example"><strong>Example:</strong> Requesting an additional field for posts using posts_fields filter hook</a></h4>



<p>in order to try this hook, we can <strong>extend <code>SELECT</code> part of the query</strong> and request an extra field.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Using <code>$wpdb-&gt;posts</code> is the same as typing actual <code>posts</code> table name.</p>
</blockquote>



<p>In this example, we&#8217;ll <strong>add a field to post items</strong> containing a text: <strong>concatenation of <code>ID</code> and <code>post_title</code></strong> columns.</p>



<pre><code class="language-php">//Add another field to retrieved records
//Concatenation of two columns ID and post_title used in this example
if(!function_exists('my_selected_fields_in_posts_query')) {

	add_filter( 'posts_fields', 'my_selected_fields_in_posts_query', 10, 2 );

	function my_selected_fields_in_posts_query($fields, $wp_query) {
		global $wpdb;

		//we used concat
		return $fields
		       . ", concat({$wpdb-&gt;posts}.ID, 
		                    ' has title: ', 
		                    {$wpdb-&gt;posts}.post_title)
		                    as id_title_text";
	}

}</code></pre>



<h4 class="wp-block-heading" id="chapter-2-part-2-result"><a href="#chapter-2-part-2-result"><strong>Result:</strong> MySQL query after modifying <code>SELECT</code> with <code>posts_fields</code> filter hook</a></h4>



<pre><code class="language-sql">SELECT SQL_CALC_FOUND_ROWS wp_posts.*, concat(wp_posts.ID, ' has title: ', wp_posts.post_title) as id_title_text FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.post_date DESC LIMIT 0, 10;</code></pre>



<p>Did you notice the below part in the above query? </p>



<p><code>concat(wp_posts.ID, ' has title: ', wp_posts.post_title) as id_title_text</code></p>



<p>Obviously, <code>my_selected_fields_in_posts_query</code> <strong>function did this modification</strong> in the posts query.</p>



<p>As a result, you can <strong>use <code>id_title_text</code> field for each post</strong> to access it.</p>



<p>So then, the <code>id_title_text</code> field for a post with <strong>ID equal to 1</strong> and <strong>&#8220;Hello World!&#8221; as the title</strong> will be:</p>



<p><code>[id_title_text] =&gt; "1 has title: Hello World!"</code></p>



<h3 class="wp-block-heading" id="chapter-2-part-3"><a href="#chapter-2-part-3"><strong>Part 3:</strong> Modify <code>WHERE</code> in Posts Query (set conditions for query)</a></h3>



<p>Using the <strong><code>posts_where</code> filter</strong> gives WP developers the ability to <strong>modify</strong> Posts Query&#8217;s <strong><code>WHERE</code> condition</strong>.</p>



<h4 class="wp-block-heading" id="chapter-2-part-3-example"><a href="#chapter-2-part-3-example"><strong>Example:</strong> Setting conditions for posts query using <code>posts_where</code> filter hook</a></h4>



<p>In order to try this hook, we&#8217;re going to <strong>fetch only posts with comments</strong>.</p>



<pre><code class="language-php">// set WHERE conditions in this example
if(!function_exists('my_where_conditions_in_posts_query')) {

	add_filter( 'posts_where', 'my_where_conditions_in_posts_query', 10, 2 );

	function my_where_conditions_in_posts_query($where, $wp_query) {

		global $wpdb;

		//we'll get 404 error on single post
		//we want only list items to affect, disable this feature for single posts:
		if(is_single())
			return $where;

		//always start with AND because we have a default WHERE 1=1 in the query
		//try only fetching posts with comments on them:
		return $where. " AND comment_count &gt; 0";
	}

}</code></pre>



<p>The <code>return $where. " AND comment_count &gt; 0"</code> is telling MySQL that we only need records with <strong>at least one comment</strong>.</p>



<h4 class="wp-block-heading" id="chapter-2-part-3-result"><a href="#chapter-2-part-3-result"><strong>Result:</strong> MySQL query after modifying <code>WHERE</code> with <code>posts_where</code> filter hook</a></h4>



<pre><code class="language-sql">SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') AND wp_posts.comment_count &gt; 0 ORDER BY wp_posts.post_date DESC LIMIT 0, 10</code></pre>



<h3 class="wp-block-heading" id="chapter-2-part-4"><a href="#chapter-2-part-4"><strong>Part 4:</strong> Modify <code>ORDER BY</code> in Posts Query (sorting)</a></h3>



<p><strong><code>posts_orderby</code> filter hook</strong> is available to use when we want to <strong>set the sort order</strong> of WordPress post items in posts query.</p>



<h4 class="wp-block-heading" id="chapter-2-part-4-example"><a href="#chapter-2-part-4-example"><strong>Example:</strong> Setting sort order for posts query using <code>posts_orderby</code> filter hook</a></h4>



<p>This example <strong>forces</strong> the posts query to retrieve <strong>more commented records at first positions</strong>. therefore, we set the <strong>sort order</strong> of posts query <strong>as <code>comment_count</code>, <code>DESC</code></strong> as the <strong>order direction</strong>.</p>



<pre><code class="language-php">// set ORDER BY column and direction in this example
if(!function_exists('my_orderby_in_posts_query')) {

	add_filter( 'posts_orderby', 'my_orderby_in_posts_query', 10, 2 );

	function my_orderby_in_posts_query($orderby) {

		global $wpdb;

		//DESC means from high to low, use 'ASC' for reverse
		$orderDirection = 'DESC';

		//we removed default sort order and set comment_count DESC as new one
		return "{$wpdb-&gt;posts}.comment_count {$orderDirection}";
	}

}</code></pre>



<h4 class="wp-block-heading" id="chapter-2-part-4-result"><a href="#chapter-2-part-4-result"><strong>Result:</strong> MySQL query after modifying <code>ORDER BY</code> with <code>posts_orderby</code> filter hook</a></h4>



<pre><code class="language-sql">SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.comment_count DESC LIMIT 0, 10</code></pre>



<p><code>ORDER BY wp_posts.comment_count DESC</code> string presents in the Posts Query.</p>



<h3 class="wp-block-heading" id="chapter-2-part-5"><a href="#chapter-2-part-5"><strong>Part 5:</strong> Modify <code>GROUP BY</code> in Posts Query</a></h3>



<p><strong>GROUP BY in Posts Query</strong> is useful when you want to <strong>join other tables</strong> with posts table to <strong>use aggregate functions</strong>.</p>



<p>For example, when you need to <strong>count records</strong> from another table <strong>associated with each post</strong>, you must <strong>group records by post ID</strong>.</p>



<p><strong>Aggregate functions</strong> in MySQL let developers <strong>calculate something based on a group</strong> of values available in <strong>different records</strong>.</p>



<h4 class="wp-block-heading" id="supported-aggregation-functions"><a href="#supported-aggregation-functions">MySQL supported aggregate functions to use on table columns</a></h4>



<figure class="wp-block-table is-style-regular"><table class="has-fixed-layout"><thead><tr><th>Keyword</th><th>Functionality</th><th>Example</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left"><strong>AVG</strong></td><td>Calculates Average of the Values</td><td>AVG(wp_posts.comment_count)</td></tr><tr><td class="has-text-align-left" data-align="left"><strong>COUNT</strong></td><td>Calculates the Number of Rows</td><td>COUNT(wp_posts.ID)</td></tr><tr><td class="has-text-align-left" data-align="left"><strong>MAX</strong></td><td>Finds Maximum Available Value</td><td>MAX(wp_posts.comment_count)</td></tr><tr><td class="has-text-align-left" data-align="left"><strong>MIN</strong></td><td>Finds Minimum Available Value</td><td>MIN(wp_posts.comment_count)</td></tr><tr><td class="has-text-align-left" data-align="left"><strong>SUM</strong></td><td>Calculates Summation of the Values</td><td>SUM(wp_posts.comment_count)</td></tr></tbody></table></figure>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>To understand the WP posts_groupby filter&#8217;s functionality, <strong>we skipped aggerate functions</strong> in the following example (<a href="#chapter-2-part-7">read part 7</a> for aggeration function usage example along with GROUP BY).</p>
</blockquote>



<h4 class="wp-block-heading" id="chapter-2-part-5-example"><a href="#chapter-2-part-5-example"><strong>Example:</strong> Setting Post ID as GROUP BY using <code>posts_groupby</code> filter hook</a></h4>



<pre><code class="language-php">//Setting {$wpdb-&gt;posts}.ID for GROUP BY in Posts Query
if(!function_exists('groupby_post_id_in_posts')) {

	add_filter( 'posts_groupby', 'groupby_post_id_in_posts', 10, 2 );

	function groupby_post_id_in_posts( $groupby, $wp_query ) {
		global $wpdb;

		return "{$wpdb-&gt;posts}.ID";
	}
}</code></pre>



<p>This example <strong>does not make any difference</strong> when <strong>we did not join</strong> any other table <strong>and use aggerate functions</strong>.</p>



<p>To see the <strong>actual result</strong>, <a href="#chapter-2-part-7">check out part 7 of this chapter</a> (<strong>counting <code>postmeta</code> records</strong> for each post as an example).</p>



<h4 class="wp-block-heading" id="chapter-2-part-5-result"><a href="#chapter-2-part-5-result"><strong>Result:</strong> MySQL query after modifying <code>GROUP BY</code> with <code>posts_groupby</code> filter hook</a></h4>



<pre><code class="language-sql">SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10</code></pre>



<p><code>GROUP BY wp_posts.ID</code> string presents on Posts Query now.</p>



<h3 class="wp-block-heading" id="chapter-2-part-6"><a href="#chapter-2-part-6"><strong>Part 6:</strong> Modify <code>LIMIT</code> in Posts Query</a></h3>



<p><strong>Limiting the number of posts</strong> to fetch is possible when <strong>using the <code>post_limits</code> filter hook</strong> to modify the <code>LIMIT</code> part of the MySQL query.</p>



<h4 class="wp-block-heading" id="chapter-2-part-6-example"><a href="#chapter-2-part-6-example"><strong>Example:</strong> Setting fetching limit to 100 records with <code>post_limits</code></a></h4>



<p>In this example, we will set the fetch record <strong>limit to 100</strong> rows.</p>



<pre><code class="language-php">//Set post limits to 100 rows
if(!function_exists('limit_number_of_posts_in_query')) {

	add_filter( 'post_limits', 'limit_number_of_posts_in_query', 10, 2 );

	function limit_number_of_posts_in_query( $limit, $wp_query ) {

		return 'LIMIT 0, 100';
	}
}</code></pre>



<h4 class="wp-block-heading" id="chapter-2-part-6-result"><a href="#chapter-2-part-6-result"><strong>Result:</strong> MySQL query after modifying <code>LIMIT</code> with <code>post_limit</code>s filter hook:</a></h4>



<pre><code class="language-sql">SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.post_date DESC LIMIT 0, 100</code></pre>



<p><code>LIMIT 0, 100</code> is the string responsible for commanding MySQL to <strong>fetch only 100 rows</strong> from the <code>posts</code> table.</p>



<h3 class="wp-block-heading" id="chapter-2-part-7"><a href="#chapter-2-part-7"><strong>Part 7:</strong> Modify <code>JOIN</code> in Posts Query</a></h3>



<p><strong><em>This part of our tutorial is the most crucial.</em></strong></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>If we use <strong><code>JOIN</code> without <code>GROUP BY</code></strong>, and <strong>not requesting fields</strong> in <code>SELECT</code>, We&#8217;ll end up with <strong>incorrect data</strong>.</p>
</blockquote>



<p>We must <strong>use <code>LEFT JOIN</code>, <code>GROUP BY</code> and also <code>SELECT</code> together</strong> to have a meaningful set of fields and <strong>correct data</strong>.</p>



<h4 class="wp-block-heading" id="chapter-2-part-7-example"><a href="#chapter-2-part-7-example"><strong>Example:</strong> Join <code>postmeta</code> table with <code>posts</code> table to select a <code>postmeta_counter</code> field for each post entity</a></h4>



<p>To see the result in <strong>this example</strong>, we will <strong>try <code>SELECT</code>, <code>GROUP BY</code>, and also <code>JOIN</code> together</strong>.</p>



<p>At this point, You <strong>don&#8217;t need to create a new table</strong>. In order to postpone this matter, we&#8217;ll <strong>use existing <code>postmeta</code> table</strong> to <strong>join with <code>posts</code></strong> for a test.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>We&#8217;ll try CUSTOM tables in the &#8220;<strong>build a post view counter example</strong>&#8221; on <strong><a href="#chapter-3">Chapter 3 of this tutoruial</a></strong>.</p>



<p><strong><a href="#chapter-3">Read Chapter 3</a> for a real case</strong> scenario of joining NON-WP tables with Posts Query.</p>
</blockquote>



<p>When implementing the below example, as result, it gives us an <strong>additional <code>postmeta_counter</code> field</strong> for each post.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Using <code>$wpdb-&gt;postmeta</code> is the same as typing actual <code>postmeta</code> table name.</p>
</blockquote>



<p>Obviously, <strong>additional <code>postmeta_counter</code> field</strong> represents the <strong>number of available metadata</strong> for that post.</p>



<p>We also set <strong><code>postmeta_counter</code> as the <code>ORDER BY</code></strong> for our posts query <strong>to sort results</strong> based on the number of metadata available for each post.</p>



<pre><code class="language-php">// the actual JOIN of postmeta with posts query
if(!function_exists('join_postmeta_to_posts')) {

	add_filter('posts_join', 'join_postmeta_to_posts', 10, 2);

	function join_postmeta_to_posts($join, $wp_query) {
		global $wpdb;

		//we need LEFT JOIN, other JOINs does not work in this case
		return $join . " LEFT JOIN {$wpdb-&gt;postmeta} as postmeta
					   ON postmeta.post_id = {$wpdb-&gt;posts}.ID";
	}

}

// select data we need from postmeta by modifying SELECT
if(!function_exists('select_postmeta_count_in_posts')) {

	add_filter('posts_fields', 'select_postmeta_count_in_posts', 10, 2);

	function select_postmeta_count_in_posts($fields, $wp_query) {
		//postmeta defined at JOIN.
		return $fields . ", COUNT(postmeta.meta_id) postmeta_counter";
	}

}

// Group by ID of posts gives us details of post + additional field
// It tells MySQL that we need all data for posts as main information, not other way around.
if(!function_exists('groupby_post_id_in_posts')) {

	add_filter( 'posts_groupby', 'groupby_post_id_in_posts', 10, 2 );

	function groupby_post_id_in_posts( $groupby, $wp_query ) {
		global $wpdb;
		$comma = " ";
		if ( $groupby ) {
			$comma = ", ";
		}

		return $groupby . $comma . "{$wpdb-&gt;posts}.ID";
	}
}</code></pre>



<h4 class="wp-block-heading" id="chapter-2-part-7-result"><a href="#chapter-2-part-7-result"><strong>Result:</strong> MySQL query that executes after using these filter hooks together:</a></h4>



<pre><code class="language-sql">SELECT SQL_CALC_FOUND_ROWS DISTINCT wp_posts.*, COUNT(postmeta.meta_id) postmeta_counter FROM wp_posts LEFT JOIN wp_postmeta as postmeta ON postmeta.post_id = wp_posts.ID WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10</code></pre>



<p><code>, COUNT(postmeta.meta_id) postmeta_counter</code> string is for <strong>selecting <code>postmeta_counter</code></strong> as an extra field <strong>for posts</strong>. (<code>posts_field</code> hook adds this)</p>



<p>Note that the <code>LEFT JOIN wp_postmeta as postmeta ON postmeta.post_id = wp_posts.ID</code> string is responsible for <strong>joining <code>postmeta</code> with <code>posts</code></strong> table. (<code>posts_join</code> hook adds this)</p>



<p>Also <code>ON postmeta.post_id = wp_posts.ID</code> tells MySQL to <strong>join the <code>postmeta</code></strong> table with <code>posts</code> and <strong>match records using the <code>post_id</code> column</strong> of <code>postmeta</code> table.</p>



<p>This means <strong>when the <code>post_id</code> column</strong> value in the <code>postmeta</code> table is <strong>equal to the <code>ID</code> column</strong> of <code>posts</code> table, postmeta entity will <strong>combine with post</strong> entity.</p>



<p>Undoubtedly, <code>GROUP BY wp_posts.ID</code> in the above query is <strong>crucial</strong> to get the <strong>data based on the post</strong> entity. (Along with <code>LEFT JOIN</code>)</p>



<p><code>GROUP BY wp_posts.ID</code> <strong>adds</strong> the <strong><code>postmeta_counter</code> field</strong> to the post entity, along <strong>with other post fields</strong>. (<code>posts_groupby</code> hook adds this)</p>



<h2 class="wp-block-heading" id="chapter-3"><a href="#chapter-3"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f949.png" alt="🥉" class="wp-smiley" style="height: 1em; max-height: 1em;" />Chapter 3:</strong> Build a post view counter functionality by joining a custom post views table with Posts Query</a></h2>



<p>At this point, you have enough information to go to the real case example part without guilt (copy past part!).</p>



<p>For a helpful <strong>example</strong>, I will add a <strong>post view counter</strong> for each post, using a <strong>custom-made table populated with fake data</strong>.</p>



<h3 class="wp-block-heading" id="chapter-3-step-1"><a href="#chapter-3-step-1"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" /><strong>Step 1:</strong> Create a table with sample data for post views in the WordPress database</a></h3>



<p>To begin with, you <strong>need a database table</strong> and <strong>sample data</strong>.</p>



<p>Hence, you must use a <strong>UI-based database management</strong> software or run <strong>direct Mysql Queries</strong> that I provided <strong>below</strong>.</p>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f9e0.png" alt="🧠" class="wp-smiley" style="height: 1em; max-height: 1em;" /> regardless of the fact that the <strong>following two parts</strong> contain useful details, <strong>you can Skip them</strong> by using <a href="#chapter-3-alternative"><strong>alternative PHP code</strong></a>.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Before going further, note that I <strong>assumed</strong> Database <strong>Prefix is <code>wp_</code> as the default</strong> WordPress setting.</p>



<p>So if you&#8217;ve <strong>changed your installation&#8217;s prefix, replace <code>wp_</code></strong> in all of below MySQL queries <strong>with your prefix</strong> (see names of your wp tables for a hint)</p>
</blockquote>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/27a1.png" alt="➡" class="wp-smiley" style="height: 1em; max-height: 1em;" />First, <strong>Connect to WP database</strong> using a database management software, <strong>such as phpMyAdmin or PostgreSQL</strong>.</p>



<p>However, you <strong>can connect to the database</strong> and run queries <strong>directly from the command line</strong>, But it <strong>requires advanced OS knowledge</strong>.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>If you see <strong>table names like <code>abc_posts</code></strong>, <code>abc_postmeta</code>, and <code>abc_comments</code> in WP database, means <strong><code>abc_</code> is your table prefix</strong>.</p>



<p><strong>Replace the <code>wp_</code></strong> in this tutorial <strong>with your actual WP prefix</strong>. But if you <strong>do not have a prefix, remove it</strong> from MySQL queries below.</p>
</blockquote>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/27a1.png" alt="➡" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Then, <strong>Create the <code>wp_post_views</code> table</strong> with four <strong>columns: <code>id</code>, <code>post_id</code>, <code>user_id</code>, <code>user_ip</code></strong>.</p>



<p>You can create the <code>wp_post_views</code> table, and also insert the sample data for it using database management software UI.</p>



<p>In that case, skip the following two parts. Because these <strong>MySQL commands</strong> are for <strong>creating the table</strong> and its <strong>sample data</strong>.</p>



<h4 class="wp-block-heading" id="chapter-3-step-1-part-1"><a href="#chapter-3-step-1-part-1"><strong>Part 1:</strong> Creating the <code>wp_post_views</code> table</a></h4>



<p>In case you <strong>did not use database manager</strong> UI to create the table, <strong>run the below query to create the <code>wp_post_views</code> table</strong>:</p>



<pre><code class="language-sql">CREATE TABLE IF NOT EXISTS `wp_post_views` ( 
	`id` INT NOT NULL AUTO_INCREMENT,
	`post_id` INT(11) NOT NULL,
	`user_id` INT(11) NULL,
	`user_ip` VARCHAR(32) NOT NULL,
	PRIMARY KEY  (`id`)
);</code></pre>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f53a.png" alt="🔺" class="wp-smiley" style="height: 1em; max-height: 1em;" />Remember to replace <code>wp_post_views</code> with <code>abc_post_views</code> if <code>abc_</code> is your table name prefix instead of <code>wp_</code>.</p>



<h4 class="wp-block-heading" id="chapter-3-step-1-part-2"><a href="#chapter-3-step-1-part-2"><strong>Part 2:</strong> Generate sample data in <code>wp_post_views</code> table</a></h4>



<p>You can <strong>generate this sample data using database manager</strong> UI too. <strong>but</strong> if you <strong>want to use MySQL query</strong>, execute this:</p>



<pre><code class="language-sql">INSERT INTO `wp_post_views`
			(`id`, `post_id`, `user_id`, `user_ip`)
			VALUES 
			(NULL, '1', NULL, '184.55.55.55');</code></pre>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f53a.png" alt="🔺" class="wp-smiley" style="height: 1em; max-height: 1em;" />Again, remember to replace <code>wp_post_views</code> with <code>abc_post_views</code> if <code>abc_</code> is your table name prefix instead of <code>wp_</code>.</p>



<h4 class="wp-block-heading" id="chapter-3-alternative"><a href="#chapter-3-alternative"><strong>Alternatively:</strong> Use WordPress PHP functions to create the <code>wp_post_views</code> database and sample data in one step</a></h4>



<p>Use WP <strong>functions to create the table and its sample data</strong> if you <strong>don&#8217;t want to</strong> connect with the database and <strong>run queries</strong> yourself.</p>



<p>You can <strong>copy this code</strong> in your <strong>plugin</strong>, <code><strong>functions.php</strong></code> of the activated theme, as well as <strong>any file that can execute WP functions</strong>.</p>



<p>I recommend <strong>creating a simple mu-plugin</strong>, which is <strong>short for Must Use Plugin</strong>.</p>



<p>First, <strong>create this file</strong> in the specified directory:</p>



<p><code>wp-content/mu-plugins/my-post-views-setup.php</code></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Create the <code>mu-plugins</code> inside <code>wp-content</code> directory if not already exists!</p>
</blockquote>



<p>Then, <strong>Copy/Past</strong> this code into it:</p>



<pre><code class="language-php">&lt;?php

if(!function_exists('myPostViewsPluginSetup')){

	//we used init hook because mu-plugins does not support register_activation_hook().
	add_action('init', 'myPostViewsPluginSetup');

	//setup function for our plugin. this function only runs once.
	function myPostViewsPluginSetup() {

		//check if post view plugin is activated
		if(get_option('my_post_views_plugin_activated') === '1')
			return;

		global $wpdb;

		$sql = "CREATE TABLE IF NOT EXISTS `{$wpdb-&gt;prefix}post_views` ( 
						`id` INT NOT NULL AUTO_INCREMENT,
						`post_id` INT(11) NOT NULL,
						`user_id` INT(11) NULL,
						`user_ip` VARCHAR(32) NOT NULL,
						PRIMARY KEY  (`id`)
					);";

		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
		dbDelta($sql);

		//add a sample visit for all posts when activating
		$posts = get_posts(array('posts_per_page' =&gt; -1));
		foreach($posts as $post){
			$wpdb-&gt;insert("{$wpdb-&gt;prefix}post_views",
							array('post_id' =&gt; $post-&gt;ID,
								  'user_id' =&gt; null,
								  'user_ip' =&gt; '::')
						 );
		}

		//set activation option to 1, so we do not execute this function again.
		//if we could use register_activation_hook() in mu plugins we had no such problem.
		update_option( 'my_post_views_plugin_activated', '1');

	}

}</code></pre>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><strong>MU-Plugins</strong> in WordPress are <strong>enabled by default</strong>. So you <strong>do NOT need to enable it</strong> on the admin panel.</p>
</blockquote>



<p><strong>After this</strong>, I can imagine that the <strong>wp_post_views table is in the WP database</strong> with a sample visit saved for each post on your website.</p>



<h3 class="wp-block-heading" id="chapter-3-step-2"><a href="#chapter-3-step-2"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f91d.png" alt="🤝" class="wp-smiley" style="height: 1em; max-height: 1em;" /><strong>Step 2:</strong> Join the <code>wp_post_views</code> table with WordPress Posts Query</a></h3>



<p>To join our wp_post_views with posts query, use the below code:</p>



<pre><code class="language-php">// select data we need from custom table by modifying SELECT
if(!function_exists('add_my_post_views_to_fields')) {

	add_filter('posts_fields', 'add_my_post_views_to_fields', 10, 2);

	function add_my_post_views_to_fields($fields, $wp_query) {
		return $fields . ", COUNT(post_views.id) view_counter";
	}

}

// join our custom table with posts query
if(!function_exists('join_my_post_views_to_query')) {

	add_filter('posts_join', 'join_my_post_views_to_query', 10, 2);

	function join_my_post_views_to_query($join, $wp_query) {
		global $wpdb;

		//we need LEFT JOIN, other JOINs does not work in this case
		return $join . " LEFT JOIN {$wpdb-&gt;prefix}post_views post_views 
					   ON post_views.post_id = {$wpdb-&gt;posts}.ID";
	}

}

// if did not set groupby, records will be disappeared
if(!function_exists('groupby_my_post_views_in_query')) {

	add_filter('posts_groupby', 'groupby_my_post_views_in_query', 10, 2);

	function groupby_my_post_views_in_query($groupby, $wp_query) {
		global $wpdb;
		$comma = " ";
		if ($groupby)
			$comma = ", ";

		return $groupby . $comma . "{$wpdb-&gt;posts}.ID";
	}

}</code></pre>



<p>After this, If you check the posts array in detail, you can find our view_counter as a new field.</p>



<h3 class="wp-block-heading" id="chapter-3-step-3"><a href="#chapter-3-step-3"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f44c.png" alt="👌" class="wp-smiley" style="height: 1em; max-height: 1em;" /><strong>Step 3:</strong> Try printing the post views number for each post</a></h3>



<p>To print post views numbers, you can use a content modify hook to add <code>view_counter</code> any spot you want.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>My cheatsheet when I need a filter is this file: <code>wp-includes/default-filters.php</code>, But not just for posts.</p>
</blockquote>



<p>For example, <code>the_excerpt</code> is a hook to modify post content. therefore, you can use it and add <code>view_counter</code> to the post excerpt. </p>



<p>Likewise, <code>the_content</code> is the modifier hook for the post&#8217;s content. </p>



<p>Furthermore, <code>the_title</code> is a clear name for the post title filter hook.</p>



<p>I used these three options to print the post view counter in the below example. But you better select one and remove others.</p>



<pre><code class="language-php">// append view_counter field after post excerpt
if(!function_exists('append_post_views_to_post_excerpt')) {

	//Note: use get_the_excerpt if get_the_title() prints the excerpt in your theme.
	add_filter('the_excerpt', 'append_post_views_to_post_excerpt', 10, 2);

	function append_post_views_to_post_excerpt($excerpt) {
		global $post;

		if($post &amp;&amp; isset($post-&gt;view_counter))
			return "{$excerpt} <div>(Post Views: {$post-&gt;view_counter})</div>";

		return $excerpt;
	}

}

// append view_counter field after post content
if(!function_exists('append_post_views_to_post_content')) {

	//Note: use get_the_content if get_the_title() prints the content in your theme.
	add_filter('the_content', 'append_post_views_to_post_content', 10, 2);

	function append_post_views_to_post_content($excerpt) {
		global $post;

		if($post &amp;&amp; isset($post-&gt;view_counter))
			return "{$excerpt} <div>(Post Views: {$post-&gt;view_counter})</div>";

		return $excerpt;
	}

}

// append view_counter field after post title
if(!function_exists('append_post_views_to_post_title')) {

	//Note: use get_the_title if get_the_title() prints the title in your theme.
	add_filter('the_title', 'append_post_views_to_post_title', 10, 2);

	function append_post_views_to_post_title($title) {
		global $post;

		if($post &amp;&amp; isset($post-&gt;view_counter))
			return "{$title} <div>(Post Views: {$post-&gt;view_counter})</div>";

		return $title;
	}

}</code></pre>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>First, use <code>get_the_excerpt</code> hook when <code>echo get_the_excerpt()</code> prints the post excerpt.</p>



<p>Second, use <code>get_the_content</code> filter when <code>echo get_the_content()</code> prints the post content.</p>



<p>Lastly, use <code>get_the_title</code> filter when <code>echo get_the_title()</code> prints the post title.</p>
</blockquote>



<p>After this, check your posts list or single post page, and you can view <code>Post Views: x</code> where you requested.</p>



<h3 class="wp-block-heading" id="chapter-3-step-4"><a href="#chapter-3-step-4"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f44d.png" alt="👍" class="wp-smiley" style="height: 1em; max-height: 1em;" /><strong>Step 4:</strong> Save actual post visits in our <code>wp_post_views</code> table</a></h3>



<p>There are two options available when you want to save post view record on the database table after each visit.</p>



<p>One for the websites without cache plugins and another if the cache is enabled.</p>



<h4 class="wp-block-heading" id="chapter-3-step-4-option-1"><a href="#chapter-3-step-4-option-1"><strong>Option #1:</strong> Save visits when page caching is NOT enabled</a></h4>



<p>Use this code to get the visitor&#8217;s IP address and current user&#8217;s ID (if available), then save the data to the post views table in case of a visit.</p>





<p>After this, a record inserts into the post views table when a visitor visits a post page.</p>



<p>If not, it may be a problem with page caching plugins. In such a case, use option 2 to save the visits.</p>



<h4 class="wp-block-heading" id="chapter-3-step-4-option-2"><a href="#chapter-3-step-4-option-2"><strong>Option #2:</strong> Save visits when page caching is enabled</a></h4>



<p>Because cache plugins ditch filter hooks, you must create a special URL to save page visits with JavaScript AJAX requests.</p>



<p>You need a <code>&lt;script&gt;</code> tag in post pages, containing a JavaScript function for sending an AJAX request to save visits for the current post.</p>



<h3 class="wp-block-heading" id="chapter-3-step-5"><a href="#chapter-3-step-5"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f381.png" alt="🎁" class="wp-smiley" style="height: 1em; max-height: 1em;" /><strong>Step 5:</strong> Wrap all these functionalities into a DIY Post View Counter Plugin</a></h3>



<p>Even though you can use previous steps to utilize the post view counter, I&#8217;ll teach you to create a plugin out of what you&#8217;ve learned.</p>



<p>WP plugins are simply functional by enabling them from the admin panel, so you can employ this functionality for any website you want with a few clicks.</p>



<h4 class="wp-block-heading" id="chapter-3-step-5-part-1"><a href="#chapter-3-step-5-part-1"><strong>Part 1:</strong> Create the plugin&#8217;s folder and main PHP file</a></h4>



<p>Plugins are stored in the <code>wp-content/plugins</code> directory inside WordPress folder structures.</p>



<p>To create the <code>my-post-view-counter</code> plugin, create this file in the specified directory:</p>



<p><code>wp-content/plugins/my-post-view-counter/my-post-view-counter.php</code></p>



<h4 class="wp-block-heading" id="chapter-3-step-5-part-2"><a href="#chapter-3-step-5-part-2"><strong>Part 2:</strong> Append all functions in the plugin&#8217;s main PHP file</a></h4>



<p>To do this, simple <strong>Copy/Past</strong> these codes into the <code>my-post-view-counter.php</code> file:</p>



<pre><code class="language-php">&lt;?php
/**
 * My Post Views
 *
 * @package     MyPostViwes
 * @author      Mehdi Nazari
 * @copyright   2022 Mehdi Nazari
 * @license     GPL-2.0-or-later
 *
 * @wordpress-plugin
 * Plugin Name: My Post Views
 * Plugin URI:  https://mehdinazari.com/join-custom-tables-with-wordpress-posts-query/
 * Description: This plugin saves post views on a custom table and then prints it on posts.
 * Version:     1.0.0
 * Author:      Mehdi Nazari
 * Author URI:  https://mehdinazari.com
 * Text Domain: my-post-views
 * License:     GPL v2 or later
 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 */


if (!function_exists('myPostViewsPluginSetup')) {

	add_action('init', 'myPostViewsPluginSetup');

	register_activation_hook( __FILE__, 'myPostViewsPluginSetup' );


	//setup function for our plugin. this function only runs once.
	function myPostViewsPluginSetup() {

		global $wpdb;

		$sql = "CREATE TABLE IF NOT EXISTS `{$wpdb-&gt;prefix}post_views` ( 
						`id` INT NOT NULL AUTO_INCREMENT,
						`post_id` INT(11) NOT NULL,
						`user_id` INT(11) NULL,
						`user_ip` VARCHAR(32) NOT NULL,
						PRIMARY KEY  (`id`)
					);";

		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
		dbDelta( $sql );

		//add a sample visit for all posts when activating
		$posts = get_posts( array( 'posts_per_page' =&gt; - 1 ) );
		foreach ( $posts as $post ) {
			$wpdb-&gt;insert( "{$wpdb-&gt;prefix}post_views",
				array(
					'post_id' =&gt; $post-&gt;ID,
					'user_id' =&gt; null,
					'user_ip' =&gt; '::'
				)
			);
		}

	}

}

// select data we need from custom table by modifying SELECT
if(!function_exists('add_my_post_views_to_fields')) {

	add_filter('posts_fields', 'add_my_post_views_to_fields', 10, 2);

	function add_my_post_views_to_fields($fields, $wp_query) {
		return $fields . ", COUNT(post_views.id) view_counter";
	}

}

// join our custom table with posts query
if(!function_exists('join_my_post_views_to_query')) {

	add_filter('posts_join', 'join_my_post_views_to_query', 10, 2);

	function join_my_post_views_to_query($join, $wp_query) {
		global $wpdb;

		//we need LEFT JOIN, other JOINs does not work in this case
		return $join . " LEFT JOIN {$wpdb-&gt;prefix}post_views post_views 
					   ON post_views.post_id = {$wpdb-&gt;posts}.ID";
	}

}

// if did not set groupby, records will be disappeared
if(!function_exists('groupby_my_post_views_in_query')) {

	add_filter('posts_groupby', 'groupby_my_post_views_in_query', 10, 2);

	function groupby_my_post_views_in_query($groupby, $wp_query) {
		global $wpdb;
		$comma = " ";
		if ($groupby)
			$comma = ", ";

		return $groupby . $comma . "{$wpdb-&gt;posts}.ID";
	}

}

//get visitor's ip address
if(!function_exists('getVisitorIPAddress')) {
	function getVisitorIPAddress(){

		if (!empty($_SERVER['HTTP_CLIENT_IP']))
			$ip = $_SERVER['HTTP_CLIENT_IP'];
		elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
			$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
		else
			$ip = $_SERVER['REMOTE_ADDR'];

		return $ip ? $ip : "::";
	}

}

//add visit record to post views table
if(!function_exists('addPostVisitsToMyPostViewsTable')) {
	function addPostVisitsToMyPostViewsTable(){

		global $wpdb;

		//define visit data array
		$visitData = array();

		//get the post ID
		$visitData['post_id'] = get_the_ID();

		//get user ID (if available)
		$userId = get_current_user_id();
		if($userId)
			$visitData['user_id'] = $userId;

		//get visitor IP
		$visitData['user_ip'] = getVisitorIPAddress();

		//insert visit, then return number of rows on success, or false if failed.
		return $wpdb-&gt;insert("{$wpdb-&gt;prefix}post_views", $visitData);
	}

}

//trigger addPostVisitsToMyPostViewsTable() in case of post visit, using the_content hook
if(!function_exists('add_visit_to_my_post_views_trigger')) {

	add_filter('the_content', 'add_visit_to_my_post_views_trigger');

	function add_visit_to_my_post_views_trigger($content){

		//check if it's a post, then save the visit
		if (is_single())
			addPostVisitsToMyPostViewsTable();

		//let WP continue without modifying post content
		return $content;
	}

}


// append view_counter field after post excerpt
if(!function_exists('append_post_views_to_post_excerpt')) {

	//Note: use get_the_excerpt if get_the_title() prints the excerpt in your theme.
	add_filter('the_excerpt', 'append_post_views_to_post_excerpt', 10, 2);

	function append_post_views_to_post_excerpt($excerpt) {
		global $post;

		if($post &amp;&amp; isset($post-&gt;view_counter))
			return "{$excerpt} (Post Views: {$post-&gt;view_counter})";

		return $excerpt;
	}

}

// append view_counter field after post content
if(!function_exists('append_post_views_to_post_content')) {

	//Note: use get_the_content if get_the_title() prints the content in your theme.
	add_filter('the_content', 'append_post_views_to_post_content', 10, 2);

	function append_post_views_to_post_content($excerpt) {
		global $post;

		if($post &amp;&amp; isset($post-&gt;view_counter))
			return "{$excerpt} (Post Views: {$post-&gt;view_counter})";

		return $excerpt;
	}

}

// append view_counter field after post title
if(!function_exists('append_post_views_to_post_title')) {

	//Note: use get_the_title if get_the_title() prints the title in your theme.
	add_filter('the_title', 'append_post_views_to_post_title', 10, 2);

	function append_post_views_to_post_title($title) {
		global $post;

		if($post &amp;&amp; isset($post-&gt;view_counter))
			return "{$title} (Post Views: {$post-&gt;view_counter})";

		return $title;
	}

}</code></pre>



<h4 class="wp-block-heading" id="chapter-3-step-5-part-3"><a href="#chapter-3-step-5-part-3"><strong>Part 3:</strong> Activate the plugin from the WP admin panel</a></h4>



<p>Open your WordPress admin panel and enable your plugin from the <code>plugins-&gt;installed plugins</code> page.</p>



<p>That&#8217;s it, and now you have the post view counter functionality on your website.</p>



<p>Try it by visiting a post in the frontend, then check the counter to see if it works or not.</p>



<h2 class="wp-block-heading" id="chapter-4"><a href="#chapter-4"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f3c5.png" alt="🏅" class="wp-smiley" style="height: 1em; max-height: 1em;" />Chapter 4:</strong> Tips to keep in mind when you want to join custom tables in WordPress Posts Query</a></h2>



<p>Now that you have come to this point, get ready for your mastering degree in 3&#8230;2&#8230;1</p>



<p>Oh, please wait a minute; I guess I forgot something important. <strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f6a8.png" alt="🚨" class="wp-smiley" style="height: 1em; max-height: 1em;" /></strong></p>



<p>Finally, read these <strong>seven tips to master Posts Query</strong> in WordPress. <strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f447.png" alt="👇" class="wp-smiley" style="height: 1em; max-height: 1em;" /></strong></p>



<h3 class="wp-block-heading" id="chapter-4-part-1"><a href="#chapter-4-tip-1"><strong>Tip #1:</strong> Backup, Backup, Backup, and again, BACKUP!</a></h3>



<p>I can&#8217;t tell you how many times I <strong>got out of trouble</strong> because I <strong>had a recent backup</strong> available.</p>



<p>Believe me, the <strong>most necessary step</strong> when developing software is <strong>backing up files and databases</strong>.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Remember to <strong>store backup files somewhere safe</strong>. Because backups often include <strong>sensitive data, usable by hackers</strong>.</p>
</blockquote>



<p>You can <strong>find the best <a href="https://wordpress.org/plugins/tags/backup/">backup management plugins</a></strong><a href="https://wordpress.org/plugins/tags/backup/"> </a>when visiting the wordpress.org plugins directory.</p>



<h3 class="wp-block-heading" id="chapter-4-tip-2"><a href="#chapter-4-tip-2"><strong>Tip #2:</strong> Understand the difference between different types of JOIN</a></h3>



<p>In SQL queries, you can use <strong>JOIN to combine multiple tables</strong> and then make a <strong>mixed result</strong> based on <strong>specified relationships</strong>.</p>



<p>For example, you have <strong><code>posts</code> and <code>postmeta</code> tables in the WP</strong> database.</p>



<p>The <code>postmeta</code> table has a <strong><code>post_id</code> column</strong> that <strong>binds the relationship</strong> between <code>postmeta</code> and the <code>posts</code> table.</p>



<p>When we want to add <strong>meta information for a post </strong>with <strong><code>ID</code> equal to 1</strong>, we can create a <strong>record in the <code>postmeta</code></strong> table and set <code><strong>post_id=1</strong></code> for it.</p>



<p>Because of <strong>this approach</strong>, MySQL <strong>know</strong>s<strong> which <code>postmeta</code></strong> belongs to <strong>which post</strong> entity in <code>posts</code> table.</p>



<p>When we want to <strong>retrieve information of a post</strong> and <strong>include data</strong> stored <strong>for that post in <code>postmeta</code></strong> table, we can <strong>join the two tables</strong> and <strong>make a mixed record</strong> of their columns.</p>



<p>Though, we have <strong>multiple options</strong> to tell the database how <strong>to combine tables</strong>:</p>



<ol class="wp-block-list">
<li><strong><code>JOIN</code>:</strong> Asks for records with matching values in both tables. therefore, If a match does not exist, the result is null.</li>



<li><strong><code>LEFT JOIN</code>:</strong> Asks for records from the first table mixed with matched records from the second. therefore, If a match does not exist in the second table, information on the first table will return.</li>



<li><strong><code>RIGHT JOIN</code>:</strong> Asks for records from the second table mixed with matched records from the second table. accordingly, If a match does not exist in the first table, information on the second table will return.</li>



<li><strong>FULL JOIN:</strong> Asks for records mixed together; hence, the first or second table does not matter.</li>
</ol>



<p>I guess <code><strong>LEFT JOIN</strong></code> is helpful <strong>in many scenarios</strong>.</p>



<p>However, I will not explain more about possible join options. Because you <strong>need a full-length tutorial</strong> on this topic.</p>



<p>A picture worth a thousand words, So look at this one:</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1024" height="480" src="https://mehdinazari.com/wp-content/uploads/2022/09/sql-joins.jpg" alt="SQL Table Joins Visualization" class="wp-image-4212" srcset="https://mehdinazari.com/wp-content/uploads/2022/09/sql-joins.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2022/09/sql-joins-300x141.jpg 300w, https://mehdinazari.com/wp-content/uploads/2022/09/sql-joins-768x360.jpg 768w, https://mehdinazari.com/wp-content/uploads/2022/09/sql-joins-800x375.jpg 800w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">SQL Table Joins Visualization</figcaption></figure>
</div>


<h3 class="wp-block-heading" id="chapter-4-tip-3"><a href="#chapter-4-tip-3"><strong>Tip #3:</strong> Group By <code>{$wpdb-&gt;posts}.ID</code> is an essential part of our code when using aggeration functions along with joining tables</a></h3>



<p>Obviously, <strong>Post ID is a unique</strong> key for each post.</p>



<p>Also, <strong>GROUP BY keyword is for grouping</strong> records based on a column.</p>



<p><a href="#supported-aggregation-functions"><strong>Aggregation Functions</strong></a> are helpful when <a href="https://mehdinazari.com/wp-admin/post.php?post=327&amp;action=edit#supported-aggregation-functions"></a><strong>performing calculations on multiple records</strong> in tables.</p>



<p>When we want to <strong>perform an aggeration function</strong> on associated values to a post, we <strong>need to group records by Post ID</strong>.</p>



<p>This way, we tell the database: &#8220;We need to calculate something based on available values for each post item. Please do the calculation, then specify which value is for which post item. Thank you!&#8221;.</p>



<h3 class="wp-block-heading" id="chapter-4-tip-4"><a href="#chapter-4-tip-4"><strong>Tip #4:</strong> Find solutions to store your data in <code>postmeta</code> table instead of creating new tables</a></h3>



<p>In <a href="#chapter-1">chapter 1 of this tutorial</a>, I told you this:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>The WP <strong>development team planned</strong> a database table <strong>structure to store</strong> data for <strong>all the possible scenarios</strong>.</p>
</blockquote>



<p><strong>in case you did not encounter any performance issues</strong>, you better <strong>trust the WordPress</strong> <strong>structure</strong>.</p>



<p>The <strong><code>posts</code> and <code>postmeta</code></strong> tables can offer a <strong>solution to</strong> store different entities, <strong>NOT only Posts</strong>, but <strong>any type</strong> of data.</p>



<p>Consider <strong>these two tables</strong> your <strong>primary way</strong> of storing data when developing plugins or themes.</p>



<p>Therefore, <strong>custom post types are the solution for</strong> offering <strong>content storage</strong> to users.</p>



<p>Plus, WordPress <strong>preserved functionalities</strong> that developers <strong>can execute on the post items</strong>.</p>



<p>For example, you can <strong>create a slideshow</strong> plugin and save the <strong>slides with a custom post type</strong>.</p>



<p>You can also create <strong>custom taxonomies to categorize</strong> items of custom post types.</p>



<p>Always think twice before <strong>making new tables</strong> and <strong>messing up the WordPress</strong> database.</p>



<h3 class="wp-block-heading" id="chapter-4-tip-5"><a href="#chapter-4-tip-5"><strong>Tip #5:</strong> Choice a unique and understandable name for your new fields and database columns</a></h3>



<p>When using the <strong><code>posts_filter</code> hook</strong> to request new fields, <strong>or create new tables</strong> in the database, always <strong>use comprehensible name</strong> keys.</p>



<p>For one thing, <strong>separate</strong> different <strong>words</strong> in the key <strong>with underlines</strong> to <strong>increase the readability</strong>.</p>



<p>As an example, do <strong>NOT</strong> use <strong><code>postid</code>, or <code>postId</code></strong> (better choice, by the way), use <strong><code>post_id</code> instead</strong>.</p>



<p>Another developer can <strong>read the name at first sight</strong> when using <strong>underline as the separator</strong>.</p>



<h3 class="wp-block-heading" id="chapter-4-tip-6"><a href="#chapter-4-tip-6"><strong>Tip #6:</strong> For testing proposes, do not execute <code>get_posts()</code> in the <code>functions.php</code> directly</a></h3>



<p>At least use a <strong>hook with a suitable execution time</strong>.</p>



<p>When trying to <strong>execute get_posts() directly</strong> in your <strong>functions.php file</strong>, posts query modifier <strong>hooks will not affect</strong> the result.</p>



<p><strong><code>template_redirect</code> hook</strong> can be a <strong>good choice</strong> when you want <strong>to try</strong> if your codes work as expected or not.</p>



<p>This hook indeed <strong>executes after</strong> posts query <strong>modifier hooks</strong>.</p>



<pre><code class="language-php">add_action('template_redirect', 'my_test_function_name');
function my_test_function_name(){
    // run your codes, but it is not a cool way to test!
    print_r(get_posts());
}</code></pre>



<h3 class="wp-block-heading" id="chapter-4-tip-7"><a href="#chapter-4-tip-7"><strong>Tip #7:</strong> Append <code>_request</code> at the end of hook names if you are building a caching plugin (ex: <code>posts_join_request</code> instead of <code>posts_join</code>)</a></h3>



<p>For one thing, cache plugins will save a static version of your pages someplace on the disk.</p>



<p>If a user visits those cached pages, WP serves that static file containing pure HTML code instead of connecting to the database.</p>



<p>When you are working on <strong>building your caching plugin</strong>, you can <strong>append <code>_request</code> to</strong> posts query <strong>modification hooks</strong>.</p>



<p>Using this approach, undoubtedly, WordPress <strong>ensures</strong> that your <strong>query modifier</strong> functions are <strong>executing</strong>.</p>



<figure class="wp-block-table"><table><thead><tr><th>Original Hook</th><th>Hook for Caching Plugins</th></tr></thead><tbody><tr><td><code>posts_distinct</code></td><td><code>posts_distinct_request</code></td></tr><tr><td><code>posts_fields</code></td><td><code>posts_fields_request</code></td></tr><tr><td><code>posts_where</code></td><td><code>posts_where_request</code></td></tr><tr><td><code>posts_groupby</code></td><td><code>posts_groupby_request</code></td></tr><tr><td><code>posts_orderby</code></td><td><code>posts_orderby_request</code></td></tr><tr><td><code>post_limits</code></td><td><code>post_limits_request</code></td></tr><tr><td><code>posts_join</code></td><td><code>posts_join_request</code></td></tr></tbody></table></figure>



<p>Because the coding chapters of this tutorial are finished, you can travel back to <a href="#chapter-1">chapter 1</a>.</p>



<p>However, you can continue scrolling to the final chapter for the top learning resources.</p>



<h2 class="wp-block-heading" id="final-chapter"><a href="#final-chapter"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f3c6.png" alt="🏆" class="wp-smiley" style="height: 1em; max-height: 1em;" /><strong>Final Chapter:</strong> Never Stop Learning, My Developer Friend, NEVER!</a></h2>



<p>In case you missed that, I was shouting the &#8220;NEVER&#8221; in the title.</p>



<p>Ok, Now, It&#8217;s the final chapter.</p>



<p>But only if you consider this section a chapter or if learning somehow had a final chapter.</p>



<p>Then, I hope this is not the final chapter of learning for any of you developers; I just finished my work in this section.</p>



<p><strong>Keep reading</strong> the perfect resources available to learn more about <strong>Extending WordPress Posts Query</strong>.</p>



<p><strong>Continue learning</strong> by visiting the list of resources for the brilliant developers who <strong>never get satisfied</strong> by one tutorial (even if it&#8217;s a long tutorial like this one!).</p>



<h3 class="wp-block-heading" id="final-chapter-part-1"><a href="#final-chapter-part-1"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/26d3.png" alt="⛓" class="wp-smiley" style="height: 1em; max-height: 1em;" />Part 1:</strong> Top resources to learn about WordPress Posts Query Development</a></h3>



<p>Of course, <strong>I did not cover every part</strong> of this topic. <strong>Nobody can do</strong> it alone.</p>



<p>I tried to include everything I learned over the years in this tutorial. Although, It would be <strong>best if you continued exploring</strong>; When there is <strong>more stuff to know</strong>.</p>



<p>Visit places on the internet that can help you a lot more than I can:</p>



<h4 class="wp-block-heading" id="final-chapter-part-1-source-1"><a href="#final-chapter-part-1-source-1"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f517.png" alt="🔗" class="wp-smiley" style="height: 1em; max-height: 1em;" />Source #1:</strong> WordPress official pages about Posts Query hooks:</a></h4>



<p><strong>WordPress&#8217;s official</strong> website has the best tutorials <strong>for developers</strong>. Then, If you are interested in being a WP developer, visit the <a href="https://developer.wordpress.org/">developers section of the WordPress.org website</a> to try out tutorials.</p>



<p>I recommend these pages for you to learn Posts Query development on the official WP website:</p>



<ul class="wp-block-list">
<li><a href="https://developer.wordpress.org/reference/classes/wp_query/" target="_blank" rel="noreferrer noopener">WP_Query class page</a></li>



<li><a href="https://developer.wordpress.org/reference/classes/wp_query/get_posts/" target="_blank" rel="noreferrer noopener">get_posts function page</a></li>



<li><a href="https://developer.wordpress.org/reference/hooks/posts_distinct/" target="_blank" rel="noreferrer noopener">posts_distinct hook page</a></li>



<li><a href="https://developer.wordpress.org/reference/hooks/posts_fields/" target="_blank" rel="noreferrer noopener">posts_fields hook page</a></li>



<li><a href="https://developer.wordpress.org/reference/hooks/posts_join/" target="_blank" rel="noreferrer noopener">posts_join hook page</a></li>



<li><a href="https://developer.wordpress.org/reference/hooks/posts_where/" target="_blank" rel="noreferrer noopener">posts_where hook page</a></li>



<li><a href="https://developer.wordpress.org/reference/hooks/posts_groupby/" target="_blank" rel="noreferrer noopener">posts_groupby hook page</a></li>



<li><a href="https://developer.wordpress.org/reference/hooks/posts_orderby/" target="_blank" rel="noreferrer noopener">posts_orderby hook page</a></li>



<li><a href="https://developer.wordpress.org/reference/hooks/post_limits/" target="_blank" rel="noreferrer noopener">post_limits hook page</a></li>
</ul>



<h4 class="wp-block-heading" id="final-chapter-part-1-source-2"><a href="#final-chapter-part-1-source-2"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f517.png" alt="🔗" class="wp-smiley" style="height: 1em; max-height: 1em;" />Source #2:</strong> StackExchange and StackOverflow questions on Posts Queries topic</a></h4>



<p>Search any keyword you&#8217;ve encountered in my tutorial on StackOverflow, then you will be surprised to witness developers helping others.</p>



<p>Visit the <a href="https://stackoverflow.com/search?q=wp_query" target="_blank" rel="noreferrer noopener">wp_query search page on StackOverflow</a> for related topics regarding querying WP posts.</p>



<p>The <a href="https://wordpress.stackexchange.com/questions/tagged/wp_query?tab=Frequent" target="_blank" rel="noreferrer noopener">list of frequent questions tagged with wp-query on wordpress.stackexchange.com</a> also contains many frequently asked questions you may encounter in the future.</p>



<p>StackOverflow is a site in the network of StackExchange that contains programming questions, while wordpress.stackexchange.com is a site about WordPress-only topics.</p>



<h3 class="wp-block-heading" id="final-chapter-part-2"><a href="#final-chapter-part-2"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/26d3.png" alt="⛓" class="wp-smiley" style="height: 1em; max-height: 1em;" />Part 2:</strong> Where to ask questions about challenges you are facing</a></h3>



<p><a href="https://stackoverflow.com" target="_blank" rel="noreferrer noopener">StackOverflow</a> is always the best place to ask your questions about programming issues.</p>



<p>Don&#8217;t forget <a href="https://wordpress.stackexchange.com" target="_blank" rel="noreferrer noopener">wordpress.stackexchange.com</a>, which has a truly active community of brilliant WordPress developers, humble enough to help beginners.</p>



<p>WordPress&#8217;s official support team has a <a href="https://wordpress.org/support/forum/wp-advanced/" target="_blank" rel="noreferrer noopener">forum for WP developers</a> that you can visit to ask questions about WordPress development.</p>



<h3 class="wp-block-heading" id="final-chapter-part-3"><a href="#final-chapter-part-3"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/26d3.png" alt="⛓" class="wp-smiley" style="height: 1em; max-height: 1em;" />Part 3:</strong> My top recommended list of tutorials for interested WordPress developers</a></h3>



<p>Learn more about WP development by reading seven must essential WordPress tutorials on my blog; however, I did not include any external links in the list (I&#8217;m sorry about that <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f625.png" alt="😥" class="wp-smiley" style="height: 1em; max-height: 1em;" />):</p>



<ol class="wp-block-list">
<li><a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">Learn how to build a plugin for WordPress</a></li>



<li><a href="https://mehdinazari.com/wordpress-action-filter-hooks-tutorial/">Learn how to use action and filter hooks in WordPress</a></li>



<li><a href="https://mehdinazari.com/wordpress-query-posts/">Learn how to retrieve WordPress posts with desired filters</a></li>



<li><a href="https://mehdinazari.com/query-wordpress-categories-tags-taxonomies/">Learn how to query WordPress categories, tags, and custom taxonomies</a></li>



<li><a href="https://mehdinazari.com/add-custom-shortcode-wordpress/">Learn how to register custom shortcodes in WordPress</a></li>



<li><a href="https://mehdinazari.com/get-comment-information-by-comment-id-wordpress/">Learn how to get comment details in WordPress</a></li>



<li><a href="https://mehdinazari.com/list-users-in-wordpress-programmatically/">Learn how to get the list of users in WordPress</a></li>
</ol>



<p>Repeat this tutorial from <a href="#chapter-1">chapter 1</a>, or continue scrolling to see a list of the latest WordPress tutorials on my blog.</p><p>The post <a href="https://mehdinazari.com/join-custom-tables-with-wordpress-posts-query/">How to Extend WordPress Posts Query and Join New Tables</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/join-custom-tables-with-wordpress-posts-query/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get Post Date with Custom Format in WordPress [Shortcode]</title>
		<link>https://mehdinazari.com/get-post-date-special-date-formats-wordpress/</link>
					<comments>https://mehdinazari.com/get-post-date-special-date-formats-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 01 Sep 2022 10:31:52 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=1743</guid>

					<description><![CDATA[<p>Do you need to get the publish date for the active post? or just get the publish date by specifying a post ID? in this WordPress tutorial, we used a particular WP function to retrieve the publish date of any post with various formats. We used PHP codes to get the post date of a [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/get-post-date-special-date-formats-wordpress/">How to Get Post Date with Custom Format in WordPress [Shortcode]</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Do you need to get the publish date for the active post? or just get the publish date by specifying a post ID? in this WordPress tutorial, we used a particular WP function to retrieve the publish date of any post with various formats. We used PHP codes to get the post date of a requested post, but it can be wrapped into a shortcode.</p>



<span id="more-1743"></span>



<p>There is <strong>a function in WordPress that can retrieve a post&#8217;s publish date</strong>.</p>



<p><strong><code>get_the_date()</code> </strong>is the function <strong>responsible for getting the publish date of a post</strong>.</p>



<p><code>get_the_date()</code> accepts an <strong>optional &#8216;format&#8217; parameter</strong>, which is helpful when you want <strong>to customize the output string</strong>.</p>



<p>If you <strong>do not specify the date format</strong>, get_the_date() will <strong>get it from WordPress settings</strong> (Path: <strong>Admin Panel -&gt; Settings -&gt; General</strong>).</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="337" src="https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-date-settings-1024x337.jpg" alt="" class="wp-image-3887" srcset="https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-date-settings-1024x337.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-date-settings-300x99.jpg 300w, https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-date-settings-768x253.jpg 768w, https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-date-settings-800x263.jpg 800w, https://mehdinazari.com/wp-content/uploads/2022/09/wordpress-date-settings.jpg 1491w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">WordPress Panel -&gt; Settings -&gt; General</figcaption></figure>
</div>


<h2 class="wp-block-heading">Get the Active Post Publish Date in WordPress</h2>



<p>To retrieve the Publish Date of the current queried post in WordPress, use this as an example:</p>



<pre><code class="language-php">$postDate = get_the_date();

//printing the active post date with WP setting's format:
echo $postDate;</code></pre>



<p>To <strong>specify the date format</strong>, use this example <strong>for Active Post</strong>:</p>



<pre><code class="language-php">//Storing a few possible date formats in an array:
$postDateFormats = [
            'F j, Y', // ex: September 1, 2022
            'jS M Y', // ex: 1st Sep 2022
            'Y/m/d g:i:s A', // ex: 2022/09/01 6:09:06 AM
            'Y/m/d \a\t g:i A', // ex: 2022/09/01 at 6:09 AM
            'Y/m/d g:i:s A', // ex: 2022/09/01 6:09:06 AM
            'c', // ex: 2022-09-01T06:09:06-04:00(ISO format for schema)
            'r', // ex: Thu, 01 Sep 2022 06:09:06 -0400 (RFC 2822)
            'u', // ex:  1662027259 (Unix timestamp)
];

//print post date using them in different lines:
foreach($postDateFormats as $format){
	echo get_the_date($format)." <br />";
}</code></pre>



<p>The above example <strong>used a loop to go through each post format</strong> and print the date.</p>



<p>You can <strong>select one of them</strong> and use it; for example, to use <code>September 1, 2022</code> output format, use:  <code>get_the_date('F j, Y')</code>.</p>



<h2 class="wp-block-heading">Get the Post Publish Date for Specified Post ID in WordPress</h2>



<p>To specify the post ID, Use the second parameter of the <code>get_the_date</code> function.</p>



<p>For example, to get the publish date for a post with <code>ID = 1</code>, Use this code:</p>



<pre><code class="language-php">$postId = 1;

$postDate = get_the_date('',$postId);

//printing the post date with WP setting's format:
echo $postDate;</code></pre>



<p>To <strong>specify the date format and the Post ID at the same time</strong>, use this example (we used post ID = 1):</p>



<pre><code class="language-php">//define post ID you want the date for:
$postId = 1;

//Storing a few possible date formats in an array:
$postDateFormats = [
            'F j, Y', // ex: September 1, 2022
            'jS M Y', // ex: 1st Sep 2022
            'Y/m/d g:i:s A', // ex: 2022/09/01 6:09:06 AM
            'Y/m/d \a\t g:i A', // ex: 2022/09/01 at 6:09 AM
            'Y/m/d g:i:s A', // ex: 2022/09/01 6:09:06 AM
            'c', // ex: 2022-09-01T06:09:06-04:00(ISO format for schema)
            'r', // ex: Thu, 01 Sep 2022 06:09:06 -0400 (RFC 2822)
            'u', // ex:  1662027259 (Unix timestamp)
];

//print post date using them in different lines:
foreach($postDateFormats as $format){
	echo get_the_date($format, $postId)." <br />";
}</code></pre>



<p>The above example <strong>used a loop to go through each post format</strong> and <strong>print the date for the specified post</strong>.</p>



<p>You can <strong>select one of them</strong> and use it; for <code>September 1, 2022</code> output format, use:  <code>get_the_date('F j, Y', $postId)</code>.</p>



<h2 class="wp-block-heading">Printing the Post Publish Date Using a Shortcode</h2>



<p>To print the publish date with a shortcode, first, we have to define the shortcode and then use it in the WordPress editor.</p>



<h3 class="wp-block-heading">Step 1: Register the <code>[my-post-date]</code> Shortcode in WordPress</h3>



<p>open the <code>functions.php</code> file of your active theme or your custom-made plugin main PHP file, and copy/paste this snippet into it:</p>





<h3 class="wp-block-heading">Step 2: Use the <code>[my-post-date]</code> Shortcode in WordPress</h3>



<p>Open a post or create a new one. in the editor, just write <code>[my-post-date]</code> in the content part. This will print the active post date with the default format on that post page.</p>



<p>If you want to print the date in a special format, use the <code>post-format</code> attribute for the shortcode. (Ex: <code>[my-post-date date-format='F j, Y']</code>)</p>



<p>If you want to print the date for a specific post ID, use the <code>post-id</code> attribute for the shortcode. (Ex: <code>[my-post-date date-format='F j, Y' post-id=1]</code>)</p><p>The post <a href="https://mehdinazari.com/get-post-date-special-date-formats-wordpress/">How to Get Post Date with Custom Format in WordPress [Shortcode]</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/get-post-date-special-date-formats-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Check if the Current Page is a Post in WordPress</title>
		<link>https://mehdinazari.com/check-if-current-page-is-single-post-wordpress/</link>
					<comments>https://mehdinazari.com/check-if-current-page-is-single-post-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Mon, 29 Aug 2022 15:25:46 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=967</guid>

					<description><![CDATA[<p>WP developers use the is_single function to detect regular WordPress posts on the current user&#8217;s browser. For example, to check if the current page is an article (WordPress post), look for the is_single function to return a true value in a PHP condition. This function also can do more! Read this comprehensive article to learn [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/check-if-current-page-is-single-post-wordpress/">How to Check if the Current Page is a Post in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>WP developers use the is_single function to detect regular WordPress posts on the current user&#8217;s browser. For example, to check if the current page is an article (WordPress post), look for the is_single function to return a true value in a PHP condition. This function also can do more! Read this comprehensive article to learn about the is_single function and its usage.</p>



<span id="more-967"></span>



<h2 class="wp-block-heading">What WordPress Function is Responsible for Checking if the Current Page is a Single Post?</h2>



<p>The <a href="https://developer.wordpress.org/reference/functions/is_single/" target="_blank" rel="noreferrer noopener">WordPress <code>is_single</code> function</a> can determine a post&#8217;s page in an active visitor&#8217;s browser.</p>



<p>Using the <code>is_single</code> function, you can execute blocks of codes <strong>only if the current page is a single page</strong> (post page) in WordPress.</p>



<p>This function returns a <strong>true value if the current page is a post of any type</strong> (default and custom types).</p>



<p>Look for a <strong>false value if the current user is on a &#8220;page&#8221;</strong> (not a wp post = false value).</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Note: <code>is_single()</code> will be true for attachments (usually). detect attachments, use <code>is_attachment()</code> to be sure.</p>
</blockquote>



<h2 class="wp-block-heading"><code>is_single</code> function syntax</h2>



<p>This WP function <strong>accepts an optional parameter</strong> <code>$post</code>.</p>



<p>If you want to <strong>check if the current page displays a specific post</strong>, determine what post you want to check. <strong>You can use an integer value for a specific post ID</strong> or an <strong>array of Integers for multiple post IDs</strong>.</p>



<p>The <code>is_single</code> function also <strong>accepts string values</strong> for <code>$post</code> to <strong>check the post status by post title, slug</strong>, or an <strong>array containing these values</strong>.</p>





<p>Look at the below example to understand what this function is doing.</p>



<h2 class="wp-block-heading">Check if the current page is a single page using the <code>is_single</code> function</h2>



<p>We used the <code>is_single</code> function in three examples of different situations:</p>



<h3 class="wp-block-heading">Only check if the current user is on a post (just check if it&#8217;s a general WP post, ID is not necessary)</h3>



<p><strong><code>is_single()</code> with no argument</strong> will detect <strong>posts in general</strong>.</p>



<pre><code class="language-php">if(is_single()){
	echo "This is a Post of any type!";
}
else{
	echo "This is a NOT a Post!";
}</code></pre>



<h3 class="wp-block-heading">Check if the current user is on a specific post using Post ID</h3>



<p>If you <strong>specify an integer</strong> for <code>is_single()</code>, this function will accept it <strong>as a Post ID</strong>. </p>



<pre><code class="language-php">// int for post id, string for title and slug
$postId = 1;
if(is_single($postId)){
	echo "This is the Post you Specified!";
}
else{
	echo "This is a NOT the post, It can be another post, or not a post!";
}</code></pre>



<h3 class="wp-block-heading">Check if the current user is on a post that is one of the specified posts</h3>



<p>Specify an <strong>array containing mixed values of Post IDs, Slugs, and Titles</strong> to check if the current page does <strong>belong to one of them</strong>.</p>



<pre><code class="language-php">// int for post id, string for title and slug
$postsToCheck = array(1,"slug-here","the title of a post");
if(is_single($postsToCheck)){
	echo "This is one of Posts you Specified!";
}
else{
	echo "This is a NOT any of these posts, It can be another post, or not a post!";
}</code></pre><p>The post <a href="https://mehdinazari.com/check-if-current-page-is-single-post-wordpress/">How to Check if the Current Page is a Post in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/check-if-current-page-is-single-post-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Check if the Current Page is Search Page in WordPress</title>
		<link>https://mehdinazari.com/check-if-the-current-page-is-wordpress-search-page/</link>
					<comments>https://mehdinazari.com/check-if-the-current-page-is-wordpress-search-page/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Tue, 16 Aug 2022 13:17:04 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=962</guid>

					<description><![CDATA[<p>WordPress developers can detect Search Page using the is_search function. is_search function detects if the current page in the user browser is the website search page or not. The result of running the is_search is a Boolean, and it accepts no parameters. Let&#8217;s try this function with an example. Check if the current page is [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/check-if-the-current-page-is-wordpress-search-page/">How to Check if the Current Page is Search Page in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>WordPress developers can detect Search Page using the is_search function. is_search function detects if the current page in the user browser is the website search page or not. The result of running the is_search is a Boolean, and it accepts no parameters. Let&#8217;s try this function with an example.</p>



<span id="more-962"></span>



<h2 class="wp-block-heading">Check if the current page is a Search Page using the <code>is_search</code> function</h2>



<p>Since WordPress v1.5.0, developers can execute the <a href="https://developer.wordpress.org/reference/functions/is_search/" target="_blank" rel="noreferrer noopener"><code>is_search</code> function</a> to determine if the current user is viewing the search page or not.</p>



<p>This function checks if the global wp_query is for a search or not, which helps you detect the search page of WordPress.</p>



<h3 class="wp-block-heading"><code>is_search</code> function syntax</h3>



<p>This function does not accept any parameter and returns true if a search query is detected on the current page.</p>



<pre><code class="language-php">is_search()</code></pre>



<h3 class="wp-block-heading"><code>is_search</code> function example</h3>



<p>In this example, we&#8217;ll check if the current page in the browser is the WordPress search page.</p>



<p>&#8220;We looked at every article and found these results for you.&#8221; will be printed for the visitor If the search page is presented.</p>



<pre><code class="language-php">if(is_search()){
    echo "We looked at every article and found these results for you.";
}</code></pre>



<p>If you need to get the searched query, you can use <code>$_GET['s']</code> variable available from the current URL.</p>



<p>Example of printing searched query if it is the search page:</p>



<pre><code class="language-php">if(is_search() &amp;&amp; isset($_GET['s'])){
    echo "We looked at every article for `".$_GET['s']."` and found these results for you.";
}</code></pre><p>The post <a href="https://mehdinazari.com/check-if-the-current-page-is-wordpress-search-page/">How to Check if the Current Page is Search Page in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/check-if-the-current-page-is-wordpress-search-page/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Change or Remove ‘Howdy Admin’ in WordPress Toolbar</title>
		<link>https://mehdinazari.com/change-howdy-admin-wp/</link>
					<comments>https://mehdinazari.com/change-howdy-admin-wp/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Tue, 16 Aug 2022 12:27:39 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Admin Panel]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=1741</guid>

					<description><![CDATA[<p>If you constantly use the WordPress admin panel, you must have noticed the &#8216;Howdy Admin&#8217; text on the screen&#8217;s top right corner. Because of the fixed position toolbar, this text is always visible everywhere you go. In this helpful tutorial for the developers who embrace the attention to detail, I&#8217;m going to show how you [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/change-howdy-admin-wp/">How to Change or Remove ‘Howdy Admin’ in WordPress Toolbar</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>If you constantly use the WordPress admin panel, you must have noticed the &#8216;Howdy Admin&#8217; text on the screen&#8217;s top right corner. Because of the fixed position toolbar, this text is always visible everywhere you go. In this helpful tutorial for the developers who embrace the attention to detail, I&#8217;m going to show how you can modify or remove this text from the WP panel with a WP filter hook, so you are not forced to read it any time you log in.</p>



<span id="more-1741"></span>



<p>Not every WordPress administrator has noticed the ugly text on the top right corner of the WP admin panel, even if it&#8217;s an odd text and has a fixed position on the screen.</p>



<p>I guess this text does not bother everybody, but I have a solution for those who do not like this way of WordPress greeting admins.</p>



<h2 class="wp-block-heading">Change the WordPress ‘Howdy Admin’ text to what you desire</h2>



<p>A filter hook in WordPress can modify the admin bar menu.</p>



<p>The <code>admin_bar_menu</code> filter hook has the ability to modify or remove items in the admin panel bar of WordPress.</p>



<p>Use this code in your <code>functions.php</code> of your active theme or your custom-made plugin:</p>



<pre><code class="language-php">add_filter('admin_bar_menu', 'change_howdy_in_toolbar', 20);
function change_howdy_in_toolbar($wp_admin_bar){
    //set your desired text to replace
    $replaceWithThis = "Hi Admin";

    //we need to modify my-account node in the toolbar
    //'id' key is flag for replace action
    $node = array(
        'id' =&gt; 'my-account',
        'title' =&gt; $replaceWithThis
    );

    //add_node will REPLACE the title
    $wp_admin_bar-&gt;add_node($node);
}</code></pre>



<p>As you see in the comments above, we need to modify the my-account node in the toolbar.</p>



<p>If you are already familiar with WordPress filters, you know a filter gives you a variable to use when you are modifying WP core content.</p>



<p>This parameter in the <code>admin_bar_menu</code> filter is an instance of class <code>WP_Admin_Bar</code> that contains useful methods to add or modify content. we named it <code>$wp_admin_bar</code> like WP core function.</p>



<p><code>add_node()</code> method available in <code>$wp_admin_bar</code> can add or modify a node in admin toolbar.</p>



<p>Two useful methods available by this variable are <code>add_node</code> which can add or modify a node, and <code>remove_node</code>, used in deletion.</p>



<p><code>add_node()</code> method accepts an array of information to add as new node or modifies an existing node if the id key is used before.</p>



<h2 class="wp-block-heading">Remove the ‘Howdy Admin’ from the WordPress admin bar completely</h2>



<p>To remove the box and the text together from the admin bar, you can use this code in your <code>functions.php</code> of your active theme or your custom-made plugin:</p>



<pre><code class="language-php">add_filter('admin_bar_menu', 'remove_howdy_from_toolbar', 20);
function remove_howdy_from_toolbar($wp_admin_bar){
    $wp_admin_bar-&gt;remove_node('my-account');
}</code></pre><p>The post <a href="https://mehdinazari.com/change-howdy-admin-wp/">How to Change or Remove ‘Howdy Admin’ in WordPress Toolbar</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/change-howdy-admin-wp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Check if the Current Page is a Tag in WP (+Example)</title>
		<link>https://mehdinazari.com/check-if-the-current-page-is-a-tag-page-in-wordpress/</link>
					<comments>https://mehdinazari.com/check-if-the-current-page-is-a-tag-page-in-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Tue, 16 Aug 2022 09:46:22 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=961</guid>

					<description><![CDATA[<p>If the current page is a tag page in WordPress, the is_tag function will return a true value. The is_tag function accepts only one parameter. you can use that parameter to check if the current page is a specific tag. We&#8217;re going to review the is_tag function and its usage in an example. Check if [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/check-if-the-current-page-is-a-tag-page-in-wordpress/">How to Check if the Current Page is a Tag in WP (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>If the current page is a tag page in WordPress, the is_tag function will return a true value. The is_tag function accepts only one parameter. you can use that parameter to check if the current page is a specific tag. We&#8217;re going to review the is_tag function and its usage in an example.</p>



<span id="more-961"></span>



<h2 class="wp-block-heading">Check if the current page is a tag page, using the <code>is_tag</code> function</h2>



<p>Tag is one of WordPress&#8217;s default taxonomies, like categories, post formats, and many other classifications.</p>



<p>When a user visits an archive page, developers can detect if that page is a tag page by using <a href="https://developer.wordpress.org/reference/functions/is_tag/" target="_blank" rel="noreferrer noopener">the <code>is_tag</code> function</a> of WordPress.</p>



<h3 class="wp-block-heading"><code>is_tag</code> function syntax</h3>



<p>The syntax has everything you need to know about what it does and what it needs to get the information:</p>



<pre><code class="language-php">is_tag(int|string|int[]|string[] $tag = '')</code></pre>



<p><code>$tag</code> parameter is optional; if you do not specify it, <code>is_tag()</code> will return true for all tag pages.</p>



<p>You can check if the current page is a specified tag by declaring the target tag with ID, Name, or slug.</p>



<p><code>is_tag</code> function also can check if one page belongs to any of multiple declared targets with an array of IDs, Names, and slugs.</p>



<p>Keep reading for examples&#8230;</p>



<h2 class="wp-block-heading">Check if the current page is a tag page (not specified)</h2>



<p>To check if a page is a tag page (not specified tag, just tag page in general), you can just use this function in a condition as it is:</p>



<pre><code class="language-php">if(is_tag()){
	echo "This page is a tag page in general";
}</code></pre>



<h2 class="wp-block-heading">Check if the current page is a SPECIFIED tag</h2>



<p><code>is_tag</code> function accepts Integer for tag ID and String for tag name or slug.</p>



<p>in the next three examples, we&#8217;ll check the current page for a specified tag with ID, name, and slug:</p>



<h3 class="wp-block-heading">Using <code>is_tag</code> with tag id:</h3>



<p>Because tags are WP terms, tag id is the term_id of a tag (Integer).</p>



<p>In this example, We&#8217;ll check if the current page in the user&#8217;s browser is the tag with term_id = 5:</p>



<pre><code class="language-php">$targetTagId = 5; //Tag with term_id = 5
if(is_tag($targetTagId)){
	//this page is the exact tag

}
else{
	//this page is NOT the specified tag page
	//but it can be another tag, or not a tag page

}</code></pre>



<h3 class="wp-block-heading">Using <code>is_tag</code> with tag name:</h3>



<p><code>is_tag</code> function accepts a string to check the page for a tag with specified name (or slug).</p>



<pre><code class="language-php">$targetTagName = "My Tag"; //"My Tag" as tag name
if(is_tag($targetTagName)){
	//this page is the exact tag

}
else{
	//this page is NOT the specified tag page
	//but it can be another tag, or not a tag page

}</code></pre>



<h3 class="wp-block-heading">Using <code>is_tag</code> with tag slug:</h3>



<p>Slug is a little different from the name. Slug does not contain any spaces or capital letters in it.</p>



<p>In this example, we&#8217;ll check if the current page does blog to a tag with the &#8220;my-tag&#8221; slug:</p>



<pre><code class="language-php">$targetTagSlug = "my-tag"; //"my-tag" as tag slug
if(is_tag($targetTagSlug)){
	//this page is the exact tag

}
else{
	//this page is NOT the specified tag page
	//but it can be another tag, or not a tag page

}</code></pre>



<h2 class="wp-block-heading">Check if the current page belongs to one of the multiple tags</h2>



<p>WordPress developers can determine an array of mixed-type values to check if the current page belongs to one of them or not.</p>



<pre><code class="language-php">$targetTags = array(1, 'my-tag', 'My Tag');
if(is_tag($targetTags)){
	//this page belongs to one of these tags

}
else{
	//this page does NOT belong to any of these tags
	//but it can be another tag, or not a tag page

}</code></pre><p>The post <a href="https://mehdinazari.com/check-if-the-current-page-is-a-tag-page-in-wordpress/">How to Check if the Current Page is a Tag in WP (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/check-if-the-current-page-is-a-tag-page-in-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Check if the Current User is logged in WordPress</title>
		<link>https://mehdinazari.com/check-if-user-is-logged-in-wordpress/</link>
					<comments>https://mehdinazari.com/check-if-user-is-logged-in-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Tue, 16 Aug 2022 09:07:52 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=876</guid>

					<description><![CDATA[<p>To check if a user is logged in or not, we can use WordPress is_user_logged_in function. This function accepts no arguments and only checks the current user authentication status. the is_user_logged_in function returns a boolean value, true if the user is logged in, false if not. Be with me if you want to see this [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/check-if-user-is-logged-in-wordpress/">How to Check if the Current User is logged in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>To check if a user is logged in or not, we can use WordPress is_user_logged_in function. This function accepts no arguments and only checks the current user authentication status. the is_user_logged_in function returns a boolean value, true if the user is logged in, false if not. Be with me if you want to see this function in action.</p>



<span id="more-876"></span>



<h2 class="wp-block-heading">How to check if the current user is logged in when developing WordPress?</h2>



<p>WordPress introduced <code><a href="https://developer.wordpress.org/reference/functions/is_user_logged_in/" target="_blank" rel="noreferrer noopener">is_user_logged_in()</a></code> in version 2.0 to let developers determine if the current visitor is registered or is a guest.</p>



<h3 class="wp-block-heading"><code>is_user_logged_in</code> function syntax</h3>



<p>The function has clear syntax and does not accept any parameter so that you can use it directly in your conditions:</p>



<pre><code class="language-php">is_user_logged_in()</code></pre>



<p>The result of executing this function is a boolean value that replicates the visitor&#8217;s registration status.</p>



<p>The <code>is_user_logged_in()</code> uses <a href="https://developer.wordpress.org/reference/functions/wp_get_current_user/" target="_blank" rel="noreferrer noopener">wp_get_current_user()</a> under the hood. <br /><code>is_user_logged_in()</code> gets the user object from <code>wp_get_current_user()</code>, if the object exists, it returns true; otherwise, false.</p>



<h3 class="wp-block-heading"><code>is_user_logged_in</code> function usage</h3>



<p>In this example, we&#8217;ll use the <code>is_user_logged_in()</code> to print an invitation to register on our website for visitors:</p>



<pre><code class="language-php">if(is_user_logged_in()) {
    echo 'You can use our features, because you are registered!';
}
else {
    echo 'welcome to our website, register to use our features!';
}</code></pre><p>The post <a href="https://mehdinazari.com/check-if-user-is-logged-in-wordpress/">How to Check if the Current User is logged in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/check-if-user-is-logged-in-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get the ID of Current Logged in User from WordPress!</title>
		<link>https://mehdinazari.com/get-the-current-user-id-wordpress/</link>
					<comments>https://mehdinazari.com/get-the-current-user-id-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Mon, 15 Aug 2022 15:33:44 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=1752</guid>

					<description><![CDATA[<p>Performing features of an interactive website requires the ID of the current interacting user. WordPress has a function responsible for getting the current user&#8217;s ID in W, which is helpful when it comes to developing interactive features for users. This tutorial is about retrieving the current user&#8217;s ID if the visitor is logged in. Introducing [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/get-the-current-user-id-wordpress/">How to Get the ID of Current Logged in User from WordPress!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Performing features of an interactive website requires the ID of the current interacting user. WordPress has a function responsible for getting the current user&#8217;s ID in W, which is helpful when it comes to developing interactive features for users. This tutorial is about retrieving the current user&#8217;s ID if the visitor is logged in.</p>



<span id="more-1752"></span>



<h2 class="wp-block-heading">Introducing <code>get_current_user_id</code> function</h2>



<p>Since WordPress v2.0.3, developers can use a dedicated function to retrieve the current user&#8217;s ID. Before that, they need to get the whole user object first, then extract the ID from it.</p>



<p><code>get_current_user_id</code>() function introduced to help developers write fewer lines of code when they want to retrieve the current user&#8217;s ID.</p>



<h3 class="wp-block-heading"><code>get_current_user_id</code> function syntax</h3>



<p>You do not need to specify anything for this function to get the current user&#8217;s ID. The function will detect the current user itself.</p>



<pre><code class="language-php">get_current_user_id()</code></pre>



<p>After execution, the <code>get_current_user_id()</code> returns the current user&#8217;s ID, or if the user is not logged in, it will return 0.</p>



<h3 class="wp-block-heading"><code>get_current_user_id</code> function example</h3>



<p>If this example, we&#8217;ll check the current user ID, and if it is equal to what we determined (ID 1), a text message will be printed on the screen:</p>





<h2 class="wp-block-heading">Another way to get the current user&#8217;s ID (Not Recommended for cleaner code)</h2>



<p>The <code>get_current_user_id()</code> function is running <code>wp_get_current_user()</code> under the hood. You can directly get the current user with all information, then try to extract the ID from the returned <code>WP_User</code> object.</p>



<p>For a cleaner code, you better use the <code>get_current_user_id()</code>.</p>



<p>If you are still interested, you can get the current user&#8217;s object from WP and then try to extract the ID from it using this code:</p>



<pre><code class="language-php">$targetUserId=1;

//get the current user as WP_User object
$currentUser = wp_get_current_user();

//check if current user is available with isset() and then check if it's our targeted user
if(isset($currentUser-&gt;ID) &amp;&amp; $currentUser-&gt;ID === $targetUserId){
	//current user id is matching our target user's id
	echo "Wellcome to our website, You are a special customer to us";
}</code></pre><p>The post <a href="https://mehdinazari.com/get-the-current-user-id-wordpress/">How to Get the ID of Current Logged in User from WordPress!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/get-the-current-user-id-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Detect WP Home Page [Default or Static Front Page]</title>
		<link>https://mehdinazari.com/check-if-the-current-page-is-home-page/</link>
					<comments>https://mehdinazari.com/check-if-the-current-page-is-home-page/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Mon, 15 Aug 2022 10:08:37 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=958</guid>

					<description><![CDATA[<p>Looking for a way to determine the WordPress Home Page when visitors are viewing it? Use the is_home or is_front_page functions in a PHP condition when you want to do stuff when the Current Page is WordPress Website Home Page. Check our example for the is_home and is_front_page functions; we&#8217;ve reviewed these functions and explained [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/check-if-the-current-page-is-home-page/">How to Detect WP Home Page [Default or Static Front Page]</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Looking for a way to determine the WordPress Home Page when visitors are viewing it? Use the is_home or is_front_page functions in a PHP condition when you want to do stuff when the Current Page is WordPress Website Home Page. Check our example for the is_home and is_front_page functions; we&#8217;ve reviewed these functions and explained their usage.</p>



<span id="more-958"></span>



<h2 class="wp-block-heading">Check if the current page is the WP home page (<code>is_home</code> vs <code>is_front_page</code>)</h2>



<p>The <a href="https://developer.wordpress.org/reference/functions/is_home/"><code>is_home</code> function</a> was introduced in WordPress v2.1 to help developers detect the Home Page when a user is visiting.</p>



<p>But it has a con; <code>is_home()</code> does not detect the main page of your website if you set a static front page in WordPress settings. use the <a href="https://developer.wordpress.org/reference/functions/is_front_page/"><code>is_front_page()</code> function</a> to detect the front page regardless of settings.</p>



<h3 class="wp-block-heading"><code>is_home</code> and <code>is_front_page</code> function syntax</h3>



<p>These two functions need no arguments, and they will return a Boolean value as the result.</p>



<pre><code class="language-php">is_home()</code></pre>



<pre><code class="language-php">is_front_page()</code></pre>



<h2 class="wp-block-heading">What is the difference between <code>is_home</code> and <code>is_front_page</code> functions in WordPress?</h2>



<p>From WordPress v2.1, the administrator can set a static page as the website&#8217;s front page; and also a &#8220;posts page&#8221; to show your website&#8217;s post list.</p>



<p><code>is_home</code>() function will return a false value when you set a static page for the WP front. In the case of setting a &#8220;posts page&#8221; in WP settings, this function will return true on that page.</p>



<p>This setting is available in WordPress <strong>Admin Panel -&gt; Settings -&gt; Reading</strong> page.</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="379" src="https://mehdinazari.com/wp-content/uploads/2022/08/wp-reading-settings-1024x379.jpg" alt="" class="wp-image-1893" srcset="https://mehdinazari.com/wp-content/uploads/2022/08/wp-reading-settings-1024x379.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2022/08/wp-reading-settings-300x111.jpg 300w, https://mehdinazari.com/wp-content/uploads/2022/08/wp-reading-settings-768x284.jpg 768w, https://mehdinazari.com/wp-content/uploads/2022/08/wp-reading-settings-800x296.jpg 800w, https://mehdinazari.com/wp-content/uploads/2022/08/wp-reading-settings.jpg 1260w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Set a static page for WordPress&#8217;s front page</figcaption></figure>
</div>


<p><code>is_front_page()</code> was introduced later to detect the wp front page regardless of settings.</p>



<p><code>is_home()</code> actually detects the WP home&#8217;s posts query. It means if you have a different page for your blog posts and you&#8217;ve set a static page for home, it will return a false value.</p>



<p><strong><code>is_home()</code> vs <code>is_front_page()</code>:</strong> is_home detects your posts page. is_front_page detects WordPress&#8217;s home page anyway.</p><p>The post <a href="https://mehdinazari.com/check-if-the-current-page-is-home-page/">How to Detect WP Home Page [Default or Static Front Page]</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/check-if-the-current-page-is-home-page/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Check if the Current Page is a Category in WordPress!</title>
		<link>https://mehdinazari.com/check-if-the-current-page-is-category-in-wordpress/</link>
					<comments>https://mehdinazari.com/check-if-the-current-page-is-category-in-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Sun, 14 Aug 2022 14:22:39 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=960</guid>

					<description><![CDATA[<p>Categories are actually WordPress terms under the hood, like tags and other classification entities. But there is a simple solution in WordPress to detect a category page. WordPress developers can use the is_category function to check if the current page is a category or not. This WP function accepts one argument. Using that argument, you [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/check-if-the-current-page-is-category-in-wordpress/">How to Check if the Current Page is a Category in WordPress!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Categories are actually WordPress terms under the hood, like tags and other classification entities. But there is a simple solution in WordPress to detect a category page. WordPress developers can use the is_category function to check if the current page is a category or not. This WP function accepts one argument. Using that argument, you can determine if the current page is a specific category page or one of the specified categories. We&#8217;re going to explain how to use the is_category function with a perfect example. Read this WordPress tutorial to learn how to check if a category is currently being displayed in a visitor&#8217;s browser.</p>



<span id="more-960"></span>



<h2 class="wp-block-heading">Check if the current page is a category using <code>is_category</code> function</h2>



<p>The <a href="https://developer.wordpress.org/reference/functions/is_category/" target="_blank" rel="noreferrer noopener"><code>is_category</code> function</a> can check if the current page is a category page or not.</p>



<p>The syntax has everything you need to know:</p>



<pre><code class="language-php">is_category(int|string|int[]|string[] $category = '')</code></pre>



<p>This function only accepts a single argument to specify the category (or categories) you want to check if the current page is presenting.</p>



<p>The <code>$category</code> can be a single value of type integer or string. If a single value is declared (not an array), WP will check if the current page is a category matching the given slug, name, or ID.</p>



<p>If you have multiple values, to check if the current page is a category matching any of the given array values, you can declare an array of IDs (integer), category names (string), or slugs (string). It is possible to use them mixed together.</p>



<p>Keep reading to find examples for each use case&#8230;</p>



<h2 class="wp-block-heading">Check if the current page is a category page (not specified)</h2>







<pre><code class="language-php">//just use the function with no argument
if(is_category()){
	//this page is a category page

}
else{
	//this page is NOT a category page

}</code></pre>



<h2 class="wp-block-heading">Check if the current page is a specified category</h2>



<p>Providing a single value of type Integer to String for the <code>is_category</code> function will result in checking the current page for a specified category.</p>



<h3 class="wp-block-heading">Check by category ID:</h3>



<p>Using integer value will result in checking the current page for a specific category by ID.</p>



<pre><code class="language-php">$categoryId = 7; //Category with term_id = 7
if(is_category($categoryId)){
	//this page is the exact category

}
else{
	//this page is NOT the specified category page
	//but it can be another category, or not a category page

}</code></pre>



<h3 class="wp-block-heading">Check by category slug:</h3>



<p>Developers can use String value to check the current page for a specific category by slug (or name in the next example).</p>



<p>In this example, we checked if the current query belongs to a category with a specific slug (uncategorized):</p>



<pre><code class="language-php">$categorySlug = "uncategorized";
if(is_category($categorySlug)){
	//this page is the exact category page

}
else{
	//this page is NOT the specified category page
	//but it can be another category, or not a category page

}</code></pre>



<h3 class="wp-block-heading">Check by category name:</h3>



<p>Category names can have spaces, and their letters are not forced lower case, which makes them different from slugs.</p>



<p>If you declare the category you want to check with a String, WP also will check the page for a category with the given name (besides slug).</p>



<p>In this example, we checked if the current query belongs to a category with a specific name (Uncategorized):</p>



<pre><code class="language-php">$categoryName = "Uncategorized";
if(is_category($categoryName)){
	//this page is the exact category page

}
else{
	//this page is NOT the specified category page
	//but it can be another category, or not a category page

}</code></pre>



<h2 class="wp-block-heading">Check if the current page is at least one of multiple categories</h2>



<p>We are declaring an array for the <code>is_category</code> function. Using this array of values (IDs, Names, or Slugs), WordPress will check if the current page is at least one of the specified categories.</p>



<p>You can use mixed-type values for the array. It means each array value will be checked by the <code>is_category</code> function individually. <strong>It returns a true value when encountering the FIRST match</strong>.</p>



<p>In this example, <code>is_category</code> determines if the current page is a category page matching one of the given array values (ID, slug, and name mixed together):</p>



<pre><code class="language-php">$categories = array(7, 'my-category-slug', 'My Category Name');
if(is_category($categories)){
	//this page belongs to one of these categories

}
else{
	//this page does NOT belong to any of these categories
	//but it can be another category, or not a category page

}</code></pre><p>The post <a href="https://mehdinazari.com/check-if-the-current-page-is-category-in-wordpress/">How to Check if the Current Page is a Category in WordPress!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/check-if-the-current-page-is-category-in-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Check if Post has a Specific Tag in WordPress</title>
		<link>https://mehdinazari.com/check-if-post-has-specific-tag-wordpress/</link>
					<comments>https://mehdinazari.com/check-if-post-has-specific-tag-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Sun, 14 Aug 2022 12:26:13 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=946</guid>

					<description><![CDATA[<p>To check if a post is in a tag or any of multiple tags, WP developers use the has_tag function. This function accepts two parameters to specify the tag and the post. You can execute functions when developing WordPress functionalities based on post tags using the returned boolean value by the WP has_tag function. My [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/check-if-post-has-specific-tag-wordpress/">How to Check if Post has a Specific Tag in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>To check if a post is in a tag or any of multiple tags, WP developers use the has_tag function. This function accepts two parameters to specify the tag and the post. You can execute functions when developing WordPress functionalities based on post tags using the returned boolean value by the WP has_tag function. My review for the WP has_tag function contains a practical example!</p>



<span id="more-946"></span>



<h2 class="wp-block-heading">The has_tag function: Checks if a Post has a Specific Tag or Tags</h2>



<p>Syntax of the <code>has_tag</code> function:</p>



<pre><code class="language-php">has_tag(string|int|array $tag='', int|object $post=null)</code></pre>



<p>As it is obvious from the syntax, the <code>has_tags()</code> function has the ability to determine if a specific tag or specified multiple tags are added to a post by the author.</p>



<p>Two optional parameters, <code>$tag</code> &amp; <code>$post</code>, are what this function asks you to return an exact boolean answer for your request.</p>



<p>The <code>$tag</code> can be String if you want to check the tag&#8217;s existence in a post with its slug or name.</p>



<p>Use Integer value for <code>$tag</code> if you have the ID of a tag and you want to check if it exists in a WP post.</p>



<p><strong><code>$tag</code> also can be an array</strong> containing multiple tag IDs, Slugs, or names. In case of encountering with array value for the <code>$tag</code> parameter, the <code>has_tag()</code> function will return a true value if any of the given tags are set for the specified post.</p>



<p>If the <code>$tag</code> parameter is not set for the <code>has_tag()</code> function, it will check if the post has any tags at all.</p>



<p>The <code>$post</code> parameter is also optional; this means developers can skip determining the post if they are targeting the current queried post.</p>



<p>For example, If you execute the <code>has_tag()</code> function in <code>single.php</code> file of the active theme, WP will check if the current post has any tags at all, and it will be true if the post has even one tag.</p>



<h2 class="wp-block-heading">Learn how to detect tags in a WP post with examples</h2>



<p>Either If you are looking for a way to check if a single tag exists in a WordPress post or if any of a collection of tags exists there, you can use the has_tag() function.</p>



<h3 class="wp-block-heading">Check if a post exists in a specific tag</h3>



<p>If you can provide a string value for tag slug or tag name or an integer value for tag ID, you just need to pass it to <code>has_tag</code> function.</p>



<p>In this example, I checked the existence of a tag with <code>tutorial-articles</code> slug in a post with ID 1.</p>



<pre><code class="language-php">//set post id (set NULL for the current queried post)
$postId = 1;

// use tag slug, tag name or term ID (int) to check existance
$tag = "tutorial-articles";

// check if tutorial-articles tag is set for the post
if(has_tag($tag, $postId)){
	//post exists, do stuff:
	echo "This post exists in the tag.";
}
else{
	echo "This post does NOT exist in the tag.";
}</code></pre>



<p>To check the existence of the tag in the current queried post, you can just skip declaring <code>$postId</code>, or make it <code>Null</code>.</p>



<h3 class="wp-block-heading">Check if a post exists in any of multiple tags</h3>



<p>If you have multiple tags to check the post&#8217;s existence in them, you can still use the has_tag function.<br />You just need to declare the <code>$tag</code> parameter as an <code>Array</code> of tag slugs, names, or tag IDs.</p>



<p>In the below example, I&#8217;ll check if the post with ID 1 exists in any of the given tag slugs.</p>



<pre><code class="language-php">//set post id (set NULL for the current queried post)
$postId = 1;

// check exitence of post in one of these array values
$tags = array("tutorial-articles", "top-tutorials", "recommended-articles");

// check if good-post tag is set for the post
if(has_tag($tags, $postId)){
	//post exists, do stuff:
	echo "This post does NOT exist in one of the given tags.";
}
else{
	echo "This post does exist in any of these tags.";
}</code></pre>



<p>The <code>$tags</code> variable that I declared can be an array of tag slugs, names (string), or IDs (integer).</p><p>The post <a href="https://mehdinazari.com/check-if-post-has-specific-tag-wordpress/">How to Check if Post has a Specific Tag in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/check-if-post-has-specific-tag-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Exclude Posts with a Word from WordPress Query</title>
		<link>https://mehdinazari.com/exclude-wordpress-posts-keyword-in-title/</link>
					<comments>https://mehdinazari.com/exclude-wordpress-posts-keyword-in-title/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 11 Aug 2022 13:37:52 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=1552</guid>

					<description><![CDATA[<p>Excluding posts by a word in the title from the WP posts query has a simple solution which I shared in this tutorial. This solution uses the `s` argument in the posts query, and it is easier than what you can imagine. Read this short WordPress tutorial to learn how developers exclude posts from queries [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/exclude-wordpress-posts-keyword-in-title/">How to Exclude Posts with a Word from WordPress Query</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Excluding posts by a word in the title from the WP posts query has a simple solution which I shared in this tutorial. This solution uses the `s` argument in the posts query, and it is easier than what you can imagine. Read this short WordPress tutorial to learn how developers exclude posts from queries by specifying a keyword in the title.</p>



<span id="more-1552"></span>



<p>These kinds of functionalities are the main reason that I Love WP <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p>If you are looking for a way to query WordPress posts, you better first read my tutorial on <a href="https://mehdinazari.com/wordpress-query-posts/" target="_blank" rel="noreferrer noopener">how to query WordPress posts</a>. Then you can continue this tutorial to learn how to exclude posts from a query by specifying a keyword.</p>



<h2 class="wp-block-heading">Exclude WordPress Posts from a Query by Keyword</h2>



<p>use <code>'s' =&gt; '-title'</code> in your arguments when you&#8217;re executing the <code>get_posts</code> function (replace title with your desired keyword). This way, you tell the WP to exclude all those posts from the <code>get_post</code> query.</p>



<pre><code class="language-php">$keywordToExclude = "change keyword here";
$args = array(
	's' =&gt; '-'.$keywordToExclude
);

//query posts
$posts = get_posts($args);

//print all posts without the keyword in title
foreach ($posts as $post){
	echo "Title: ".$post-&gt;post_title." <br />";
}</code></pre><p>The post <a href="https://mehdinazari.com/exclude-wordpress-posts-keyword-in-title/">How to Exclude Posts with a Word from WordPress Query</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/exclude-wordpress-posts-keyword-in-title/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get Users in WordPress (+Print Users List Shortcode)</title>
		<link>https://mehdinazari.com/list-users-in-wordpress-programmatically/</link>
					<comments>https://mehdinazari.com/list-users-in-wordpress-programmatically/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 11 Aug 2022 12:35:10 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=944</guid>

					<description><![CDATA[<p>WordPress get_users function retrieves users based on given filters and order. This function will return the list of users in an array. WP developers can use the given array to print a List of WordPress users in a shortcode. We&#8217;re going to review the get_users syntax, try the function usage, and create a shortcode to [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/list-users-in-wordpress-programmatically/">How to Get Users in WordPress (+Print Users List Shortcode)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>WordPress get_users function retrieves users based on given filters and order. This function will return the list of users in an array. WP developers can use the given array to print a List of WordPress users in a shortcode. We&#8217;re going to review the get_users syntax, try the function usage, and create a shortcode to print a list of users whenever we want!</p>



<span id="more-944"></span>



<h2 class="wp-block-heading">List users in WordPress using the <code>get_users</code> function  </h2>



<p>The result of executing the <a href="https://developer.wordpress.org/reference/functions/get_users/" target="_blank" rel="noreferrer noopener">WordPress <code>get_users</code> function</a> is an array of user IDs or objects.</p>



<p>This function is super flexible. WP <strong>developers can determine the type of returned value, fields, query filters, order</strong>, and a bunch of other stuff we&#8217;ll get into shortly by specifying an array of optional arguments.</p>



<h3 class="wp-block-heading"><code>get_users</code> function syntax</h3>



<p>This WordPress function receives an array of arguments to customize the result set for you.</p>



<pre><code class="language-php">get_users(array $args = array())</code></pre>



<p>As you can see, because <code>$args</code> has the default value of <code>array()</code>, <code>$args</code> is an optional parameter.</p>



<p>The optional <code>$args</code> parameter accepts a variety of options which I&#8217;ll explain after the example.</p>



<h3 class="wp-block-heading"><code>get_users</code> function example: Print list of all users in WP</h3>



<p>To print all users (including admin users) in an HTML list, use the below code:</p>



<pre><code class="language-php">$args = array(); //define arguments if you need
$users = get_users($args);

$listHtml = '&lt;ul&gt;';
foreach($users as $user){
	$listHtml .= '&lt;li&gt;'
	. 'ID: '.$user-&gt;data-&gt;ID."&lt;br /&gt;"
	. 'Username: '.$user-&gt;data-&gt;user_login."&lt;br /&gt;"
	. 'Nice Name: '.$user-&gt;data-&gt;user_nicename."&lt;br /&gt;"
	. 'Display Name: '.$user-&gt;data-&gt;display_name."&lt;br /&gt;"
	. 'Email: '.$user-&gt;data-&gt;user_email."&lt;br /&gt;"
	. 'URL (website): '.$user-&gt;data-&gt;user_url."&lt;br /&gt;"
	. 'Registration Date: '.$user-&gt;data-&gt;user_registered."&lt;br /&gt;"
	. '&lt;li&gt;';
}
$listHtml .= '&lt;/ul&gt;';

echo $listHtml;</code></pre>



<h3 class="wp-block-heading">How to set arguments for <code>get_users</code> function to sort and filter the result?</h3>



<p>The <code>get_users</code> function actually executes <code><a href="https://developer.wordpress.org/reference/classes/wp_user_query/" target="_blank" rel="noreferrer noopener">WP_User_Query</a></code> under the hood.</p>



<p>You can define arguments to query users based on your needs.</p>



<p>Here is the list of all possible arguments to set for the <code>get_users</code> function:</p>



<pre><code class="language-php">$args = array(
            'blog_id'             =&gt; 1,
            'role'                =&gt; '',
            'role__in'            =&gt; array(),
            'role__not_in'        =&gt; array(),
            'capability'          =&gt; '',
            'capability__in'      =&gt; array(),
            'capability__not_in'  =&gt; array(),
            'meta_key'            =&gt; '',
            'meta_value'          =&gt; '',
            'meta_compare'        =&gt; '',
            'include'             =&gt; array(),
            'exclude'             =&gt; array(),
            'search'              =&gt; '',
            'search_columns'      =&gt; array(),
            'orderby'             =&gt; 'login',
            'order'               =&gt; 'ASC',
            'offset'              =&gt; '',
            'number'              =&gt; '',
            'paged'               =&gt; 1,
            'count_total'         =&gt; true,
            'fields'              =&gt; 'all',
            'who'                 =&gt; '',
            'has_published_posts' =&gt; null,
            'nicename'            =&gt; '',
            'nicename__in'        =&gt; array(),
            'nicename__not_in'    =&gt; array(),
            'login'               =&gt; '',
            'login__in'           =&gt; array(),
            'login__not_in'       =&gt; array(),
        );</code></pre>



<p>Explaining above attributes:</p>



<ul class="wp-block-list">
<li><code>blog_id</code> -&gt; to set blog id (int), default is the current blog (do not need to set it for a normally installed WP)</li>



<li><code>role</code> -&gt; to get users with a specified role</li>



<li><code>role__in</code> -&gt; accepts array to get users of many roles (array values)</li>



<li><code>role__not_in</code> -&gt; accepts array to get users without specified roles (array values)</li>



<li>capability -&gt; to specify the capability of users you want to get</li>



<li><code>capability__in</code> -&gt; accepts array to get users with specified capabilities (array values)</li>



<li><code>capability__not_in</code> -&gt; accepts array to get users without specified capabilities (array values)</li>



<li><code>meta_key</code> -&gt; to filter users based on a meta information set on the user object (<code>meta_value</code> required)</li>



<li><code>meta_value</code> -&gt; to filter users based on value of the key defined in <code>meta_key</code></li>



<li><code>meta_compare</code> -&gt; to set the comparison operation to compare <code>meta_value</code> with provided data in the database for <code>meta_key</code> label</li>



<li><code>include</code> -&gt; to include an array of user IDs in the query</li>



<li><code>exclude</code> -&gt; to exclude an array of user IDs from the query</li>



<li><code>search</code> -&gt; to search users based on a keyword match in <code>search_columns</code></li>



<li><code>search_columns</code> -&gt; default value is empty. If left empty, <code>search</code> tries to determine the search column based on the search keyword. </li>



<li><code>orderby</code> -&gt; default is &#8216;login&#8217;, possible values: &#8216;ID&#8217;, &#8216;display_name&#8217;, &#8216;name&#8217;, &#8216;include&#8217;, &#8216;user_login&#8217; ,&#8217;login&#8217;, &#8216;login__in&#8217;, &#8216;user_email, &#8217;email&#8217; , &#8216;user_registered&#8217;, &#8216;registered&#8217;, &#8216;post_count&#8217;</li>



<li><code>order</code> -&gt; default direction is ASC, and you can change it to DESC for reverse order</li>



<li><code>offset</code> -&gt; Useful for list pagination. it receives an integer which determines how many users to skip before fetching the list from the database</li>



<li><code>number</code> -&gt; limit the number of users you want to retrieve</li>



<li><code>paged</code> -&gt; to determine if pagination is active for this query or not. Default is true.</li>



<li>count_total -&gt; default is true</li>



<li><code>fields</code> -&gt; to determine what field you need as a return. default is all. It can be a single field or an array of available user fields (ex: &#8216;ID&#8217;, &#8216;display_name&#8217;, &#8216;user_login&#8217;, &#8216;user_nicename&#8217;, &#8216;user_email&#8217;, &#8216;user_url&#8217;, &#8216;user_registered&#8217;, &#8216;user_pass&#8217;, &#8216;user_activation_key&#8217;, &#8216;user_status&#8217;)</li>



<li><code>who</code> -&gt; only possible value is ‘authors’. The other option is the default value which is all users.</li>



<li><code>has_published_posts</code> -&gt; to get only authors with published posts</li>



<li><code>nicename</code> -&gt; to filter users based on nice name</li>



<li><code>nicename__in</code> -&gt;it accepts an array to filter users based on a collection of nice names</li>



<li><code>nicename__not_in</code> -&gt; it accepts an array to exclude users based on a collection of nice names</li>



<li><code>login</code> -&gt; to get an specific user with specified username</li>



<li><code>login__in</code> -&gt; it accepts an array to filter users based on a collection of usernames</li>



<li><code>login__not_in</code> -&gt; it accepts an array to exclude users based on a collection of usernames</li>
</ul>



<h3 class="wp-block-heading">What information can I get from <code>WP_User</code> objects?</h3>



<p>WP_User object contains all information about a user in WordPress. Check out the below attributes to know if it fits your needs:</p>



<pre><code class="language-php">WP_User Object
	(
		[data] =&gt; stdClass Object
			(
				[ID]
				[user_login]
				[user_pass]
				[user_nicename]
				[user_email]
				[user_url]
				[user_registered]
				[user_activation_key]
				[user_status]
				[display_name]
			)
			
		[ID]
		[caps] =&gt; Array()
		[cap_key]
		[roles] =&gt; Array()
		[allcaps] =&gt; Array()
		[filter]
	)
</code></pre>



<p>The <code>data</code> attribute contains all printable information about the user.</p>



<p>The <code>caps</code>, <code>cap_key</code>, <code>roles</code>, and <code>allcaps</code> are the attributes you are looking for if you want to work with WordPress ACL and user permissions. the <code>allcaps</code> is detailed user access to WordPress functionalities.</p>



<h2 class="wp-block-heading">List users in WP editor using a shortcode</h2>



<h3 class="wp-block-heading">Defining a new shortcode to print all users</h3>



<p>Shortcodes are an amazing part of WP development.</p>



<p>Shortcodes are the easiest way to use dynamic content between your regular text when editing WP posts.</p>



<p>In this example, I&#8217;ll create a function out of previous code that you hopefully tested. I&#8217;ll call it <code>my_custom_users_list()</code>.</p>



<p>Then I&#8217;ll hook a shortcode to the function, so every time the shortcode is presented in a post&#8217;s content, It will print a list of registered users on your website.</p>



<p><strong><s>-&gt;</s></strong> Add this code to <code>functions.php</code> file of your active template:</p>



<pre><code class="language-php">//first check if my_custom_users_list is defined before or not.
if(!function_exists('my_custom_users_list')){
	//function that runs when shortcode is called
	function my_custom_users_list() {
		$args = array(); //define arguments if you need
		$users = get_users($args);

		$listHtml = '&lt;ul&gt;';
		foreach($users as $user){
			$listHtml .= '&lt;li&gt;'
			             . 'ID: '.$user-&gt;data-&gt;ID."&lt;br /&gt;"
			             . 'Username: '.$user-&gt;data-&gt;user_login."&lt;br /&gt;"
			             . 'Nice Name: '.$user-&gt;data-&gt;user_nicename."&lt;br /&gt;"
			             . 'Display Name: '.$user-&gt;data-&gt;display_name."&lt;br /&gt;"
			             . 'Email: '.$user-&gt;data-&gt;user_email."&lt;br /&gt;"
			             . 'URL (website): '.$user-&gt;data-&gt;user_url."&lt;br /&gt;"
			             . 'Registration Date: '.$user-&gt;data-&gt;user_registered."&lt;br /&gt;"
			             . '&lt;/li&gt;';
		}
		$listHtml .= '&lt;/ul&gt;';

		return $listHtml;
	}

}

//register my-users-list shortcode
function register_my_users_list_shortcode(){
	add_shortcode('my-users-list', 'my_custom_users_list');
}
add_action( 'init', 'register_my_users_list_shortcode' );

//to test the shortcode, uncomment next line:
/*echo do_shortcode('[my-users-list]');*/</code></pre>



<h3 class="wp-block-heading">Using the shortcode inside WP editor or <code>do_shortcode</code> function</h3>



<p>To use this custom-made shortcode, you can add [my-users-list] in the WordPress editor while editing a post or page (or whatever).</p>



<p>If you want to use this function in PHP code, you can use:</p>



<pre><code class="language-php">echo do_shortcode('[my-users-list]');</code></pre><p>The post <a href="https://mehdinazari.com/list-users-in-wordpress-programmatically/">How to Get Users in WordPress (+Print Users List Shortcode)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/list-users-in-wordpress-programmatically/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get Post Format by Post ID in WordPress</title>
		<link>https://mehdinazari.com/retrieve-a-post-format-wordpress/</link>
					<comments>https://mehdinazari.com/retrieve-a-post-format-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 11 Aug 2022 11:25:12 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=935</guid>

					<description><![CDATA[<p>Check out this WordPress tutorial if you want to learn how to retrieve the format of a post using a post ID. WordPress has a great function for post format detection; it calls get_post_format. We&#8217;re going to review this function in a Practical example. The get_post_format function is responsible to retrieve the format of a [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/retrieve-a-post-format-wordpress/">How to Get Post Format by Post ID in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Check out this WordPress tutorial if you want to learn how to retrieve the format of a post using a post ID. WordPress has a great function for post format detection; it calls get_post_format. We&#8217;re going to review this function in a Practical example.</p>



<span id="more-935"></span>



<p>The <a href="https://developer.wordpress.org/reference/functions/get_post_format/"><code>get_post_format</code> function</a> is responsible to retrieve the format of a WP post. This functionality has been added to WordPress since version 3.1.</p>



<h2 class="wp-block-heading">get_post_format function syntax</h2>



<p>This is the syntax when you want to use the <code>get_post_format</code> function of WordPress (keep reading for the practical example):</p>



<pre><code class="language-php">get_post_format(int|WP_Post|null $post = null)</code></pre>



<p>If you do not specify the optional <code>$post</code> parameter for this function, or you just pass <code>null</code>, <code>get_post_format</code> will retrieve the post format of the current queried WP post (current post in the loop or in the <code>single.php</code> file).</p>



<h2 class="wp-block-heading">Example of using the get_post_format function to retrieve a post&#8217;s format in WP</h2>



<p>We have specified the ID of the post in <code>$postId</code> variable. We used <code>1</code> as the post ID, you can change it to any post ID you need or do not specify it for the current queried post (the default value for <code>$post</code> parameter is null).</p>



<pre><code class="language-php">$postId = 1;
$postFormat = get_post_format($postId);
if($postFormat)
	echo $postFormat;</code></pre>



<h2 class="wp-block-heading">WordPress default Post Formats</h2>



<p>WP has its own post formats; also, <strong>developers can add new post formats</strong> with specifications they desire.</p>



<p>If you did not add any new post formats to WordPress, either by installing third-party plugins or your own codes, This is the list of possible formats (as a &#8220;string&#8221; that represents the name of the format):</p>



<ul class="wp-block-list">
<li>aside</li>



<li>chat</li>



<li>gallery</li>



<li>link</li>



<li>image</li>



<li>quote</li>



<li>status</li>



<li>video</li>



<li>audio</li>
</ul>



<p>If you try the function on a not -freshly installed WordPress, you may get other formats too.</p><p>The post <a href="https://mehdinazari.com/retrieve-a-post-format-wordpress/">How to Get Post Format by Post ID in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/retrieve-a-post-format-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Remove a User Role from WordPress (with example)</title>
		<link>https://mehdinazari.com/remove-role-from-wordpress/</link>
					<comments>https://mehdinazari.com/remove-role-from-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 21:31:59 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=981</guid>

					<description><![CDATA[<p>remove_role function in WordPress has a simple syntax. remove_role only gets a role name and if it exists, this function will remove the role from WordPress. We&#8217;re going to remove the &#8220;Contributor&#8221; role from our WordPress for an example. What are user roles in WordPress? As you must know, every user registers with a user [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/remove-role-from-wordpress/">How to Remove a User Role from WordPress (with example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>remove_role function in WordPress has a simple syntax. remove_role only gets a role name and if it exists, this function will remove the role from WordPress. We&#8217;re going to remove the &#8220;Contributor&#8221; role from our WordPress for an example.</p>



<span id="more-981"></span>



<h2 class="wp-block-heading">What are user roles in WordPress?</h2>



<p>As you must know, every user registers with a user role in WordPress.</p>



<p>WordPress has a few default user roles with different capabilities:</p>



<ul class="wp-block-list">
<li>Super Admin</li>



<li>Administrator</li>



<li>Editor</li>



<li>Author</li>



<li>Contributor</li>



<li>Subscriber</li>
</ul>



<p>User roles are essential for developing a legitimate ACL (read more about <a href="https://en.wikipedia.org/wiki/Access-control_list" target="_blank" rel="noreferrer noopener">ACL on Wikipedia</a>).</p>



<p>Developers most of the time give access to a specific user role to modify data or run functionalities in the admin panel.</p>



<p>Not every user must have access to moderation functionalities, so WordPress introduced user roles to control user access.</p>



<p>If you are the first user of your WP, you are most likely a Super Admin.</p>



<p>You can create other users by using the admin panel or through public user registration.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Super Admin can set the &#8220;New User Default Role&#8221; in <code>Settings-&gt;General</code> page inside the admin panel.</p>
</blockquote>



<h2 class="wp-block-heading">How can I remove a user role in WordPress?</h2>



<p>If you want to remove a WordPress default user role or a role you&#8217;ve created yourself, you can use the <code>remove_role</code> function.</p>



<h3 class="wp-block-heading">remove_role function syntax</h3>



<p>The <code>remove_role</code> function will remove a role only with a role name. The only parameter the function gets is <code>$role</code>.</p>



<pre><code class="language-php">remove_role($role)</code></pre>



<p>the <code>$role</code> parameter is a string value for a role name, the only variable needed to delete a WordPress role.</p>



<h3 class="wp-block-heading">remove_role function example</h3>



<p>For example, we&#8217;re going to remove the &#8220;Contributor&#8221; role from WordPress:</p>



<pre><code class="language-php">$role = "contributor";
remove_role($role)</code></pre>



<p>Above will work in <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">a custom WordPress plugin</a> or inside the <code>functions.php</code> file of your current theme.</p>



<p>If you do not know how to <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">create a WordPress plugin</a>, I recommend you read my tutorial:</p>



<p><a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">How to create a Hello World plugin for WordPress in 3 Steps</a></p><p>The post <a href="https://mehdinazari.com/remove-role-from-wordpress/">How to Remove a User Role from WordPress (with example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/remove-role-from-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Check if a Post Exists in WordPress (+Example)</title>
		<link>https://mehdinazari.com/check-if-post-exists-in-wordpress/</link>
					<comments>https://mehdinazari.com/check-if-post-exists-in-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 21:30:18 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=978</guid>

					<description><![CDATA[<p>WordPress has many ways to check a post&#8217;s existence by ID, title, content, date, ETC. get_post and post_exists are two useful functions in WordPress collection that can help developers check the existence of any post. Let&#8217;s review these two functions and try their usage. Check if a post exists by the Post ID get_post function: [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/check-if-post-exists-in-wordpress/">How to Check if a Post Exists in WordPress (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>WordPress has many ways to check a post&#8217;s existence by ID, title, content, date, ETC. get_post and post_exists are two useful functions in WordPress collection that can help developers check the existence of any post. Let&#8217;s review these two functions and try their usage.</p>



<span id="more-978"></span>



<h2 class="wp-block-heading">Check if a post exists by the Post ID</h2>



<h3 class="wp-block-heading">get_post function: Not the most perfect option</h3>



<p><a href="https://developer.wordpress.org/reference/functions/get_post/" target="_blank" rel="noreferrer noopener">The <code>get_post</code> function</a> is useful when you want to check whether a post exists, but it is not the most optimized option.</p>



<p><code>!is_null( get_post($postId)</code> is working when you want to make sure a post with an ID exists in WordPress:</p>



<pre><code class="language-php">$postId = 1;
if(!is_null(get_post($postId)){
    //post exists!

}</code></pre>



<p>I wrote a <a href="https://mehdinazari.com/wordpress-query-posts/">tutorial about the get_post function</a> a while ago, you can read the article to learn how to work with this function deeper:</p>



<p><a href="https://mehdinazari.com/wordpress-query-posts/">WordPress Query Posts by Category, Tag, Custom attribute, and more!</a></p>



<p>But I told you it&#8217;s not the best idea to use the <code>get_post</code> function to check if a post exists or not.</p>



<p>Continue reading this article for better options to use when you want to check if a post exists by ID.</p>



<h3 class="wp-block-heading">get_post_status function: Better choice due to less resource usage</h3>



<p>I recommend using the <a href="https://developer.wordpress.org/reference/functions/get_post_status/" target="_blank" rel="noreferrer noopener"><code>get_post_status</code> function</a> to check if a post exists in WordPress or not.</p>



<pre><code class="language-php">$postId = 1;
if(get_post_status($postId)) {
    //post exists!

}</code></pre>



<h2 class="wp-block-heading">post_exists function: Check post existence by title, content, date</h2>



<p>The most used WordPress function for post existence status is <a href="https://developer.wordpress.org/reference/functions/post_exists/" target="_blank" rel="noreferrer noopener">the <code>post_exists</code> function</a>.</p>



<h3 class="wp-block-heading">post_exists function syntax</h3>



<p>This function determines if a post is existed by title, content, date, type, and status.</p>



<p>If the <code>post_exists</code> function finds any post matching specified options; It&#8217;ll return the post ID.</p>



<pre><code class="language-php">post_exists($title, $content = '', $date = '', $type = '', $status = '')</code></pre>



<p><code>$title</code> is required, but other parameters are optional.</p>



<h3 class="wp-block-heading"><code>post_exists</code> usage example</h3>



<p>In the below example, I tried checking if a post with the title &#8220;A title to test&#8221; exists or not:</p>



<pre><code class="language-php">$findPostByTitle = "A title to test";
if(post_exists($findPostByTitle)){
    //post exists!

}</code></pre><p>The post <a href="https://mehdinazari.com/check-if-post-exists-in-wordpress/">How to Check if a Post Exists in WordPress (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/check-if-post-exists-in-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get Plugin Directory Path in WordPress (+Example)</title>
		<link>https://mehdinazari.com/get-plugin-directory-path-wordpress/</link>
					<comments>https://mehdinazari.com/get-plugin-directory-path-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 21:29:22 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=975</guid>

					<description><![CDATA[<p>Referring to a directory can sometimes be challenging! to fix this issue WordPress has many functions to retrieve correct directory paths for developers. one of the functions is plugin_dir_path which is responsible for retrieving the current plugin directory inside WordPress. When it comes to including multiple files inside a plugin, the plugin_dir_path function becomes super [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/get-plugin-directory-path-wordpress/">How to Get Plugin Directory Path in WordPress (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Referring to a directory can sometimes be challenging! to fix this issue WordPress has many functions to retrieve correct directory paths for developers. one of the functions is <code>plugin_dir_path</code> which is responsible for retrieving the current plugin directory inside WordPress.</p>



<span id="more-975"></span>



<p>When it comes to including multiple files inside a plugin, the <code>plugin_dir_path</code> function becomes super helpful.</p>



<p>It&#8217;s popular for WordPress developers to use the <code>plugin_dir_path</code> function for including PHP files into each other.</p>



<h2 class="wp-block-heading">Get Plugin Directory Path Using plugin_dir_path Function</h2>



<p><a href="https://developer.wordpress.org/reference/functions/plugin_dir_path/" target="_blank" rel="noreferrer noopener">The <code>plugin_dir_path</code> function in WordPress</a> is available if you need a complete path to your plugin&#8217;s directory.</p>



<h3 class="wp-block-heading"><code>plugin_dir_path</code> function syntax</h3>



<p>The function syntax is pretty easy:</p>



<pre><code class="language-php">plugin_dir_path($file)</code></pre>



<p><code>$file</code> parameter&#8217;s value must be a string.</p>



<p>I saw lots of developers using the <code>dirname(__FILE__)</code> value for <code>$file</code> in the main file of their plugins.</p>



<p>Keep reading; We&#8217;ll try the most common usage of <code>plugin_dir_path</code> function in an example:</p>



<h3 class="wp-block-heading">Using <code>plugin_dir_path</code> function to get the plugin directory path</h3>



<p>Using this code inside your custom plugin is useful.</p>



<p>To make it possible for us to use our main plugin directory in a variable everywhere, we can <code>define</code> It with PHP:</p>



<pre><code class="language-php">define('MY_CUSTOM_PLUGIN_DIR', plugin_dir_path(dirname( __FILE__ )));</code></pre>



<p>Remember that this code works in the main file of a plugin.</p>



<p>For future usage of defining <code>MY_CUSTOM_PLUGIN_DIR</code>, I have an example for you:</p>



<pre><code class="language-php">$cssUrl = MY_CUSTOM_PLUGIN_DIR . '/css/plugin-style.css';</code></pre>



<p>You can use the defined variable everywhere you want inside your plugin.</p>



<p>Also, you can <a href="https://mehdinazari.com/get-wordpress-root-path/" title="2 Simple Ways to Get WordPress Root Path">get the path to the WordPress root directory</a> with the <code>get_home_path</code> function if needed (or <code>ABSPATH</code> constant). Sometimes it&#8217;s a better option to use instead of <code>plugin_dir_path</code> function.</p>



<p>If you are not familiar with the process of creating a WordPress plugin, you better read my tutorial:</p>



<p><a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">How to create a Hello World plugin for WordPress in 3 Steps</a></p>



<p>To keep more into it, you can read the <a href="https://developer.wordpress.org/reference/functions/plugin_dir_path/">plugin_dir_path function code reference on the WordPress official website</a> for developers.</p><p>The post <a href="https://mehdinazari.com/get-plugin-directory-path-wordpress/">How to Get Plugin Directory Path in WordPress (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/get-plugin-directory-path-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to List All Authors in WordPress (Shortcode Included!)</title>
		<link>https://mehdinazari.com/how-to-list-all-authors-in-wordpress-using-code/</link>
					<comments>https://mehdinazari.com/how-to-list-all-authors-in-wordpress-using-code/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 21:27:13 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=973</guid>

					<description><![CDATA[<p>In this WordPress tutorial, We&#8217;ll list all authors using the wp_list_authors function. You can use this WordPress functionality in different scenarios. To make this function more useful, we&#8217;ll create a shortcode for printing all authors. wp_list_authors function syntax Listing authors in WordPress is possible by using the wp_list_authors function. There was a list_authors function available [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/how-to-list-all-authors-in-wordpress-using-code/">How to List All Authors in WordPress (Shortcode Included!)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>In this WordPress tutorial, We&#8217;ll list all authors using the wp_list_authors function. You can use this WordPress functionality in different scenarios. To make this function more useful, we&#8217;ll create a shortcode for printing all authors.</p>



<span id="more-973"></span>



<h2 class="wp-block-heading">wp_list_authors function syntax</h2>



<p>Listing authors in WordPress is possible by using <a href="https://developer.wordpress.org/reference/functions/wp_list_authors/" target="_blank" rel="noreferrer noopener">the <code>wp_list_authors</code> function</a>.</p>



<p>There was a <code>list_authors</code> function available in WordPress too, but it is deprecated from the WordPress version 2.1.0!</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>WordPress recommends that you use <code>wp_list_authors</code> instead of <code>list_authors</code>.</p>
</blockquote>



<pre><code class="language-php">wp_list_authors($args = "")</code></pre>



<p>the <code>$args</code> parameter can be an array or string. You can specify arguments to customize the result based on your needs.</p>



<h3 class="wp-block-heading">What can be inside the $args array for wp_list_authors function?</h3>



<ul class="wp-block-list">
<li><strong>orderby</strong>: determines what is the order based on. possible values are: &#8216;nicename&#8217;, &#8216;ID&#8217;, &#8217;email&#8217;, &#8216;url&#8217;, &#8216;registered&#8217;, &#8216;user_nicename&#8217;, &#8216;user_email&#8217;, &#8216;user_url&#8217;, &#8216;user_registered&#8217;, &#8216;name&#8217;, &#8216;display_name&#8217;, &#8216;post_count&#8217;, &#8216;meta_value&#8217;, &#8216;user_login&#8217;.</li>



<li><strong>order</strong>: sets order direction. it can be one these two values: ASC or DESC.</li>



<li><strong>number</strong>: sets limit for authours you want to get or print. value must be an integer. if you do not set this, the function will use all authors.</li>



<li><strong>optioncount</strong>: displays how many posts this author has. value can be true or false (default: false).</li>



<li><strong>exclude_admin</strong>: exclude admin users from the list. value can be true or false (default: true). </li>



<li><strong>show_fullname</strong>: determines if fullname must be displayed or not. value can be true or false (default: false).</li>



<li><strong>hide_empty</strong>: it tells WP to exclude authors with no posts. value can be true or false (default: true).</li>



<li><strong>feed</strong>: displays a text link to authors feed. value must be string.</li>



<li><strong>feed_image</strong>: displays an image link to authors feed. value must be string.</li>



<li><strong>feed_type</strong>: sets the type of feed we want to display. value can be &#8216;rss2&#8217;, &#8216;atom&#8217;.</li>



<li><strong>echo</strong>: requests the print action for this function. value can be true or false. if it sets to true, you do not need to use php echo function (default: true).</li>



<li><strong>style</strong>: If value sets to <code>list</code>, authors will be inside a <code>&lt;li&gt;</code> tag, other values will generate comma separated authors information.</li>



<li><strong>html</strong>: determines if you want the output be in HTML or plain text (default: true, HTML format).</li>



<li><strong>exclude</strong>: excludes authors by IDs. it accepts comma separated user IDs or an array containing IDs (<code>int[]</code>).</li>



<li><strong>include</strong>:  includes authors by IDs. it accepts comma separated user IDs or an array containing IDs (<code>int[]</code>).</li>
</ul>



<h2 class="wp-block-heading">wp_list_authors function example</h2>



<p>In this example, we&#8217;re going to <strong>print</strong> a list of authors using the <code>wp_list_authors</code> function in WordPress.</p>



<p>I set a number of 10 authors (admins included) to be printed with the number of their posts displayed ordered by user ID.</p>



<p>In this example, printing style is list and authors with no posts are excluded.</p>



<pre><code class="language-php">$args = array(
	'orderby'       =&gt; 'ID',
	'order'         =&gt; 'ASC',
	'number'        =&gt; 10,
	'optioncount'   =&gt; true,
	'exclude_admin' =&gt; false,
	'show_fullname' =&gt; false,
	'hide_empty'    =&gt; true,
	'echo'          =&gt; true,
	'style'         =&gt; 'list',
	'html'          =&gt; true,
	'exclude'       =&gt; '',
	'include'       =&gt; '',
);

wp_list_authors($args);</code></pre>



<p>Look at the <code>echo</code> field in <code>$args</code> array. It defines that we need the authors&#8217; list to be printed by the function itself.</p>



<p>If the <code>echo</code> field was set to false, you must use the PHP echo command to print the list.</p>



<h2 class="wp-block-heading">Listing authors with a shortcode in WordPress</h2>



<p>In this example, We&#8217;ll create a shortcode to print a list of authors when we want.</p>



<p>You can use this code inside the <code>functions.php</code> file of your current theme Or <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">create a new WordPress plugin for yourself</a>.</p>



<pre><code class="language-php">function print_my_authors_in_list($atts){
	$args = array(
		'orderby'       =&gt; isset($atts['orderby']) ? $atts['orderby'] : 'name',
		'order'         =&gt; isset($atts['order']) ? $atts['order'] : 'ASC',
		'number'        =&gt; isset($atts['number']) ? $atts['number'] : '',
		'optioncount'   =&gt; isset($atts['optioncount']) ? $atts['optioncount'] : false,
		'exclude_admin' =&gt; isset($atts['exclude-admin']) ? $atts['exclude-admin'] : true,
		'show_fullname' =&gt; isset($atts['show-fullname']) ? $atts['show-fullname'] : false,
		'hide_empty'    =&gt; isset($atts['hide-empty']) ? $atts['hide-empty'] : true,
		'echo'          =&gt; false,
		'style'         =&gt; isset($atts['style']) ? $atts['style'] : 'list',
		'html'          =&gt; isset($atts['html']) ? $atts['html'] : true,
		'exclude'       =&gt; isset($atts['exclude']) ? $atts['exclude'] : '',
		'include'       =&gt; isset($atts['include']) ? $atts['include'] : '',
	);

	return wp_list_authors($args);
}

add_shortcode("print-my-authors-list","print_my_authors_in_list");

// try to execute the shortcode:
// use 0 or 1 instead of true/false
echo do_shortcode('[print-my-authors-list exclude-admin="0" optioncount="1"]');</code></pre>



<p>In the above example, We executed the shortcode with the <code>do_shortcode</code> function.</p>



<p>You also can use this shortcode inside WordPress editor.</p><p>The post <a href="https://mehdinazari.com/how-to-list-all-authors-in-wordpress-using-code/">How to List All Authors in WordPress (Shortcode Included!)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/how-to-list-all-authors-in-wordpress-using-code/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Check if a Post is Sticky in WordPress (+Example)</title>
		<link>https://mehdinazari.com/check-if-a-post-is-sticky-or-not-wordpress/</link>
					<comments>https://mehdinazari.com/check-if-a-post-is-sticky-or-not-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 21:26:04 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=971</guid>

					<description><![CDATA[<p>Sticky posts in WordPress will stick to the top of the post lists. Moderators can set a post to be sticky inside the WordPress admin panel. Developers can check if a post is sticky or not in WordPress, using the is_sticky function. In this WordPress tutorial, We&#8217;re going to set a sticky post and check [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/check-if-a-post-is-sticky-or-not-wordpress/">How to Check if a Post is Sticky in WordPress (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Sticky posts in WordPress will stick to the top of the post lists. Moderators can set a post to be sticky inside the  WordPress admin panel. Developers can check if a post is sticky or not in WordPress, using the is_sticky function. In this WordPress tutorial, We&#8217;re going to set a sticky post and check if the is_sticky function detects it as a sticky post or not.</p>



<span id="more-971"></span>



<h2 class="wp-block-heading">How to check if a specific post is sticky when developing WordPress?</h2>



<p><code>is_sticky</code> function will help you in this situation.</p>



<p>Just give the <code>is_sticky</code> function a post ID , and it will determine if a post is sticky or not with a true/false value. </p>



<p>The current queried post will be targeted if you do not specify a post ID.</p>



<h3 class="wp-block-heading">is_sticky function syntax</h3>



<p>The syntax is pretty easy and understandable:</p>



<pre><code class="language-php">is_sticky(int $postId)</code></pre>



<h3 class="wp-block-heading">is_sticky function example</h3>



<p>To check if the post with ID 1 is sticky or not in WordPress, you can use this code:</p>



<pre><code class="language-php">$postId = 1;
if(is_sticky(int $postId)){
    //post is sticky!

}</code></pre><p>The post <a href="https://mehdinazari.com/check-if-a-post-is-sticky-or-not-wordpress/">How to Check if a Post is Sticky in WordPress (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/check-if-a-post-is-sticky-or-not-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Check if the Current User is Administrator in WP</title>
		<link>https://mehdinazari.com/check-if-the-current-user-is-an-admin-wordpress/</link>
					<comments>https://mehdinazari.com/check-if-the-current-user-is-an-admin-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 21:25:00 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=969</guid>

					<description><![CDATA[<p>User authentication is essential while developing WordPress. Detecting if the current user is an administrator in WordPress is not challenging, using the current_user_can function. This function is one of the most important security functions in WordPress. current_user_can function: Check if the current user has a specified ability The current_user_can function is responsible for checking if [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/check-if-the-current-user-is-an-admin-wordpress/">How to Check if the Current User is Administrator in WP</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>User authentication is essential while developing WordPress. Detecting if the current user is an administrator in WordPress is not challenging, using the current_user_can function. This function is one of the most important security functions in WordPress.</p>



<span id="more-969"></span>



<h2 class="wp-block-heading"><code></code><code>current_user_can</code> function: Check if the current user has a specified ability</h2>



<p><a href="https://developer.wordpress.org/reference/functions/current_user_can/">The <code>current_user_can</code> function</a> is responsible for checking if the current user has a specified ability or not.</p>



<p>We can use this function to check if the current user is an administrator or not.</p>



<h3 class="wp-block-heading"><code>current_user_can</code> function syntax</h3>



<p>WordPress <code>current_user_can</code> function needs two parameters to work as you need.</p>



<p>it just checks if the current user can do <strong>something with something</strong> or not!</p>



<pre><code class="language-php">current_user_can($capability, $object_id, ...$moreArgs)</code></pre>



<p><code>$capability</code> determines what ability you want to check.</p>



<p><code>$object_id</code> determines what is the ID of the object you need the ability to be checked for (optional).</p>



<p><code>…$moreArgs</code> in syntax means that you can define more arguments based on the function usage.</p>



<h3 class="wp-block-heading">How to use <code>current_user_can</code> function to Check if the current user is an Admin</h3>



<p>If you check the <strong>administrator capability for the current user</strong>, you can determine if the current user is an admin or not:</p>



<pre><code class="language-php">if(current_user_can('administrator')){
     //current user is an administrator

}</code></pre>



<h2 class="wp-block-heading">DO NOT Use <code>is_admin()</code> to Detect an Administrator User</h2>



<p><code>is_admin()</code> is the function to check if the user is currently in the admin panel; it does not work on the frontend of the WordPress.</p><p>The post <a href="https://mehdinazari.com/check-if-the-current-user-is-an-admin-wordpress/">How to Check if the Current User is Administrator in WP</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/check-if-the-current-user-is-an-admin-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Check if a Post is in Specific Categories (+Example)</title>
		<link>https://mehdinazari.com/check-if-a-post-specific-category/</link>
					<comments>https://mehdinazari.com/check-if-a-post-specific-category/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 21:16:53 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=954</guid>

					<description><![CDATA[<p>Checking if a post is in a specific category can help developers serve functionalities based on categories. For example, changing a post style or loading a specific file for it, when it&#8217;s in a specific category. the WordPress in_category can check if a post has a category checked for it or not. In this tutorial, [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/check-if-a-post-specific-category/">How to Check if a Post is in Specific Categories (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Checking if a post is in a specific category can help developers serve functionalities based on categories. For example, changing a post style or loading a specific file for it, when it&#8217;s in a specific category. the WordPress in_category can check if a post has a category checked for it or not.</p>



<span id="more-954"></span>



<p>In this tutorial, we&#8217;ll try using the <a href="https://developer.wordpress.org/reference/functions/in_category/" target="_blank" rel="noreferrer noopener">WordPress <code>in_category</code> function</a> in a working WordPress environment.</p>



<h2 class="wp-block-heading"><code>in_category</code> function syntax</h2>



<p>This function gets two parameters, the first one contains the categories, and the second one is the post.</p>





<p><code>$category</code> parameter can be an integer, string, or an array containing multiple integers and strings (int[] or string[]).</p>



<p><code>$post</code> parameter is optional; it can be a post ID or a post object.</p>



<p>If you do not specify <code>$post</code>, WordPress will consider the current post.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>The WordPress <code>in_category</code> function runs the <code>has_category</code> function under the hood.</p>
</blockquote>



<h2 class="wp-block-heading">Check if a post is in specified categories using the <code>in_category</code> function  </h2>



<p>In this example, we&#8217;re going to check if a post with id 1 is in the uncategorized category or not.</p>



<p>Change the <code>$category</code> to your category name, and <code>$postId</code> to your desired post&#8217;s id (use null for current post).</p>



<pre><code class="language-php">$category = "uncategorized"; //change the name
$postId = 1; //set null for current post
if(in_category($category, $postId)){
     //post is in the category

}</code></pre>



<p>You can change the <code>$category</code> value to an array.</p>



<p><a href="https://mehdinazari.com" title="https://mehdinazari.com">WordPress developers</a> can use <code>array("uncategorized")</code> value for <code>$category</code> and get the same result from the above example.</p><p>The post <a href="https://mehdinazari.com/check-if-a-post-specific-category/">How to Check if a Post is in Specific Categories (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/check-if-a-post-specific-category/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Check if Content has a Specific Shortcode in WP</title>
		<link>https://mehdinazari.com/check-if-content-has-specific-shortcode-wordpress/</link>
					<comments>https://mehdinazari.com/check-if-content-has-specific-shortcode-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 21:13:40 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=949</guid>

					<description><![CDATA[<p>Checking if a specific shortcode is available in content is an easy task to handle while developing WordPress. has_shortcode is the function available in WordPress that developers can use to check if the content has a shortcode or not! in this WordPress tutorial we&#8217;ll have a closer look at the WordPress has_shortcode function. has_shortcode function [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/check-if-content-has-specific-shortcode-wordpress/">How to Check if Content has a Specific Shortcode in WP</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Checking if a specific shortcode is available in content is an easy task to handle while developing WordPress. has_shortcode is the function available in WordPress that developers can use to check if the content has a shortcode or not! in this WordPress tutorial we&#8217;ll have a closer look at the WordPress has_shortcode function.</p>



<span id="more-949"></span>



<h2 class="wp-block-heading"><code>has_shortcode</code> function syntax</h2>



<p><a href="https://developer.wordpress.org/reference/functions/has_shortcode/">The <code>has_shortcode</code> function</a> gets two parameters, a content and a tag.</p>



<p>Developers use this function to check if a shortcode is available in the content or not.</p>



<pre><code class="language-php">has_shortcode($content, $tag)</code></pre>



<p>Behind the scenes, WordPress uses regex to find shortcodes in content and checks if a specific shortcode is available between them or not.</p>



<p>But this function does more than just a regex checking.</p>



<p><code>has_shortcode</code> also checks if the shortcode is a real shortcode in WordPress or Not.</p>



<h2 class="wp-block-heading"><code>has_shortcode</code> function usage example</h2>



<p>this function has a simple syntax to use. We&#8217;re going to try it in a working example:</p>



<pre><code class="language-php">if(has_shortcode('[test]', 'test')){
	// test is not a default WP shortcode
	// if you or a plugin did not defined it, will return false
}

if(has_shortcode('', 'video')){
	// test is a default WP shortcode
	// if you did not removed it, this condition is true
}</code></pre>



<p>If you are interested in shortcodes in WordPress, you can read my tutorials:</p>



<ul class="wp-block-list">
<li><a href="https://mehdinazari.com/add-custom-shortcode-wordpress/">How to Add a Custom Shortcode to WordPress? (+Example)</a></li>



<li><a href="https://mehdinazari.com/count-users-wordpress-php-code/">How to Count Users in WordPress? (Example + Shortcode)</a></li>



<li><a href="https://mehdinazari.com/how-to-list-all-authors-in-wordpress-using-code/">How to List All Authors in WordPress? (Shortcode Included!)</a></li>
</ul><p>The post <a href="https://mehdinazari.com/check-if-content-has-specific-shortcode-wordpress/">How to Check if Content has a Specific Shortcode in WP</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/check-if-content-has-specific-shortcode-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to get Post Thumbnail URL with Custom Size</title>
		<link>https://mehdinazari.com/get-wordpress-thumbnails-specific-sizes/</link>
					<comments>https://mehdinazari.com/get-wordpress-thumbnails-specific-sizes/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 21:04:30 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=939</guid>

					<description><![CDATA[<p>WordPress generates different sizes for each uploaded image in the admin panel. Also, WordPress developers can register custom sizes for future generating. If you are interested in fetching a post&#8217;s thumbnail URL in custom size, read this article. I&#8217;m going to try registering new thumbnail sizes and retrieving thumbnails for each registered size. Register a [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/get-wordpress-thumbnails-specific-sizes/">How to get Post Thumbnail URL with Custom Size</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>WordPress generates different sizes for each uploaded image in the admin panel. Also, WordPress developers can register custom sizes for future generating. If you are interested in fetching a post&#8217;s thumbnail URL in custom size, read this article. I&#8217;m going to try registering new thumbnail sizes and retrieving thumbnails for each registered size.</p>



<span id="more-939"></span>



<h2 class="wp-block-heading">Register a custom size for images in WordPress</h2>



<p>Registering a custom image size in WordPress is easy task to do.</p>



<p>To register a new image size, we are going to use the <code>add_image_size</code> function inside <code>functions.php</code> or a custom plugin:</p>



<pre><code class="language-php">$sizeName = "100-100";
$width = 100;
$height = 100;
$crop = true;

add_image_size($sizeName, $width, $height, $crop);</code></pre>



<p>Read more about registering a custom size for images, in my articles:</p>



<p><a href="https://mehdinazari.com/register-custom-image-size-wordpress/">How to Register a Custom Image Size in WordPress? (+Example)</a></p>



<h2 class="wp-block-heading">Retrieve thumbnail URL with desired size</h2>



<p>After registering a desired size for images, you can retrieve uploaded images in registered size.</p>



<p>You only need to use the name of thumbnail size you registered in <a href="https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/" target="_blank" rel="noreferrer noopener"><code>get_the_post_thumbnail_url</code> function</a>:</p>



<pre><code class="language-php">$postId = 1; //select post by id
$sizeName = "100-100"; //registered name in previous example!

$thumbnailUrl = get_the_post_thumbnail_url($postId, $sizeName);</code></pre>



<h2 class="wp-block-heading">Retrieve WordPress default thumbnail sizes</h2>



<p>WordPress has a few default image sizes: thumbnail, medium, medium_large, and large.</p>



<p>Use each one of these default sizes in <code>get_the_post_thumbnail_url</code> function to get the URL you need.</p>



<pre><code class="language-php">$postId = 1; //select post by id
$thumbnailUrl = get_the_post_thumbnail_url($postId, "thumbnail");
$mediumUrl = get_the_post_thumbnail_url($postId, "medium");
$mediumLargeUrl = get_the_post_thumbnail_url($postId, "medium_large");
$largeUrl = get_the_post_thumbnail_url($postId, "large");</code></pre>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><strong>Note:</strong> if thumbnails are not generating (check the file server to find out), check if GD is enable in your PHP.</p>



<p>To do that, open <code>php.ini</code> file in the server and search for <code>extension=gd</code> in the file. If you see <code>;</code> character in the begining of it&#8217;s declaration line, remove the <code>;</code> to enable GD.</p>



<p>Then restart the web server.</p>
</blockquote><p>The post <a href="https://mehdinazari.com/get-wordpress-thumbnails-specific-sizes/">How to get Post Thumbnail URL with Custom Size</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/get-wordpress-thumbnails-specific-sizes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Set or Get a Custom Field for a Post in WP</title>
		<link>https://mehdinazari.com/set-get-custom-field-of-post-wordpress/</link>
					<comments>https://mehdinazari.com/set-get-custom-field-of-post-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 21:02:42 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=937</guid>

					<description><![CDATA[<p>Custom Fields in WordPress give developers the ability to store metadata on posts. Custom fields help developers avoid using extra tables in the database and use what is already available for plugin and theme development. In this tutorial, I will set a custom field on a post and retrieve its saved value. Setting custom fields [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/set-get-custom-field-of-post-wordpress/">How to Set or Get a Custom Field for a Post in WP</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Custom Fields in WordPress give developers the ability to store metadata on posts. Custom fields help developers avoid using extra tables in the database and use what is already available for plugin and theme development. In this tutorial, I will set a custom field on a post and retrieve its saved value.</p>



<span id="more-937"></span>



<p>Setting custom fields on posts is one of the most important features of WordPress.</p>



<p>Developers use this functionality to save data on posts that can be retrieved easily for later usages.</p>



<p>This <a href="https://mehdinazari.com">WordPress tutorial</a> will try saving a custom field on a post and then retrieving it in the frontend.</p>



<h2 class="wp-block-heading">How to set a custom field for a post in WordPress?</h2>



<p>WordPress lets moderators set custom fields when they are editing a post in the admin panel.</p>



<p>There is also another way, Using functions to set the custom field for the post.</p>



<p>We&#8217;re going to check out both.</p>



<h3 class="wp-block-heading">1- Using WordPress admin panel (in 3 Steps)</h3>



<p>Setting a custom field in the admin UI is the preferred way for moderators.</p>



<h4 class="wp-block-heading">Step 1:</h4>



<p>When you are editing a post in the WordPress admin panel, look for the &#8220;Custom Fields&#8221; box under the editor:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="438" src="https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-in-wp-editor-1024x438.jpg" alt="Custom Fields Under WP Editor" class="wp-image-1517" srcset="https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-in-wp-editor-1024x438.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-in-wp-editor-300x128.jpg 300w, https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-in-wp-editor-768x328.jpg 768w, https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-in-wp-editor-800x342.jpg 800w, https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-in-wp-editor.jpg 1050w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Custom Fields Under WP Editor</figcaption></figure>



<h4 class="wp-block-heading">Step 2: </h4>



<p>Click &#8220;Enter new&#8221; in the custom fields box:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="438" src="https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-enter-new-1024x438.jpg" alt="Enter New Custom Field" class="wp-image-1520" srcset="https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-enter-new-1024x438.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-enter-new-300x128.jpg 300w, https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-enter-new-768x328.jpg 768w, https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-enter-new-800x342.jpg 800w, https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-enter-new.jpg 1050w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Enter New Custom Field</figcaption></figure>



<h4 class="wp-block-heading">Step 3:</h4>



<p>Then you can type a name and value and click &#8220;Add Custom Field&#8221;:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="143" src="https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-name-value-1024x143.jpg" alt="Set Name and Value for Custom Field" class="wp-image-1522" srcset="https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-name-value-1024x143.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-name-value-300x42.jpg 300w, https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-name-value-768x108.jpg 768w, https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-name-value-800x112.jpg 800w, https://mehdinazari.com/wp-content/uploads/2021/11/custom-fields-name-value.jpg 1050w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Set Name and Value for Custom Field</figcaption></figure>



<h4 class="wp-block-heading">In case you did not find the Custom Fields box when editing the post in WP:</h4>



<p>If you do not see the Custom Fields box, you must check the &#8220;Custom Fields&#8221; option in the Screen Options (old WP versions) or <code>Preferences -&gt; Panels -&gt; Additional</code> (newer versions, using Gutenberg editor).</p>



<h5 class="wp-block-heading">Enable Custom Fields in Screen Options (Classic WP Editor):</h5>



<p>Look for the &#8220;Screen Option&#8221; button on the top right location of your WordPress post edit page. It is next to the &#8220;Help&#8221; button.</p>



<h5 class="wp-block-heading">Enable Custom Fields in Post Preferences (Gutenberg Editor):</h5>



<p>To enable custom fields in the Gutenberg editor, you must <strong>open the preferences settings</strong>, like bellow:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="469" src="https://mehdinazari.com/wp-content/uploads/2021/11/screen-options-new-wp-1024x469.jpg" alt="Screen Options in New WP" class="wp-image-1523" srcset="https://mehdinazari.com/wp-content/uploads/2021/11/screen-options-new-wp-1024x469.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2021/11/screen-options-new-wp-300x137.jpg 300w, https://mehdinazari.com/wp-content/uploads/2021/11/screen-options-new-wp-768x352.jpg 768w, https://mehdinazari.com/wp-content/uploads/2021/11/screen-options-new-wp-800x366.jpg 800w, https://mehdinazari.com/wp-content/uploads/2021/11/screen-options-new-wp.jpg 1050w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Screen Options in New WP</figcaption></figure>



<p>After opening the preferences popup, <strong>Select &#8220;Panel,&#8221;</strong> and then <strong>enable the &#8220;Custom Fields&#8221; option</strong>:</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="751" src="https://mehdinazari.com/wp-content/uploads/2021/11/enable-custom-fields-new-wp-1024x751.jpg" alt="Enable Custom Fields in New WP" class="wp-image-1524" srcset="https://mehdinazari.com/wp-content/uploads/2021/11/enable-custom-fields-new-wp-1024x751.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2021/11/enable-custom-fields-new-wp-300x220.jpg 300w, https://mehdinazari.com/wp-content/uploads/2021/11/enable-custom-fields-new-wp-768x563.jpg 768w, https://mehdinazari.com/wp-content/uploads/2021/11/enable-custom-fields-new-wp-25x18.jpg 25w, https://mehdinazari.com/wp-content/uploads/2021/11/enable-custom-fields-new-wp-800x587.jpg 800w, https://mehdinazari.com/wp-content/uploads/2021/11/enable-custom-fields-new-wp.jpg 1050w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Enable Custom Fields in New WP</figcaption></figure>
</div>


<h3 class="wp-block-heading">2- Using PHP codes</h3>



<p>Functions are easier for me to explain! <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p>If you know the post ID, you want to set the custom field for, use the <code>update_post_meta</code> function to add your custom field.</p>



<p>The <code>update_post_meta</code> function will check the custom field existence; if it&#8217;s existed, the function will update it; if not, the function will add it.</p>



<h4 class="wp-block-heading">update_post_meta function syntax</h4>



<p>I&#8217;m going to explain this function first, and then I&#8217;ll try it in an example.</p>



<pre><code class="language-php">update_post_meta($post_id, $meta_key, $meta_value, $prev_value = '')</code></pre>



<p><code>$post_id</code> Is obvious. It&#8217;s the ID of the post you want to set the custom field for.</p>



<p>$meta_key is the name of the custom field you want to set.</p>



<p><code>$meta_value</code> Is the value of the custom field.</p>



<p><code>$prev_value</code> is not a required parameter, but it&#8217;s a tricky one.</p>



<p>If you set the <code>$prev_value</code> parameter, you actually are referring to a custom field with a specific value (to update it!).</p>



<p><code>$prev_value</code> is useful when you want to manage multiple custom fields with the same name.</p>



<p>By setting <code>$prev_value</code>, you are using the previous value as the reference to distinguish between the available custom fields with this name.</p>



<p>For a simple example, keep reading&#8230;</p>



<h4 class="wp-block-heading">Set or update a custom field using the update_post_meta function</h4>



<p>When you know the syntax, setting a custom field for your posts is easy.</p>



<p>For example, you can set a custom field with the name &#8220;<strong>my_rating</strong>&#8221; and value &#8220;<strong>4</strong>&#8221; in a post with an ID of 1:</p>



<pre><code class="language-php">$post_id = 1;
$meta_key = "my_rating";
$meta_value = 4;
update_post_meta($post_id, $meta_key, $meta_value);</code></pre>



<p>Read my tutorial on <a href="https://mehdinazari.com/add-custom-field-multiple-posts-wordpress/" target="_blank" rel="noopener" title="How to Add One Custom Field for Many Posts in WordPress">adding one custom field for many posts</a> simultaneously, if this can assist you further.</p>



<h2 class="wp-block-heading">How to get a custom field of a post in WordPress?</h2>



<h3 class="wp-block-heading"><code>get_post_meta</code> function syntax</h3>



<p><a href="https://developer.wordpress.org/reference/functions/get_post_meta/" target="_blank" rel="noreferrer noopener">The WordPress <code>get_post_meta</code> function</a> can retrieve the custom field value of a post for you.</p>



<pre><code class="language-php">get_post_meta($post_id, $key = '', $single = false)</code></pre>



<p><code>$key</code> is the name of the custom field you want to retrieve for the <code>$post_id</code>.</p>



<p><code>$single</code> is a boolean flag; If you set it as false (default), the result will be an array; If true, the result will be a single value.</p>



<h3 class="wp-block-heading"><code>get_post_meta</code> usage example</h3>



<p>In this example, we will retrieve what we set in the previous example.</p>



<p>We&#8217;ll retrieve the <strong>my_rating</strong> custom field from a post with an ID 1:</p>



<pre><code class="language-php">$post_id = 1;
$key = "my_rating";
$single = true; //it is a single custom field
$my_rating = get_post_meta($post_id, $key, $single);</code></pre><p>The post <a href="https://mehdinazari.com/set-get-custom-field-of-post-wordpress/">How to Set or Get a Custom Field for a Post in WP</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/set-get-custom-field-of-post-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get Page by Title in WordPress (+Example)</title>
		<link>https://mehdinazari.com/get-page-by-title-wordpress/</link>
					<comments>https://mehdinazari.com/get-page-by-title-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 20:59:58 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=931</guid>

					<description><![CDATA[<p>Getting full details of a page by title is not that challenging in WordPress. WP has a function named get_page_by_title that is useful when a developer wants to retrieve page data from a specified title. I will try this function inside a working example for those interested developers. get_page_by_title function Is useful when a WordPress [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/get-page-by-title-wordpress/">How to Get Page by Title in WordPress (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Getting full details of a page by title is not that challenging in WordPress. WP has a function named get_page_by_title that is useful when a developer wants to retrieve page data from a specified title. I will try this function inside a working example for those interested developers.</p>



<span id="more-931"></span>



<p><a href="https://developer.wordpress.org/reference/functions/get_page_by_title/"><code>get_page_by_title</code></a> function Is useful when a <a href="https://mehdinazari.com/">WordPress developer</a> wants full details of a page, but he or she only has the title available.</p>



<h2 class="wp-block-heading">How to use get_page_by_title function to find a page by title?</h2>



<h3 class="wp-block-heading">get_page_by_title syntax in WordPress</h3>



<p>The <code>get_page_by_title</code> function receives 3 parameters. You must <strong>specify a title, and two optional parameters for output, and post type.</strong></p>



<pre><code class="language-php">get_page_by_title($pageTitle, $output = OBJECT, $postType = 'page')</code></pre>



<ul class="wp-block-list">
<li><code>$pageTitle</code>: This parameter is required. Set the title to get it if it&#8217;s available.</li>



<li><code>$output</code>: Can be one of <strong>OBJECT</strong> (default value), <strong>ARRAY_A</strong> (associative array), or <strong>ARRAY_N</strong> (numeric array) values.</li>



<li><code>$postType</code>: Default value for this parameter is <strong>page</strong>, but you can set other types or an array of types.</li>
</ul>



<h3 class="wp-block-heading">Example of getting a page using get_page_by_title function</h3>



<p>I want to retrieve a page with &#8220;About Us&#8221; title, although you can replace it with anything you want:</p>



<pre><code class="language-php">$pageTitle = "About Us";
$pageObject = get_page_by_title($pageTitle);
if($pageObject){
    //page exists, use the object

}</code></pre>



<h3 class="wp-block-heading">Result of running <code>get_page_by_title</code> function</h3>



<p>The function will return a WP_Post object of the page if it&#8217;s available. otherwise, it will return a null value:</p>



<pre><code class="language-php">WP_Post Object
(
    [ID] =&gt; 140
    [post_author] =&gt; 1
    [post_date] =&gt; 2021-02-05 11:53:37
    [post_date_gmt] =&gt; 2021-02-05 11:53:37
    [post_content] =&gt; Test Content
    [post_title] =&gt; About Us
    [post_excerpt] =&gt; 
    [post_status] =&gt; publish
    [comment_status] =&gt; closed
    [ping_status] =&gt; closed
    [post_password] =&gt; 
    [post_name] =&gt; about-us
    [to_ping] =&gt; 
    [pinged] =&gt; 
    [post_modified] =&gt; 2021-02-05 11:53:37
    [post_modified_gmt] =&gt; 2021-02-05 11:53:37
    [post_content_filtered] =&gt; 
    [post_parent] =&gt; 0
    [guid] =&gt; http://sitename.com/about-us/
    [menu_order] =&gt; 0
    [post_type] =&gt; page
    [post_mime_type] =&gt; 
    [comment_count] =&gt; 0
    [filter] =&gt; raw
)</code></pre>



<h2 class="wp-block-heading">Good questions about get_page_by_title function</h2>



<p>You may have questions about the WordPress <code>get_page_by_title</code> function.</p>



<p>Here I answered a few important questions that I&#8217;ve encountered about this function:</p>



<h3 class="wp-block-heading">1- What page the get_page_by_title function will return when two or more pages have the same title?</h3>



<p>The <code>get_page_by_title</code> function will return the older one when two pages have the same title.</p>



<p>If in a case, it&#8217;s just two pages with the same title, the <code>get_page_by_title</code> function will the one with the smaller ID.</p>



<p>But if it&#8217;s multiple pages with the same title (more than two), WordPress uses publication date to determine the oldest page, not the ID.</p>



<h3 class="wp-block-heading">2- Is the <code>get_page_by_title</code> function case sensitive?</h3>



<p>Yes, It is!</p>



<p>You better set the exact title to find a page when you are using the <code>get_page_by_title</code> function.</p>



<h3 class="wp-block-heading">3- What if I need to get pages based on other information?</h3>



<p>The <code>get_posts</code> function in WordPress is useful when you need pages with other information.</p>



<p>I recommend you read my <a href="https://mehdinazari.com/wordpress-query-posts/">article about <code>get_posts</code> function</a>:</p>



<p><a href="https://mehdinazari.com/wordpress-query-posts/">WordPress Query Posts by Category, Tag, Custom attribute, and more!</a></p>



<p>When using the <code>get_posts</code> function, you can use the <code>post_type</code> field to find posts of any type (in this case, page).</p>



<h3 class="wp-block-heading">4- Where can we learn more about WordPress pages and their related functions?</h3>



<p><a href="https://developer.wordpress.org">WordPress&#8217;s official website has a developers section</a> that is the best source for any information when you are a beginner.</p>



<p><a href="https://developer.wordpress.org/?s=page">Search for page functions inside the WordPress archive</a>, so you can find many useful functions related to WordPress pages.</p><p>The post <a href="https://mehdinazari.com/get-page-by-title-wordpress/">How to Get Page by Title in WordPress (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/get-page-by-title-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to get the Previous Post Link in WordPress</title>
		<link>https://mehdinazari.com/get-previous-post-link-wordpress/</link>
					<comments>https://mehdinazari.com/get-previous-post-link-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 20:58:47 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=928</guid>

					<description><![CDATA[<p>Presenting Previous Post Link for visitors can generate more page views and increase the conversion rate. WordPress introduced the get_previous_post_link function to help developers print the Previous Post Link easily and fast. If a user reads a post, the get_previous_post_link function can help the visitor navigate better through your website. Like the get_next_post_link function (print [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/get-previous-post-link-wordpress/">How to get the Previous Post Link in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Presenting Previous Post Link for visitors can generate more page views and increase the conversion rate. WordPress introduced the get_previous_post_link function to help developers print the Previous Post Link easily and fast.</p>



<span id="more-928"></span>



<p>If a user reads a post, <a href="https://developer.wordpress.org/reference/functions/get_previous_post_link/">the <code>get_previous_post_link</code> function</a> can help the visitor navigate better through your website.</p>



<p>Like the get_next_post_link function (<a href="https://mehdinazari.com/get-next-post-url-wordpress/">print the next post link</a>), the <code>get_previous_post_link</code> function looks for the queried post by WordPress to generate a link for you.</p>



<h2 class="wp-block-heading">get_previous_post_link Function Syntax</h2>



<p>All of the parameters in <code>get_previous_post_link</code> function are optional!</p>



<p>It means that you can use this function just with parentheses (<code>get_previous_post_link()</code>).</p>



<p>Checkout the complete syntax:</p>



<pre><code class="language-php">get_previous_post_link(
    $format = '« %link',
    $link = '%title',
    $in_same_term = false,
    $excluded_terms = '',
    $taxonomy = 'category'
)</code></pre>



<h3 class="wp-block-heading">Explaining get_previous_post_link function parameters</h3>



<ul class="wp-block-list">
<li><code>$format</code>: Printing format for all of the printing text, Including the link and what&#8217;s around it. <code>%link</code> is the actual link (<code>&lt;a></code> tag).</li>



<li><code>$link</code>: Actual link printing format (<code>&lt;a></code> tag). The default value is &#8216;%title&#8217;.</li>



<li><code>$in_same_term</code>: Specifies that you only need links from the same taxonomy as the current post. The default value is false.</li>



<li><code>$excluded_terms</code>: Excludes terms by Id. You can use a comma-separated list of IDs or an array.</li>



<li><code>$taxonomy</code>: Specifies what taxonomy you want to check for printing the previous post (category, tag, etc).</li>
</ul>



<h2 class="wp-block-heading">Get the Previous Post Link in WordPress</h2>



<p>You can try using WordPress <code></code><code>get_previous_post_link</code> in the <code>single.php</code> of your currently active theme:</p>



<pre><code class="language-php">get_previous_post_link();</code></pre>



<p>Output:</p>



<pre><code class="language-php"><pre><code class="language-php">&lt;a href="http://site-url.com/post-url/" rel="previous"&gt;« Previous Post's Title&lt;/a&gt;</code></pre></code></pre><p>The post <a href="https://mehdinazari.com/get-previous-post-link-wordpress/">How to get the Previous Post Link in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/get-previous-post-link-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to get the Next Post URL in WordPress (Working Example)</title>
		<link>https://mehdinazari.com/get-next-post-url-wordpress/</link>
					<comments>https://mehdinazari.com/get-next-post-url-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 20:56:53 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=924</guid>

					<description><![CDATA[<p>WordPress get_next_post_link function helps developers to retrieve the URL of the next post when the user is currently inside one. Getting the Next Post URL is a great way to find a related article for visitors. This functionality can increase page views if a developer uses it right. get_next_post_link function will print the next post [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/get-next-post-url-wordpress/">How to get the Next Post URL in WordPress (Working Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>WordPress get_next_post_link function helps developers to retrieve the URL of the next post when the user is currently inside one. Getting the Next Post URL is a great way to find a related article for visitors. This functionality can increase page views if a developer uses it right.</p>



<span id="more-924"></span>



<p><code><a href="https://developer.wordpress.org/reference/functions/get_next_post_link/">get_next_post_link</a></code> function will print the next post URL when the user reads one.</p>



<p>So if you want to use <code>get_next_post_link</code> function while <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">developing WordPress</a>, WP will look for a current post object and will generate the next post URL for you.</p>



<h2 class="wp-block-heading">get_next_post_link Function Syntax</h2>



<p>This function&#8217;s syntax is easy to understand and parameters names represent what options you can set to customize generated HTML code.</p>



<pre><code class="language-php">get_next_post_link(
 $format = '%link »',
 $link = '%title',
 $in_same_term = false,
 $excluded_terms = '',
 $taxonomy = 'category'
)</code></pre>



<h2 class="wp-block-heading">get_next_post_link Function Usage</h2>



<p>You can use the <code>get_next_post_link</code> function inside the <code>single.php</code> file of your current template.</p>



<pre><code class="language-php">get_next_post_link()</code></pre>



<p>Output:</p>



<pre><code class="language-html">&lt;a href="http://site-url.com/post-url/" rel="next"&gt;Next Post's Title&lt;/a&gt;»</code></pre><p>The post <a href="https://mehdinazari.com/get-next-post-url-wordpress/">How to get the Next Post URL in WordPress (Working Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/get-next-post-url-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to get Publish Date of The Last Post in WordPress</title>
		<link>https://mehdinazari.com/get-publish-date-of-the-last-post-wordpress/</link>
					<comments>https://mehdinazari.com/get-publish-date-of-the-last-post-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 20:54:30 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=921</guid>

					<description><![CDATA[<p>WordPress has two perfect functions to get Publish Date of the Last Post. get_lastpostdate and get_lastpostmodified functions are helpful when the developer wants to retrieve Latest Post&#8217;s Dates. In this WordPress tutorial for beginners, We will try these two functions in a working environment and check if they return what we want? How to get [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/get-publish-date-of-the-last-post-wordpress/">How to get Publish Date of The Last Post in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>WordPress has two perfect functions to get Publish Date of the Last Post. get_lastpostdate and get_lastpostmodified functions are helpful when the developer wants to retrieve Latest Post&#8217;s Dates. In this WordPress tutorial for beginners, We will try these two functions in a working environment and check if they return what we want?</p>



<span id="more-921"></span>



<h2 class="wp-block-heading">How to get Last Post Publish Date using the <code>get_lastpostdate</code> function in WordPress?</h2>



<p><a href="https://developer.wordpress.org/reference/functions/get_lastpostdate/"><code>get_lastpostdate</code> function</a> is helpful when you want to retrieve the latest post publish date.</p>



<p>This function&#8217;s syntax is easy to understand:</p>



<pre><code class="language-php">get_lastpostdate($timezone='server', $postType='any')</code></pre>



<p>Set the <code>$timezone</code> parameter to get the date based on your selected timezone.</p>



<p><code>$postType</code> can determine what type of posts you want information about.</p>



<h2 class="wp-block-heading">How to get the Date that a Post was Modified using the <code>get_lastpostmodified</code> function in WordPress? </h2>



<p><a href="https://developer.wordpress.org/reference/functions/get_lastpostmodified/"><code>get_lastpostmodified</code> function</a> will return a date string that represents the last date and time a post was modified on the current website.</p>



<p>The syntax is much like the previous function:</p>



<pre><code class="language-php">get_lastpostmodified($timezone='server', $postType='any')</code></pre>



<p>Parameters are the same as <code>get_lastpostdate</code> function.</p>



<p>Example of running these two functions in my case:</p>



<pre><code class="language-php">$lastPostPublishDate = get_lastpostdate(); //value: 2021-11-03 07:32:44.000000
$lastPostModifyDate = get_lastpostmodified(); //value: 2021-11-05 11:30:53.000000</code></pre>



<p>Returned value was correct for me in the local work space.</p>



<p>If you are interested in more information about post dates, you can follow these articles on my blog:</p>



<p><a href="https://mehdinazari.com/post-date-wordpress/">How to get WordPress Post Date using PHP?</a></p>



<p><a href="https://mehdinazari.com/new-post-after-a-while/">How to set publishing date and time for a WordPress post Programmatically?</a></p><p>The post <a href="https://mehdinazari.com/get-publish-date-of-the-last-post-wordpress/">How to get Publish Date of The Last Post in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/get-publish-date-of-the-last-post-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get the Current Theme URL in WordPress</title>
		<link>https://mehdinazari.com/get-current-theme-url-wordpress/</link>
					<comments>https://mehdinazari.com/get-current-theme-url-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 20:53:25 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=919</guid>

					<description><![CDATA[<p>When developing WordPress, retrieving the Current Theme URL is helpful, especially to load file URLs located under the Current Theme directory. WordPress bloginfo() function can retrieve the Current Template URL. Managing URLs when directory names can be changed is a challenging task to do! To overcome this issue, a pro WordPress developer must use functions [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/get-current-theme-url-wordpress/">How to Get the Current Theme URL in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>When developing WordPress, retrieving the Current Theme URL is helpful, especially to load file URLs located under the Current Theme directory. WordPress bloginfo() function can retrieve the Current Template URL.</p>



<span id="more-919"></span>



<p>Managing URLs when directory names can be changed is a challenging task to do!</p>



<p>To overcome this issue, a <a href="https://mehdinazari.com">pro WordPress developer</a> must use functions instead of fixed URLs.</p>



<p>For example, if you use this URL when you want to load CSS:</p>



<pre><code class="language-html">&lt;link type="text/css" href="https://website.com/wp-content/themes/theme-name/css/style.css" rel="stylesheet"/&gt;</code></pre>



<p>You will run into loading problems each time you want to change the name of your theme.</p>



<p>But what if you can get this part of the URL in a parameter:</p>



<pre><code class="language-html">https://website.com/wp-content/themes/theme-name/</code></pre>



<p>So each time you change your theme name or copy codes to another theme, changing URLs won&#8217;t be necessary.</p>



<p>Using the <code>bloginfo('template_directory')</code> in your codes will print the Current Theme Directory for you.</p>



<p>For example, use this code when you want to load a CSS file located inside your current theme directory:</p>



<pre><code class="language-html">&lt;link type="text/css" href="&lt;?php bloginfo('template_directory'); ?/&gt;/css/style.css" rel="stylesheet"/&gt;</code></pre>



<p>Read more about <a href="https://developer.wordpress.org/reference/functions/bloginfo/">the bloginfo function on WordPress&#8217;s official website</a>.</p><p>The post <a href="https://mehdinazari.com/get-current-theme-url-wordpress/">How to Get the Current Theme URL in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/get-current-theme-url-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get Home URL in WordPress [Example]</title>
		<link>https://mehdinazari.com/get-home-url-wordpress/</link>
					<comments>https://mehdinazari.com/get-home-url-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 20:52:13 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=910</guid>

					<description><![CDATA[<p>get_home_url retrieves the Home Page URL of a WordPress website. get_home_url is one of the most used WordPress functions by developers when they want to use links in the development process. Let&#8217;s have a better look at this function with an example. WordPress can be installed on any sub-directory in your website host. WordPress is [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/get-home-url-wordpress/">How to Get Home URL in WordPress [Example]</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>get_home_url retrieves the Home Page URL of a WordPress website. get_home_url is one of the most used WordPress functions by developers when they want to use links in the development process. Let&#8217;s have a better look at this function with an example.</p>



<span id="more-910"></span>



<p>WordPress can be installed on any sub-directory in your website host.</p>



<p>WordPress is not always installed on the root folder, so it becomes important to have a function returning the website&#8217;s home URL.</p>



<p>When <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">developing WordPress themes or plugins</a>, Using relative addresses for file reference or link building is NOT a great idea.</p>



<p>You should never use fixed URLs also!</p>



<p>The reason is clear; addresses may change due to differences in WordPress installation, selected options, etc.</p>



<p>A good practice for making a linked reference to a website is using <a href="https://developer.wordpress.org/reference/functions/get_home_url/" target="_blank" rel="noreferrer noopener">the <code>get_home_url</code> function</a> in PHP.</p>



<h2 class="wp-block-heading">get_home_url Function: Reterives Home URL in WordPress</h2>



<p><code>get_home_url</code> function has a simple syntax in WordPress:</p>



<pre><code class="language-php">get_home_url($blogId = null, $path = '', $scheme = null)</code></pre>



<p>If you are using WordPress for a single website, pass a null value for <code>$blogId</code> (default is null also). </p>



<p><code>$path</code> is the relative path from the home URL.</p>



<p><code>$scheme</code> can be one of these values: &#8216;http&#8217;, &#8216;https&#8217;, &#8216;relative&#8217;, &#8216;rest&#8217;, or null.</p>



<h2 class="wp-block-heading">Get The Home URL in WP with the get_home_url Function</h2>



<p><code>get_home_url</code> function will return the home page URL; you must print it as HTML.</p>



<p>Example of using the <code>get_home_url</code> function in an HTML link:</p>



<pre><code class="language-php">&lt;a href="&lt;?php echo get_home_url(); ?&gt;"&gt;Home Page&lt;/a&gt;</code></pre>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Note: Do NOT confuse the WordPress home url with the <a href="https://mehdinazari.com/get-home-url-wordpress/" target="_blank" rel="noopener" title="">WordPress root path</a>.</p>
</blockquote><p>The post <a href="https://mehdinazari.com/get-home-url-wordpress/">How to Get Home URL in WordPress [Example]</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/get-home-url-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get Comment Details by ID in WordPress</title>
		<link>https://mehdinazari.com/get-comment-information-by-comment-id-wordpress/</link>
					<comments>https://mehdinazari.com/get-comment-information-by-comment-id-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 20:49:08 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=915</guid>

					<description><![CDATA[<p>In WordPress, a comment is an entity with a complete set of attributes. You can retrieve any information about a comment in WordPress using the get_comment function. Using the get_comment function, you can retrieve post ID, comment text, commenter details, date, status, etc. How to get full details of a comment in WordPress? WordPress has [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/get-comment-information-by-comment-id-wordpress/">How to Get Comment Details by ID in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>In WordPress, a comment is an entity with a complete set of attributes. You can retrieve any information about a comment in WordPress using the get_comment function. Using the get_comment function, you can retrieve post ID, comment text, commenter details, date, status, etc.</p>



<span id="more-915"></span>



<h2 class="wp-block-heading">How to get full details of a comment in WordPress?</h2>



<p>WordPress has made it pretty easy for developers to work with comment entities after version v4.4.0 release.</p>



<p>With <a href="https://developer.wordpress.org/reference/functions/get_comment/">the <code>get_comment</code> function provided by WordPress</a>, you can get a specific comment&#8217;s details by ID as an object or array (you can determine it).</p>



<p>This <a href="https://developer.wordpress.org/reference/classes/wp_comment/"><code>WP_Comment</code> object</a> contains the detail of the requested comment with meaningful labels.</p>



<h3 class="wp-block-heading"><code>get_comment</code> function syntax</h3>



<p>This function gets two optional parameters, <code>$comment</code> and <code>$output</code>.</p>



<pre><code class="language-php">get_comment($comment = null, $output = OBJECT)</code></pre>



<p><code>$comment</code> parameter determines the comment you want to retrieve details about. This can be an ID or a WP_Comment object.</p>



<p>The default value for <code>$comment</code>&nbsp;parameter is <code>null</code>. This means it will retrieve the current queried comment&#8217;s details from the database if you do not specify the comment you want.</p>



<p><code>$output</code> parameter will determine the type of returned data from WordPress. Use <code>OBJECT</code>&nbsp;(default), <code>ARRAY_A</code>, or <code>ARRAY_N</code> as the value of this <strong>optional parameter</strong>.</p>



<p>If the <code>get_comment</code> function did not find any comment with the given ID; it will return null as result.</p>



<h3 class="wp-block-heading"><code>get_comment</code> Output: <code>WP_Comment</code> object</h3>



<p>Look at the <code>WP_Comment</code> object attributes returned by the <code>get_comment</code> function of WordPress, it contains detailed information about the specified comment:</p>



<pre><code class="language-php">WP_Comment Object
(
	[comment_ID],
	[comment_post_ID],
	[comment_author]
	[comment_author_email]
	[comment_author_url]
	[comment_author_IP]
	[comment_date]
	[comment_date_gmt]
	[comment_content]
	[comment_karma]
	[comment_approved]
	[comment_agent]
	[comment_type]
	[comment_parent]
	[user_id]
)</code></pre>



<p>You can get the actual text for the comment with <code>comment_content</code> attribute of the <code>WP_Comment</code> object. the <code>comment_author</code> contains the author&#8217;s name, and <code>comment_date</code> value is the date when this comment was sent to the WP blog post.</p>



<h2 class="wp-block-heading">Example of getting a WP comment&#8217;s detail, using comment ID</h2>



<p>In this example, we will retrieve a WordPress comment&#8217;s information. We will get the comment&#8217;s detail with the ID <code>1</code>, which we specified in <code>$commentId</code> parameter:</p>



<pre><code class="language-php">$commentId = 1;
$comment = get_comment($commentId);
if($comment){
	echo "Comment ID: " .$comment-&gt;comment_ID." <br />";
	echo "Comment Post ID: " .$comment-&gt;comment_post_ID." <br />";
	echo "Comment Author: " .$comment-&gt;comment_author." <br />";
	echo "Comment Email: " .$comment-&gt;comment_author_email." <br />";
	echo "Comment Author URL: " .$comment-&gt;comment_author_url." <br />";
	echo "Comment Author IP: " .$comment-&gt;comment_author_IP." <br />";
	echo "Comment Date and time: " .$comment-&gt;comment_date." <br />";
	echo "Comment Date (GMT): " .$comment-&gt;comment_date_gmt." <br />";
	echo "Comment Content (most important): " .$comment-&gt;comment_content." <br />";
	echo "Comment Karma: " .$comment-&gt;comment_karma." <br />";
	echo "Comment Approval Status: " .$comment-&gt;comment_approved." <br />";
	echo "Comment Agent: " .$comment-&gt;comment_agent." <br />";
	echo "Comment Type: " .$comment-&gt;comment_type." <br />";
	echo "Comment parent (if it's a reply): " .$comment-&gt;comment_parent." <br />";
	echo "Comment User (if available): " .$comment-&gt;user_id." <br />";
}
else{
	echo "We did not find any comment with the given ID.";
}
</code></pre><p>The post <a href="https://mehdinazari.com/get-comment-information-by-comment-id-wordpress/">How to Get Comment Details by ID in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/get-comment-information-by-comment-id-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get Category ID by Name in WordPress</title>
		<link>https://mehdinazari.com/get-category-id-by-name-wordpress/</link>
					<comments>https://mehdinazari.com/get-category-id-by-name-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 20:46:11 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=907</guid>

					<description><![CDATA[<p>get_cat_ID function in WordPress is responsible for retrieving category ID from a given category name. I&#8217;m going to try the get_cat_ID function in an example to make the usage more clear. Several ways to get a category ID based on a given category name are available when developing WordPress. But the most preferred function, in [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/get-category-id-by-name-wordpress/">How to Get Category ID by Name in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>get_cat_ID function in WordPress is responsible for retrieving category ID from a given category name. I&#8217;m going to try the get_cat_ID function in an example to make the usage more clear.</p>



<span id="more-907"></span>



<p>Several ways to get a category ID based on a given category name are available when <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">developing WordPress</a>.</p>



<p>But the most preferred function, in this case, is <a href="https://developer.wordpress.org/reference/functions/get_cat_id/">the <code>get_cat_ID</code> function</a>.</p>



<p>The <code>get_cat_ID</code> function only gets the category name as a parameter, and as a result, it will return an integer ID number.</p>



<p>If the specified category does not exist, the <code>get_the_ID</code> function returned value will be <code>0</code>.</p>



<h2 class="wp-block-heading">How to use <code>get_cat_ID</code> function in WordPress?</h2>



<p>The <code>get_cat_ID</code> function has an easy syntax and fast usage.</p>



<h3 class="wp-block-heading"><code>get_cat_ID</code> function syntax in WordPress</h3>



<p>The function syntax is super clear. it only accepts one parameter, which is the name of the category (string):</p>



<pre><code class="language-php">get_cat_ID($categoryName)</code></pre>



<h3 class="wp-block-heading"><code>get_cat_ID</code> function Example</h3>



<p>For a fresh WordPress installation, I want to try the &#8220;uncategorized&#8221; category name to check if this function works correctly.</p>



<pre><code class="language-php">$categoryName = "uncategorized";
$categoryId = get_cat_ID($categoryName); //value was 1!</code></pre>



<p>After running the above codes, <code>$categoryId</code> in my case was 1, which is a correct value for my new WordPress installation.</p>



<p>For more information about working with WordPress categories, I recommend you read two articles in my blog:</p>



<p><a href="https://mehdinazari.com/categories-of-post-wordpress/">How to get Categories of a Post in WordPress? (3 Examples!)</a></p>



<p><a href="https://mehdinazari.com/query-wordpress-categories-tags-taxonomies/" target="_blank" rel="noreferrer noopener">How to Query WordPress Categories, Tags and Taxonomies</a></p><p>The post <a href="https://mehdinazari.com/get-category-id-by-name-wordpress/">How to Get Category ID by Name in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/get-category-id-by-name-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Count Users in WordPress (Example + Shortcode)</title>
		<link>https://mehdinazari.com/count-users-wordpress-php-code/</link>
					<comments>https://mehdinazari.com/count-users-wordpress-php-code/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 20:10:58 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=891</guid>

					<description><![CDATA[<p>WP Developers can retrieve the number of registered users when developing plugins or themes. WordPress&#160;introduced the count_users function to get the count of users when you need it. Also, the count_users function will give a detailed user count based on user roles. In this WordPress tutorial, we&#8217;re going to try the count_users function in a [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/count-users-wordpress-php-code/">How to Count Users in WordPress (Example + Shortcode)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>WP Developers can retrieve the number of registered users when developing plugins or themes. WordPress&nbsp;introduced the count_users function to get the count of users when you need it.  Also, the count_users function will give a detailed user count based on user roles.</p>



<span id="more-891"></span>



<p>In this WordPress tutorial, we&#8217;re going to try the count_users function in a working environment.</p>



<p>To get more into it, I&#8217;m going to make a shortcode out of <a href="https://developer.wordpress.org/reference/functions/count_users/" target="_blank" rel="noreferrer noopener">the <code>count_users</code> function</a> so that you can print the number anywhere you want using simple code.</p>



<p>We&#8217;ll have an extra step to make this function a shortcode, but you can think of it as a bonus tutorial.</p>



<h2 class="wp-block-heading">How to Count Users in WordPress using the <code>count_users</code> function?</h2>



<p>When you are running the count_users function, this function will return an array.</p>



<p>Returned array from the <code>count_users</code> function has a <code>total_users</code> key that contains the number of all users.</p>



<p>But what if you need to count users for each user role? Well, the returned array has that data too!</p>



<p><code>avail_roles</code> is the key that provides an array value that contains the user count for each available user role.</p>



<p>Example of the <code>count_users</code> function output (fresh WordPress installation):</p>



<pre><code class="language-php">Array
(
    [total_users] =&gt; 1
    [avail_roles] =&gt; Array
        (
            [administrator] =&gt; 1
            [none] =&gt; 0
        )

)</code></pre>



<h2 class="wp-block-heading">How to print the <code>count_users</code> function output in a shortcode?</h2>



<p>To add a shortcode in WordPress, you must use <a href="https://developer.wordpress.org/reference/functions/add_shortcode/" target="_blank" rel="noreferrer noopener">the <code>add_shortcode</code> function</a> to register it.</p>



<p>The <code>add_shortcode</code> function gets two parameters, a unique tag and a callback which is the name of our custom user counter function.</p>



<p>Add the below codes to your current theme&#8217;s <code>functions.php</code> file or your custom plugin:</p>



<pre><code class="language-php">add_shortcode('count-users', 'my_custom_user_counter');
function my_custom_user_counter() {
	return count_users()["total_users"];
}</code></pre>



<p>After adding this code to your WordPress, you can use it inside the WordPress editor or within the <a href="https://developer.wordpress.org/reference/functions/do_shortcode/" target="_blank" rel="noreferrer noopener"><code>do_shortcode</code> function</a>:</p>



<pre><code class="language-php">[count-users]</code></pre>



<p>I encourage you to create your own plugin to test codes in a more organized way.</p>



<p>If you do not know how to create a <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/" target="_blank" rel="noreferrer noopener">Simple WordPress Plugin</a>, read my tutorial:</p>



<p><a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/" target="_blank" rel="noreferrer noopener">How to create a Hello World plugin for WordPress in 3 Steps</a></p><p>The post <a href="https://mehdinazari.com/count-users-wordpress-php-code/">How to Count Users in WordPress (Example + Shortcode)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/count-users-wordpress-php-code/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Count Comments on a Post in WP Programmatically</title>
		<link>https://mehdinazari.com/how-many-comments-post-has-wordpress/</link>
					<comments>https://mehdinazari.com/how-many-comments-post-has-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 20:07:55 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=889</guid>

					<description><![CDATA[<p>The get_comments_number function will retrieve the number of comments for a post in WordPress. Do you want to check how many comments does a post has? Use the get_comments_number function with its easy syntax to get comments numbers for a post using ID. The reason you want to count the comments of a post is [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/how-many-comments-post-has-wordpress/">How to Count Comments on a Post in WP Programmatically</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>The get_comments_number function will retrieve the number of comments for a post in WordPress. Do you want to check how many comments does a post has? Use the get_comments_number function with its easy syntax to get comments numbers for a post using ID.</p>



<span id="more-889"></span>



<p>The reason you want to count the comments of a post is obvious. After all, comments are the primary way we communicate with our website/blog visitors.</p>



<p>We&#8217;ll review <a href="https://developer.wordpress.org/reference/functions/get_comments_number/" target="_blank" rel="noreferrer noopener">the <code>get_comments_number</code> function </a>and try its usage in a working example.</p>



<h2 class="wp-block-heading"><code>get_comments_number</code> function syntax</h2>



<p><a href="https://mehdinazari.com/" target="_blank" rel="noreferrer noopener">WP developers</a> can use  <code>get_comments_number</code> function to get the number of comments on a post.</p>



<p>This function accepts one argument for post reference.</p>



<pre><code class="language-php">get_comments_number($post_id)</code></pre>



<p><code>$post_id</code> can be a specific post&#8217;s ID or a post object.</p>



<h2 class="wp-block-heading">Counting comments in WordPress using <code></code><code>get_comments_number</code> function</h2>



<p>The easiest way to retrieve comments number is to use <code></code><code>get_comments_number</code> function in WP.</p>



<p>I&#8217;m going to show you, how you can retrieve the number of comments on a post with ID 1.</p>



<p>Working example of <code></code><code>get_comments_number</code> function:</p>



<pre><code class="language-php">$post_id = 1; //set the post id
get_comments_number($post_id);</code></pre><p>The post <a href="https://mehdinazari.com/how-many-comments-post-has-wordpress/">How to Count Comments on a Post in WP Programmatically</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/how-many-comments-post-has-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Add a Custom Shortcode to WordPress (+Example)</title>
		<link>https://mehdinazari.com/add-custom-shortcode-wordpress/</link>
					<comments>https://mehdinazari.com/add-custom-shortcode-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 19:56:30 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Hooks]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=874</guid>

					<description><![CDATA[<p>Shortcodes are helpful when WordPress admins want to run a function and return the result with a simple code. Developers can create a new shortcode for moderators to use when the process of calling a function is complicated or admins want to run a function on multiple pages themselves. Website moderators who do not know [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/add-custom-shortcode-wordpress/">How to Add a Custom Shortcode to WordPress (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Shortcodes are helpful when WordPress admins want to run a function and return the result with a simple code. Developers can create a new shortcode for moderators to use when the process of calling a function is complicated or admins want to run a function on multiple pages themselves. Website moderators who do not know how to code PHP often use simple shortcodes inside WordPress editor.</p>



<span id="more-874"></span>



<p>WordPress has a simple function to create custom shortcodes, its called <code>add_shortcode</code>.</p>



<p>In this <a href="https://mehdinazari.com">WordPress tutorial</a>, we&#8217;re going to add a custom shortcode using <a href="https://developer.wordpress.org/reference/functions/add_shortcode/" target="_blank" rel="noreferrer noopener">the add_shortcode function in WordPress</a>.</p>



<p>For completing the tutorial we&#8217;re going to run this shortcode inside the editor and see what happens.</p>



<h2 class="wp-block-heading">Explaining <code>add_shortcode</code> function</h2>







<pre><code class="language-php">add_shortcode($tag, $callback)</code></pre>







<h2 class="wp-block-heading">How to use the <code>add_shortcode</code> to add a new shortcode in WordPress?</h2>



<h3 class="wp-block-heading">Adding a new shortcode</h3>







<h3 class="wp-block-heading">Testing if the shortcode works</h3><p>The post <a href="https://mehdinazari.com/add-custom-shortcode-wordpress/">How to Add a Custom Shortcode to WordPress (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/add-custom-shortcode-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Register a Custom Image Size in WordPress (+Example)</title>
		<link>https://mehdinazari.com/register-custom-image-size-wordpress/</link>
					<comments>https://mehdinazari.com/register-custom-image-size-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 19:50:48 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=867</guid>

					<description><![CDATA[<p>Registering a New Image Size helps WordPress developers generate different images when the administrator uploads them on the admin panel. In this tutorial, we&#8217;ll look at the add_image_size function, responsible for registering a new image size in WordPress. WordPress has a helpful function for adding a new image size. Guess what the function name is? [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/register-custom-image-size-wordpress/">How to Register a Custom Image Size in WordPress (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Registering a New Image Size helps WordPress developers generate different images when the administrator uploads them on the admin panel. In this tutorial, we&#8217;ll look at the add_image_size function, responsible for registering a new image size in WordPress.</p>



<span id="more-867"></span>



<p>WordPress has a helpful function for adding a new image size.</p>



<p>Guess what the function name is? <code>add_image_size</code>!</p>



<p>Using <a href="https://developer.wordpress.org/reference/functions/add_image_size/">the <code>add_image_size</code> function</a> is possible in the <code>functions.php</code> file of your current theme or a <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">custom-made WordPress plugin</a>.</p>



<h2 class="wp-block-heading"><code>add_image_size</code> function syntax in WordPress</h2>



<p>the add_image_size function needs a name, width, height, and optional crop ability.</p>



<pre><code class="language-php">add_image_size( string $name, int $width, int $height, bool|array $crop = false )</code></pre>



<p><code>$name</code> must be string, setting a unique name is required for the new image size.</p>



<p><code>$width</code> and <code>$height</code> are integers, and their names represent what they do.</p>



<p><code>$crop</code> can be true, false, or an array containing the x and y positions of the crop (Ex: <code>array("left", "top")</code>).</p>



<p>You can use ‘left’, ‘center’, or ‘right’ for <code>x</code> position and ‘top’, ‘center’, or ‘bottom’ for <code>y</code> position.</p>



<h2 class="wp-block-heading">Example of adding a new image size using <code>add_image_size</code> function</h2>



<p>Using the <code>add_image_size</code> function is not challenging for a <a href="https://mehdinazari.com">WordPress developer</a>.</p>



<p>In the below example, I registered three different image sizes with different attributes:</p>



<pre><code class="language-php">//name: 500-500, with:500px, height:500px, forced crop:
add_image_size("500-500", 500, 500, true);

//name: custom-size, with:300px, height:200px, no crop:
add_image_size("custom-size", 300, 200, false);

//name: custom-cropped-size, with:150px, height:100px, crop from center:
add_image_size("custom-cropped-size", 150, 100, array("center", "center"));</code></pre>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><strong>Note:</strong> if thumbnails are not generating at all (even for default options), check if GD is enable in your PHP.</p>



<p>To do that, open <code>php.ini</code> file in the server and search for <code>extension=gd</code> in the file. If you see <code>;</code> character in the begining of it&#8217;s declaration line, remove the <code>;</code> to enable GD.</p>



<p>Then restart the web server.</p>
</blockquote>



<h2 class="wp-block-heading">How to regenerate older images based on the new registered image size?</h2>



<p>Registering a new image size will apply to future image uploads in the admin panel.</p>



<p>You can use the <a href="https://wordpress.org/plugins/regenerate-thumbnails/" target="_blank" rel="noopener" title="">Regenerate Thumbnails plugin</a> to regenerate image sizes for older images.</p>



<p>I used this plugin so many times. It has the option to skip image sizes that are already available in files.</p><p>The post <a href="https://mehdinazari.com/register-custom-image-size-wordpress/">How to Register a Custom Image Size in WordPress (+Example)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/register-custom-image-size-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Set Post Excerpt Length in WordPress</title>
		<link>https://mehdinazari.com/how-to-set-post-excerpt-lenght-in-wordpress/</link>
					<comments>https://mehdinazari.com/how-to-set-post-excerpt-lenght-in-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Mon, 01 Nov 2021 20:07:17 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Hooks]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=460</guid>

					<description><![CDATA[<p>WordPress excerpt_length filter is responsible for modifying the default length for post excerpts. WordPress lets developers set their desired length for printing excerpts on themes. We want to try it in a working example to show you how the excerpt_length filter works in WordPress and how you can use this filter in your themes. Smart [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/how-to-set-post-excerpt-lenght-in-wordpress/">How to Set Post Excerpt Length in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>WordPress excerpt_length filter is responsible for modifying the default length for post excerpts. WordPress lets developers set their desired length for printing excerpts on themes. We want to try it in a working example to show you how the excerpt_length filter works in WordPress and how you can use this filter in your themes.</p>



<span id="more-460"></span>



<p>Smart developers always use <a href="https://mehdinazari.com/wordpress-action-filter-hooks-tutorial/">WordPress filters and actions</a> if they want to modify any core functionality and data.</p>



<p>WordPress introduced <a href="https://developer.wordpress.org/reference/hooks/excerpt_length/" target="_blank" rel="noreferrer noopener">the <code>excerpt_length</code> filter</a> to use when you want to modify the except length of posts.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>The default excerpt length is 55 words in WordPress.</p>
</blockquote>



<p>To change this number in a working example, you need to modify <code>functions.php</code> file of your current theme or <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/" target="_blank" rel="noreferrer noopener">create a simple WordPress plugin</a>.</p>



<p>If you are editing the <code>functions.php</code> file of your theme, use these codes at the end of the file.</p>



<h2 class="wp-block-heading">How to use <code>excerpt_length</code> filter in WordPress</h2>



<p>Like <a href="https://mehdinazari.com/wordpress-action-filter-hooks-tutorial/">using other WordPress filters</a>. you can use excerpt_length filter easily:</p>



<pre><code class="language-php">add_filter('excerpt_length', function($length) {
	return 20; //sets length to 20!
}, 1000);</code></pre>



<p>Copy and paste this code to your active theme <code>functions.php</code> or your custom plugin file.</p>



<p>These codes will change WordPress default excerpt length from 40 to 20. You can use any number instead.</p><p>The post <a href="https://mehdinazari.com/how-to-set-post-excerpt-lenght-in-wordpress/">How to Set Post Excerpt Length in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/how-to-set-post-excerpt-lenght-in-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get Associated Tags to a WordPress Post (5 Examples)</title>
		<link>https://mehdinazari.com/tags-of-post-wordpress/</link>
					<comments>https://mehdinazari.com/tags-of-post-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Mon, 01 Nov 2021 20:07:01 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<category><![CDATA[WordPress Tags]]></category>
		<category><![CDATA[WordPress tutorials for beginners]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=689</guid>

					<description><![CDATA[<p>WordPress get_the_tags function is responsible for retrieving associated tags of a post. WordPress developers need to specify post ID to receive an array containing tag IDs, Names, Slugs in full-detailed term objects. Read this tutorial for general information about tagging, its usage, and testing the get_the_tags function in working examples. What are tags, and why [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/tags-of-post-wordpress/">How to Get Associated Tags to a WordPress Post (5 Examples)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>WordPress get_the_tags function is responsible for retrieving associated tags of a post. WordPress developers need to specify post ID to receive an array containing tag IDs, Names, Slugs in full-detailed term objects. Read this tutorial for general information about tagging, its usage, and testing the get_the_tags function in working examples.</p>



<span id="more-689"></span>



<h2 class="wp-block-heading">What are tags, and why is tagging an essential feature for blogging systems?</h2>



<p>Just like categories, Tags are one of the default tools to organize content in WordPress.</p>



<p>Administrators or developers often use tags to relate posts to each other for future listings.</p>



<p>For example, it is genius to use tags to display related articles to each post. </p>



<p>Tagging posts will help you optimize your content for search engines and improve your inbound link building.</p>



<p><strong>Tags are one of the first features of WordPress editor</strong>.</p>



<p>As a <a href="https://mehdinazari.com" target="_blank" rel="noreferrer noopener">WordPress developer</a> who writes blog posts and Loves SEO technics, I consider tags an essential feature to use.</p>



<h2 class="wp-block-heading">How to assign tags to WordPress posts?</h2>



<p>Defining tags is simple when you are using WordPress editor. Any editor can assign tags to posts while editing them.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1024" height="190" src="https://mehdinazari.com/wp-content/uploads/2021/11/wordpress-tags.jpg" alt="Add tags to WordPress post" class="wp-image-806" srcset="https://mehdinazari.com/wp-content/uploads/2021/11/wordpress-tags.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2021/11/wordpress-tags-300x56.jpg 300w, https://mehdinazari.com/wp-content/uploads/2021/11/wordpress-tags-768x143.jpg 768w, https://mehdinazari.com/wp-content/uploads/2021/11/wordpress-tags-800x148.jpg 800w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Add tags to a WordPress post in the editor</figcaption></figure>
</div>


<p>As you can see in the screenshot I took while typing this post; you can add a new tag by typing inside the bordered area.</p>



<p>If a tag is available containing the typed word, WordPress will suggest it to you; If not, you can add it as a new tag by just hitting enter on your keyboard.</p>



<h2 class="wp-block-heading">How to list tags assigned to a post programmatically?</h2>



<p>Listing associated tags of a post is a smart thing to do for user experience and SEO.</p>



<p><a href="https://developer.wordpress.org/reference/functions/get_the_tags/" target="_blank" rel="noreferrer noopener">WordPress introduced the <code>get_the_tags</code> function for developers</a> to retrieve associated tags of a post.</p>



<p><code>get_the_tags</code> function syntax:</p>



<pre><code class="language-php">get_the_tags(int|WP_Post $postId)</code></pre>



<p><code>get_the_tags</code> receives one required argument. Developers must specify post ID or post object for this function to run properly.</p>



<p>If post ID existed and tags were available, the <code>get_the_tags</code> function will return an array of <a href="https://developer.wordpress.org/reference/classes/wp_term/">WP_Term</a> objects.</p>



<p>Examples of using <code>get_the_tags</code> function:</p>



<h3 class="wp-block-heading">1- Retrieve Tag IDs array for a post</h3>



<p>PHP <code>array_map</code>  is the helper function for us to use when we want only one field of returned objects.</p>



<p>For this example, we want the <code>term_id</code> field of wp_term objects:</p>



<pre><code class="language-php">
$postId = 1;
$tagObjects = get_the_tags($postId);
$tagIds = array();
if($tagObjects){
	$tagIds = array_map(function($tag){return $tag-&gt;term_id;}, $tagObjects);//PHP 5.3 or newer
}</code></pre>



<h3 class="wp-block-heading">2- Retrieve tag names of a post</h3>



<p>Using PHP <code>array_map</code> is the solution again.</p>



<pre><code class="language-php">
$postId = 1;
$tagObjects = get_the_tags($postId);
$tagNames = array();
if($tagObjects){
	$tagNames = array_map(function($tag){return $tag-&gt;name;},$tagObjects);
}</code></pre>



<h3 class="wp-block-heading">3- Retrieve full detailed tag objects associated to a post</h3>



<p><code>get_the_tags</code> function will return the full detailed object of post associated tags.</p>



<pre><code class="language-php">$postId = 1;
$tagObjects = get_the_tags($postId);</code></pre>



<p>Returned data is structured like below:</p>



<pre><code class="language-php">Array
(
    [0] =&gt; WP_Term Object
        (
            [term_id] =&gt; 6 //a possible ID!
            [name] =&gt; lorem
            [slug] =&gt; lorem
            [term_group] =&gt; 0
            [term_taxonomy_id] =&gt; 6
            [taxonomy] =&gt; post_tag
            [description] =&gt; 
            [parent] =&gt; 0
            [count] =&gt; 2
            [filter] =&gt; raw
        )

)
</code></pre>



<h3 class="wp-block-heading">4- Ordering tags associated with a post</h3>



<p>For ordering received tags you must use the <code>usort</code> PHP function to set the order.</p>



<p>Sort returned tags by name:</p>



<pre><code class="language-php">$postId = 1;
$tagObjects = get_the_tags($postId);
usort($tagObjects, function($a, $b) {return strcmp($a-&gt;name, $b-&gt;name);}); //sorting by name!</code></pre>



<p>Sorting returned tags by id:</p>



<pre><code class="language-php">$postId = 1;
$tagObjects = get_the_tags($postId);
usort($tagObjects, function($a, $b) {return $a-&gt;term_id &gt; $b-&gt;term_id;}); //sorting by id!</code></pre>



<h3 class="wp-block-heading">5- Filtering <code>get_the_tags</code> function result</h3>



<p>We must use the <code>array_filter</code> PHP function to filter received tags based on wp_term object available attributes.</p>



<pre><code class="language-php">$postId = 1;
$tagObjects = get_the_tags($postId);
//filter a tag name (i used "test" for tag name):
$filteredData = array_filter($tagObjects, function($tag) {return $tag-&gt;name === "test";});</code></pre>



<h2 class="wp-block-heading">More information about WordPress tagging and its related functions and methods</h2>



<p>WordPress&#8217;s official website is the most comprehensive place to find information about WordPress core features.</p>



<p>I recommend you search the official WordPress website to <a href="https://developer.wordpress.org/?s=tags" target="_blank" rel="noreferrer noopener">find all available functions related to tags</a>.</p>



<p>Read my tutorial &#8220;<a href="https://mehdinazari.com/query-wordpress-categories-tags-taxonomies/">How to Query WordPress Categories, Tags and Taxonomies</a>&#8220;, to dive deeper into the WordPress taxonomy feature.</p>



<p>If you are new to WordPress development, learn how to create a plugin in this tutorial:</p>



<p><a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">How to create a Hello World plugin for WordPress</a></p><p>The post <a href="https://mehdinazari.com/tags-of-post-wordpress/">How to Get Associated Tags to a WordPress Post (5 Examples)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/tags-of-post-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get Categories of a Post in WordPress (3 Examples!)</title>
		<link>https://mehdinazari.com/categories-of-post-wordpress/</link>
					<comments>https://mehdinazari.com/categories-of-post-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Mon, 01 Nov 2021 12:03:03 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=686</guid>

					<description><![CDATA[<p>wp_get_post_categories function will help WordPress developers retrieve post categories (Name, ID, Slug, ETC). wp_get_post_categories receives a required Post ID and an optional array of arguments. In this WordPress tutorial, we&#8217;ll try retrieving Post Categories using the wp_get_post_categories function. While developing WordPress, It is essential to know how to retrieve a list of categories for a [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/categories-of-post-wordpress/">How to Get Categories of a Post in WordPress (3 Examples!)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>wp_get_post_categories function will help WordPress developers retrieve post categories (Name, ID, Slug, ETC).  wp_get_post_categories receives a required Post ID and an optional array of arguments. In this WordPress tutorial, we&#8217;ll try retrieving Post Categories using the wp_get_post_categories function.</p>



<span id="more-686"></span>



<p>While developing WordPress, It is essential to know how to retrieve a list of categories for a specific post.</p>



<p>WordPress introduced a beneficial function for developers to receive post categories using a post ID.</p>



<h2 class="wp-block-heading">Introducing <code>wp_get_post_categories</code> function</h2>



<p><a target="_blank" href="https://developer.wordpress.org/reference/functions/wp_get_post_categories/" rel="noreferrer noopener">wp_get_post_categories function</a>&nbsp;receives two parameters, the first one is required, and the second one is optional.</p>



<h3 class="wp-block-heading"><code>wp_get_post_categories</code> function syntax</h3>



<p><code>wp_get_post_categories</code> function has a mandatory parameter.</p>



<p>The developer must specify the post ID by passing it as the first parameter.</p>



<p>The second parameter is optional, but if you want to specify the parameter, it must have the type of array.</p>



<pre><code class="language-php">wp_get_post_categories(int $post_id, array $args)</code></pre>



<h3 class="wp-block-heading">3 Examples of using wp_get_post_categories function</h3>



<h4 class="wp-block-heading">1- Get category IDs of a WordPress post</h4>



<p>By default, the  <code>wp_get_post_categories</code> function will return an array of category IDs if available:</p>



<pre><code class="language-php">$postId = 1;
$categoryIds = wp_get_post_categories($postId);</code></pre>



<h4 class="wp-block-heading">2- Get category names of a WordPress post</h4>



<p>Retrieving category names is also an easy task, we must define the second parameter of <code>wp_get_post_categories</code>  function which must be an array.</p>



<p>In the defined array we need to specify the <code>field</code> key to tell WordPress what attributes of an array we want to receive?</p>



<p>Example of defining arguments array to receive category names instead of IDs:</p>



<pre><code class="language-php">$postId = 1;
$args = array("fields"=&gt;"names");
$categoryNames = wp_get_post_categories($postId, $args);</code></pre>



<h4 class="wp-block-heading">3- Get category objects of a WordPress post (full details)</h4>



<p>for full details of categories, like the previous example, you need to specify the <code>field</code> key for arguments array.</p>



<p>If the <code>field</code> key in arguments array is set to <code>all</code>, you will receive an array of <code>WP_Term</code> objects which contain ID, name, slug, description, count, and ETC.</p>



<pre><code class="language-php">$postId = 1;
$args = array("fields"=&gt;"all");
$categoryObjects = wp_get_post_categories($postId, $args);</code></pre>



<p>A possible result is something like below:</p>



<pre><code class="language-php">Array
(
    [0] =&gt; WP_Term Object
        (
            [term_id] =&gt; 1
            [name] =&gt; Uncategorized
            [slug] =&gt; uncategorized
            [term_group] =&gt; 0
            [term_taxonomy_id] =&gt; 1
            [taxonomy] =&gt; category
            [description] =&gt; 
            [parent] =&gt; 0
            [count] =&gt; 4
            [filter] =&gt; raw
        )

)</code></pre>



<h2 class="wp-block-heading">Explaining <code>wp_get_post_categories</code> arguments</h2>



<h3 class="wp-block-heading">What details can I get from <code>wp_get_post_categories</code> function in WordPress?</h3>



<p><code>wp_get_post_categories</code> function lets developers decide what type of data they want to receive from a specifically filtered result list.</p>



<p>You can filter results easily by using available WordPress filters for terms, <a href="https://developer.wordpress.org/reference/classes/wp_term_query/__construct/" target="_blank" rel="noreferrer noopener">read available filters for terms on the WordPress official</a> page.</p>



<h4 class="wp-block-heading">Ordering returned results by <code>wp_get_post_categories</code> function</h4>



<p>To order results, you must define <code>order</code> key of arguments array.</p>



<p>Results can be ordered by: &#8216;name&#8217;, &#8216;slug&#8217;, &#8216;term_group&#8217;, &#8216;term_id&#8217;, &#8216;id&#8217;, &#8216;description&#8217;, &#8216;parent&#8217;, &#8216;term_order&#8217;, &#8216;slug__in&#8217;, &#8216;count&#8217;, &#8216;meta_value&#8217;.</p>



<p>For example, we can order categories by name instead of ID, using below code:</p>



<pre><code class="language-php">$postId = 1;
$args = array(
	"fields" =&gt; "all",
	"order" =&gt; "ASC",//direction
	"orderby" =&gt; "name", //attribute to order by
);
$categoryObjects = wp_get_post_categories($postId, $args);</code></pre>



<h4 class="wp-block-heading">Filtering post categories returned by <code>wp_get_post_categories</code>  function</h4>



<p>Filtering results is easy, you can define either one of available filters (<a href="https://developer.wordpress.org/reference/classes/wp_term_query/__construct/" target="_blank" rel="noreferrer noopener">read offcial page</a>) in arguments array.</p>



<p>For example to search a category, you can use <code>search</code> key for argument array:</p>



<pre><code class="language-php">$postId = 1;
$searchName = "uncategorized";//search a name!
$args = array(
	"fields" =&gt; "all",
	"search" =&gt; $searchName
);
$categoryObjects = wp_get_post_categories($postId, $args);</code></pre>



<p>beside <code>search</code> key, you can use <code>name__</code>like or <code>description__like</code> to specify which attribute you want to search for a word.</p>



<h3 class="wp-block-heading">Where can I find more information about the <code>wp_get_post_categories</code> function?</h3>



<p>Keep reading about categories; there are a lot more details to explore.</p>



<p>I recommend you read the “<a target="_blank" href="https://mehdinazari.com/query-wordpress-categories-tags-taxonomies/" rel="noreferrer noopener">How to Query WordPress Categories, Tags and Taxonomies</a>” article on my blog.</p>



<p>This article can help you do stuff with categories. Also, it will introduce you to WordPress taxonomies and a lot more!</p>



<p>Also WordPress has the perfect <a href="https://developer.wordpress.org/reference/functions/wp_get_post_categories/" target="_blank" rel="noreferrer noopener">official page for developers about  <code>wp_get_post_categories</code> function</a>.</p><p>The post <a href="https://mehdinazari.com/categories-of-post-wordpress/">How to Get Categories of a Post in WordPress (3 Examples!)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/categories-of-post-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get Post Title in WordPress (2 Examples!)</title>
		<link>https://mehdinazari.com/post-title-wordpress/</link>
					<comments>https://mehdinazari.com/post-title-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Mon, 01 Nov 2021 04:06:49 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=687</guid>

					<description><![CDATA[<p>get_the_title is the core function responsible for retrieving Post Title in WordPress. We&#8217;ll try this function inside loops and with a specific post ID. This tutorial can be the only page you need to visit to learn how to print the title of a post when developing WordPress. Introducing get_the_title function: Responsible for retrieving Post [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/post-title-wordpress/">How to Get Post Title in WordPress (2 Examples!)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>get_the_title is the core function responsible for retrieving Post Title in WordPress. We&#8217;ll try this function inside loops and with a specific post ID. This tutorial can be the only page you need to visit to learn how to print the title of a post when developing WordPress.</p>



<span id="more-687"></span>



<h2 class="wp-block-heading">Introducing <code>get_the_title</code> function: Responsible for retrieving Post Title in WordPress</h2>



<p>Each WordPress Post has a Title, and You can retrieve this title for each post easily using the <code>get_the_title</code> function (read more on <a href="https://developer.wordpress.org/reference/functions/get_the_title/">WordPress official resources about  <code>get_the_title</code></a>).</p>



<p>It is optional for developers to specify ID (integer) or post object (WP_Post object) to retrieve a specific post&#8217;s title with the  <code>get_the_title</code>  function.</p>



<p>When you pass a specific ID (integer) or post object (WP_Post) to this function, it will retrieve the title of the specified post.</p>



<p><code>get_the_title</code> function syntax in WordPress:</p>



<pre><code class="language-php">get_the_title(int|WP_Post $post)</code></pre>



<p><code>get_the_title</code> is not that tricky to use, but we&#8217;ll try this function in a live WordPress environment to see what happens.</p>



<h2 class="wp-block-heading">How to get the title of a specific post using Post ID</h2>



<p>When you pass an id as an argument to the <code>get_the_title</code> function, it will return the post title (if available).</p>



<p>In this example, we tried printing the post title of a post with an id equal to 1:</p>



<pre><code class="language-php">$postId = 1;
echo get_the_title($postId);</code></pre>



<h2 class="wp-block-heading">How to get the title of the&nbsp;current post</h2>



<p>If tIf the developer does not specify the post ID or Object, the WordPress <code>get_the_title</code> function will retrieve the current queried object title.</p>



<p>There is a global <code>$post</code> variable in WordPress; When you use the <code>get_the_title</code> function with no argument, WordPress will check this variable for the ID.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Note: you can change the global <code>$post</code> (offen inside loops). then it is possible to run into conflicts when you did not reset the global <code>$post</code> back to it&#8217;s WordPress default after a loop.</p>



<p>use <a href="https://developer.wordpress.org/reference/functions/wp_reset_postdata/" target="_blank" rel="noreferrer noopener"><code>wp_reset_postdata</code> function</a> to reset <code>$post</code> object back to it&#8217;s original value after custom loops!</p>
</blockquote>



<pre><code class="language-php">$posts = new WP_Query(array('post_type' =&gt; 'post')); //retrieve posts
if($posts-&gt;have_posts() ) {
    while($posts-&gt;have_posts() ) {
        $posts-&gt;the_post();
        echo get_the_title();
    }
}</code></pre>



<p>If you want to try these codes, I recommend creating a plugin to organize your codes.</p>



<p>Creating a WordPress plugin is easy and fast.</p>



<p>You can read my <a href="https://mehdinazari.com/new-post-after-a-while/">Create a WordPress Hello World Plugin in 3 Steps</a> tutorial for a start.</p><p>The post <a href="https://mehdinazari.com/post-title-wordpress/">How to Get Post Title in WordPress (2 Examples!)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/post-title-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get WordPress Post Date Using PHP (+2 Examples)</title>
		<link>https://mehdinazari.com/post-date-wordpress/</link>
					<comments>https://mehdinazari.com/post-date-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Sun, 31 Oct 2021 16:13:14 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=688</guid>

					<description><![CDATA[<p>Retrieving Publish Date of a Post in WordPress is an easy task to do. We&#8217;ll try retrieving post attributes using a specific Post ID or current queried post id to show you how to work with Post Dates in WordPress using the get_the_date function. Retrieving publish date of a WordPress post using get_the_date function get_the_date [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/post-date-wordpress/">How to Get WordPress Post Date Using PHP (+2 Examples)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Retrieving Publish Date of a Post in WordPress is an easy task to do. We&#8217;ll try retrieving post attributes using a specific Post ID or current queried post id to show you how to work with Post Dates in WordPress using the get_the_date function.</p>



<span id="more-688"></span>



<h2 class="wp-block-heading">Retrieving publish date of a WordPress post using <code>get_the_date</code> function</h2>



<p><code>get_the_date</code> function is <a href="https://developer.wordpress.org/reference/functions/get_the_date/">introduced by WordPress</a> to let developers get publish date of a specific post ID or current post inside a loop.</p>



<p>This function receives 2 <strong>optional arguments</strong>:</p>



<ol class="wp-block-list">
<li><strong>Date format</strong>: you can specify the format, using <a href="https://www.php.net/manual/en/datetime.format.php" target="_blank" rel="noreferrer noopener">PHP date formats</a></li>



<li><strong>Post ID</strong> or <strong>WP_Post object</strong>: retrieving title of specific post</li>
</ol>



<p><code>get_the_date</code> syntax in WordPress:</p>



<pre><code class="language-php">get_the_date(string $format = '', int|WP_Post $post)</code></pre>



<p>Keep reading for examples&#8230;</p>



<h3 class="wp-block-heading">Get specific post publish date in WordPress using post ID</h3>



<p>In this example we&#8217;ll try to print publish date of a post with an ID equal to 1:</p>



<pre><code class="language-php">$postId = 1;
echo get_the_time('Y-m-d', $postId);</code></pre>



<h3 class="wp-block-heading">Get publish date of current post in WordPress</h3>



<p>If you are interested in printing publish date of the current post (inside a loop or <code>single.php</code> file), use <code>get_the_time</code> function <strong>with no post id</strong>.</p>



<p>Example of using this function inside a loop:</p>



<pre><code class="language-php">$posts = new WP_Query(array('post_type' =&gt; 'post')); //retrieve posts
if($posts-&gt;have_posts() ) {
    while($posts-&gt;have_posts() ) {
        $posts-&gt;the_post();
        echo get_the_time('Y-m-d'); //Echos date in Y-m-d format.
    }
}</code></pre>



<p><code>$posts-&gt;the_post()</code> will change the global <code>$post</code> object in WordPress. this object is the reference for the <code>get_the_time</code> function when you do not specify the ID.</p>



<p>Remember to reset the global <code>$post</code> object back to WordPress default after changing it. You only need to use <a href="https://developer.wordpress.org/reference/functions/wp_reset_postdata/" target="_blank" rel="noreferrer noopener">the <code>wp_reset_postdata</code> function</a> to reset it back after custom loops.</p>



<p>If you are a hard-working student, keep reading. you can read <a href="https://mehdinazari.com/new-post-after-a-while/">How to set publishing date and time for a WordPress post Programmatically?</a> in my tutorial archive.</p>



<p>A good start point for my new visitors is <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">How to create a Hello World plugin for WordPress in 3 Steps</a> article which contains good tips for those who want to use standard codes and methods.</p><p>The post <a href="https://mehdinazari.com/post-date-wordpress/">How to Get WordPress Post Date Using PHP (+2 Examples)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/post-date-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>4 Special Ways to Unpublish Post Programmatically in WordPress!</title>
		<link>https://mehdinazari.com/unpublish-posts-programmatically-wordpress/</link>
					<comments>https://mehdinazari.com/unpublish-posts-programmatically-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Sun, 31 Oct 2021 15:45:10 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<category><![CDATA[WordPress Tips]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=684</guid>

					<description><![CDATA[<p>There are 4 ways to unpublish a Post in WordPress using PHP codes. In this WordPress tutorial for beginners, we&#8217;ll try unpublishing a WordPress Post using WordPress core methods. 4 Ways to Unpublish a WordPress Post Programmatically When you develop WordPress themes or plugins, you may want to use the feature of unpublishing a WordPress [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/unpublish-posts-programmatically-wordpress/">4 Special Ways to Unpublish Post Programmatically in WordPress!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>There are 4 ways to unpublish a Post in WordPress using PHP codes. In this WordPress tutorial for beginners, we&#8217;ll try unpublishing a WordPress Post using WordPress core methods.</p>



<span id="more-684"></span>



<h2 class="wp-block-heading">4 Ways to Unpublish a WordPress Post Programmatically</h2>



<p>When you develop WordPress themes or plugins, you may want to use the feature of unpublishing a WordPress post. (read my <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">starter tutorial to Start Developing WordPress Plugins Fast</a>!)</p>



<p>Using either one of these methods to unpublish a WordPress post to hide it from visitors or users.</p>



<p>We use the <code>wp_update_post</code> method to update a specific post and unpublish it.</p>



<h3 class="wp-block-heading">1- Set Post Status as a Draft in WordPress using PHP</h3>



<p>Setting post status for a post is a way to unpublish a post without any harm.</p>



<p>Setting <code>post_status</code> to <code>draft</code> is a preffered way of unpublishing a post.</p>



<p>Set Draft post status for a post (using post ID):</p>



<pre><code class="language-php">$postId = 1;//change to your post ID

wp_update_post(array(
    'ID'    =&gt;  $postId,
    'post_status'   =&gt;  'draft'
));</code></pre>



<h3 class="wp-block-heading">2- Make the Post Visibility Private in WordPress using PHP</h3>



<p>Private posts are only accessible to admins and editors. If you set post visibility as private, it will be hidden to visitors.</p>



<p>Setting <code>post_status</code> of a post to <code>private</code> is a way of unpublishing WordPress posts.</p>



<p>Use this code to set post visibility of an ID to Private:</p>



<pre><code class="language-php">$postId = 1;//change to your post ID

wp_update_post(array(
    'ID'    =&gt;  $postId,
    'post_status'   =&gt;  'private'
));</code></pre>



<h3 class="wp-block-heading">3- Set Publish Date for Future in WordPress using PHP</h3>



<p>Setting a publish date for posts can do the trick too! you can use a future date to unpublish WordPress posts safe and without consequences.</p>



<p>I wrote a blog post about <a href="https://mehdinazari.com/new-post-after-a-while/">setting WordPress post publishing date programmatically</a>. you can read it for more information.</p>



<p>Example for setting WordPress post publish date:</p>



<pre><code class="language-php">$postId = 1;//change to your post ID

$date_time = "2050-12-31 23:59:59";//[Y-m-d H:i:s]
wp_update_post(
    array (
        'ID' =&gt; $postId,
        'post_date' =&gt; $date_time,
        'post_date_gmt' =&gt; get_gmt_from_date( $date_time )
    )
);</code></pre>



<h3 class="wp-block-heading">4- Delete the Post in WordPress using PHP!</h3>



<p>This is a harsh decision! removing a blog post is not something you decide this fast.</p>



<p>Display Warnings to the decision-makers if you are using this feature in a plugin.</p>



<pre><code class="language-php">$postId = 12341;

wp_delete_post($postId, false); //change false to true if you want to force delete this post!</code></pre><p>The post <a href="https://mehdinazari.com/unpublish-posts-programmatically-wordpress/">4 Special Ways to Unpublish Post Programmatically in WordPress!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/unpublish-posts-programmatically-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Query WordPress Categories, Tags &#038; Custom Taxonomies!</title>
		<link>https://mehdinazari.com/query-wordpress-categories-tags-taxonomies/</link>
					<comments>https://mehdinazari.com/query-wordpress-categories-tags-taxonomies/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Sat, 31 Jul 2021 10:23:33 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=311</guid>

					<description><![CDATA[<p>Learn how to list Categories, Tags, and Custom Taxonomies in WordPress using standard WP functions. In this WordPress tutorial for developers, we use get_categories, get_tags, and get_taxonomies functions with working examples. After reading this tutorial, you can list WordPress categories, tags, and taxonomies with all available filters. Key Points in WordPress Taxonomy Tutorial Before we [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/query-wordpress-categories-tags-taxonomies/">How to Query WordPress Categories, Tags & Custom Taxonomies!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Learn how to list Categories, Tags, and Custom Taxonomies in WordPress using standard WP functions. In this WordPress tutorial for developers, we use get_categories, get_tags, and get_taxonomies functions with working examples. After reading this tutorial, you can list WordPress categories, tags, and taxonomies with all available filters.</p>



<span id="more-311"></span>



<h2 class="wp-block-heading">Key Points in WordPress Taxonomy Tutorial</h2>



<ul class="wp-block-list">
<li><a href="#taxonomy" title="">Explaining WordPress taxonomies</a></li>



<li><a href="#query-categories" title="">Learn how to query categories</a></li>



<li><a href="#query-tags" title="">Learn how to query tags</a></li>



<li><a href="#query-custom-taxonomies" title="">Learn how to query custom taxonomies</a></li>



<li><a href="#resources" title="">Resources for WordPress taxonomies</a></li>
</ul>



<p>Before we begin the coding part of the tutorial, I would like to talk a little about WordPress Taxonomies.</p>



<h2 class="wp-block-heading" id="taxonomy"><a href="#taxonomy" title="">What are Taxonomies in WordPress?</a></h2>



<p><strong>Taxonomies are the mean of organizing WordPress posts</strong>. WordPress uses Taxonomies to label posts to organize them on different shelves.</p>



<p>In WordPress, <strong>categories &amp; tags are taxonomies</strong>. Also, developers can add custom taxonomies to make advanced organizing options for their items (Posts, Pages, Custom post types, etc.).</p>



<h3 class="wp-block-heading" id="term"><a href="#term" title="">What are Terms inside a Taxonomy?</a></h3>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Each item inside a taxonomy is a Term.</p>
</blockquote>



<p>You can have <strong>multiple terms inside a taxonomy</strong>.</p>



<p>For example, <strong>Tag is a Taxonomy</strong>, and each <strong>item you know as a tag is a Term for &#8220;Tag taxonomy&#8221;</strong>. Same thing for Category and each &#8220;Category Item&#8221;.</p>



<h3 class="wp-block-heading" id="default-taxonomies"><a href="#default-taxonomies" title="">What are the default Taxonomies in WordPress?</a></h3>



<p>WordPress has default taxonomies that we use inside a WordPress panel regularly.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Categories, Tags and Post Formats are default taxonomies in WordPress.</p>
</blockquote>



<h2 class="wp-block-heading">Query Taxonomies in WordPress</h2>



<p><code>get_terms</code> is the primary function we use to query taxonomies, but they are prettier functions available for categories and tags that run  <code>get_terms</code> under the hood.</p>



<p>Now if you want to get into action, remember these arguments because we will use them to filter the terms of each taxonomy.</p>



<h3 class="wp-block-heading">Default taxonomy arguments</h3>



<pre><code class="language-php">array(
   'taxonomy'=&gt;//only in get_terms
   'object_ids'   =&gt;
   'orderby' =&gt;
   'order'   =&gt;
   'hide_empty'   =&gt;//default is true!
   'include' =&gt;
   'exclude' =&gt; 
   'exclude_tree' =&gt; 
   'number'  =&gt; 
   'offset'  =&gt; 
   'fields'  =&gt; 
   'count'   =&gt; 
   'name'    =&gt; 
   'slug'    =&gt; 
   'term_taxonomy_id'  =&gt; 
   'hierarchical' =&gt; 
   'search'  =&gt; 
   'name__like'   =&gt; 
   'description__like' =&gt; 
   'pad_counts'   =&gt; 
   'get'=&gt; 
   'child_of'=&gt; 
   'parent'  =&gt; 
   'childless'    =&gt; 
   'cache_domain' =&gt; 
   'update_term_meta_cache' =&gt; 
   'meta_query'   =&gt; 
   'meta_key'=&gt; 
   'meta_value'   =&gt; 
   'meta_type'    =&gt; 
   'meta_compare' =&gt; 
);</code></pre>



<p>To those who want to see some code in this tutorial:</p>



<p>Developing WordPress is simple and fun, But if you want to run any code, you better know what it does and how it can affect your website.</p>



<p>I highly recommend you try codes on locally located WordPress installation before trying it online.</p>



<p>Also, you better <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/" target="_blank" rel="noreferrer noopener">create a WordPress plugin</a> first, then use codes inside it to have better control over them.</p>



<h3 class="wp-block-heading">Objects returned by the get_taxonomies function in WordPress</h3>



<p>You will receive an array of WP_Term objects when you use <code>get_taxonomies</code> to retrieve taxonomy items.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><strong>Note:</strong> <code>get_categories</code> and <code>get_tags</code> use <code>get_taxonomies</code> under the hood.</p>
</blockquote>



<p><code>WP_Term</code> object has useful attributes, which are listed below:</p>



<pre><code class="language-php">WP_Term Object {
    [term_id]
    [name]
    [slug]
    [term_group]
    [term_taxonomy_id]
    [taxonomy]
    [description]
    [parent]
    [count]
    [filter]
    [meta]
}</code></pre>



<h3 class="wp-block-heading" id="query-categories"><a href="#query-categories" title="">Query Categories in WordPress</a></h3>



<p><strong><code>get_categories</code> function</strong> in WordPress is available to <strong>retrieve category objects</strong> (WP_Term objects).</p>



<p>This function <strong>accepts arguments inside an array</strong> (just like <a href="https://mehdinazari.com/wordpress-query-posts/">query posts using WordPress</a>).</p>



<p><code>get_categories</code> function <strong>runs <code>get_terms</code> function under</strong> the hood. It&#8217;s just a little more readable.</p>



<h4 class="wp-block-heading">Query All Categories in WordPress</h4>



<p> <code>get_categories</code> with argument <code>hide_empty</code> set to <code>false</code> will give us all categories in WordPress:</p>



<pre><code class="language-php">//retrieving all posts using empty args
$args = array(
	"hide_empty" =&gt; false//to get all categories
);
$categories = get_categories($args);

//printing category name
foreach($categories as $category){
	echo $category-&gt;name." &lt;br /&gt;";
}</code></pre>



<h4 class="wp-block-heading">Query Top Level Categories in WordPress </h4>



<p>We use <code>get_category</code> function with <code>parent</code> argument set to <code>0</code>:</p>



<pre><code class="language-php">//retrieving all posts using parent id set to 0
$args = array(
	"hide_empty" =&gt; false,
	"parent" =&gt; 0
);

//retrieve categories
$categories = get_categories($args);

//printing category name
foreach($categories as $category){
	echo $category-&gt;name." &lt;br /&gt;";
}</code></pre>



<h4 class="wp-block-heading">Query Children of a Category in WordPress</h4>



<p><strong><code>parent</code> argument</strong> is the key to doing our task. This argument is <strong>used to query children of a specific category</strong> (using category ID).</p>



<p>In this example, we will use the parent category id set to 1 (change it to your category id):</p>



<pre><code class="language-php">//retrieving posts using parent id
$parentCategoryId = 1;
$args = array(
	"hide_empty" =&gt; false,
	"parent" =&gt; $parentCategoryId
);

//retrieve categories
$categories = get_categories($args);

//printing category name
foreach($categories as $category){
	echo $category-&gt;name." &lt;br /&gt;";
}</code></pre>



<h4 class="wp-block-heading">Order Categories in <code>get_categories</code></h4>



<p>You can manage category orders <strong>using <code>orderby</code> and <code>order</code> arguments</strong> in <code>get_categories()</code>.</p>



<p><strong><code>orderby</code> is defining order basis</strong> (&#8216;name&#8217;, &#8216;slug&#8217;, &#8216;term_group&#8217;, &#8216;term_id&#8217;, &#8216;id&#8217;, &#8216;description&#8217;, &#8216;parent&#8217;, &#8216;term_order&#8217;) and <strong><code>order</code> is the direction</strong> (<code>ASC</code> or <code>DESC</code>).</p>



<p>This example shows you how to order categories based on the category name in ascending (ASC) order:</p>



<pre><code class="language-php">//order by name
$args = array(
	"hide_empty" =&gt; false,
	"orderby" =&gt; "name",
	"order" =&gt; "ASC",
);

//retrieve categories
$categories = get_categories($args);

//printing category name
foreach($categories as $category){
	echo $category-&gt;name." &lt;br /&gt;";
}</code></pre>



<h3 class="wp-block-heading" id="query-tags"><a href="#query-tags" title="">Query Tags in WordPress</a></h3>



<p><strong><code>get_tags</code> function</strong> is responsible for <strong>retrieving tags</strong> with desired arguments.</p>



<p><code>get_tags()</code> <strong>runs <code>get_terms</code> function under</strong> the hood. Then it <strong>retrieves an array of <code>WP_Term</code> objects</strong> which are the tags.</p>



<h4 class="wp-block-heading">Query Tags with a Word in the Tag Name</h4>



<p><code><strong>name__like</strong></code> is the argument to <strong>retrieve tags based on the name</strong> in WordPress using <code>get_tags</code> function:</p>



<pre><code class="language-php">//set the word
$word = "test";

//order by name
$args = array(
	"hide_empty" =&gt; false,
	"name__like" =&gt; $word
);

//retrieve tags
$tags = get_tags($args);

//printing tag name
foreach($tags as $tag){
	echo $tag-&gt;name." &lt;br /&gt;";
}</code></pre>



<h4 class="wp-block-heading">Query Tags with a Word in the Tag Description</h4>



<p><code><strong>description__like</strong></code> is the argument that we can use with <code>get_tags</code> function to <strong>retrieve tags based on a word in their description</strong>:</p>



<pre><code class="language-php">//set the word
$word = "test";

//order by name
$args = array(
	"hide_empty" =&gt; false,
	"description__like" =&gt; $word
);

//retrieve tags
$tags = get_tags($args);

//printing tag name
foreach($tags as $tag){
	echo $tag-&gt;name." &lt;br /&gt;";
}</code></pre>



<h4 class="wp-block-heading">Order Tags in <code>get_tags</code></h4>



<p>Like categories, we use <code><strong>orderby</strong></code> and <code><strong>order</strong></code> arguments to set the order basis and its direction for querying tags.</p>



<p><code><strong>orderby</strong></code> is defining <strong>order basis</strong> (&#8216;name&#8217;, &#8216;slug&#8217;, &#8216;term_group&#8217;, &#8216;term_id&#8217;, &#8216;id&#8217;, &#8216;description&#8217;, &#8216;parent&#8217;, &#8216;term_order&#8217;) and <code><strong>order</strong></code> is the <strong>direction</strong> (<code>ASC</code> or <code>DESC</code>).</p>



<pre><code class="language-php">//order by name
$args = array(
	"hide_empty" =&gt; false,
	"orderby" =&gt; "name",
	"order" =&gt; "ASC"
);

//retrieve tags
$tags = get_tags($args);


//printing tag name
foreach($tags as $tag){
	echo $tag-&gt;name." &lt;br /&gt;";
}</code></pre>



<h3 class="wp-block-heading" id="query-custom-taxonomies"><a href="#query-custom-taxonomies" title="">Query Custom Taxonomies in WordPress</a></h3>



<p><code>get_terms</code> function in WordPress is available for querying custom taxonomies.</p>



<p>Like <code>get_categories</code> and <code>get_tags</code> functions, this function also receives arguments, but there is an extra <code>taxonomy</code> key in arguments to specify what type of taxonomy you want to retrieve.</p>



<pre><code class="language-php">//set taxonomy name
$taxonomyName = "taxonomy-name-here";

//set arguments for taxonomy
$args = array(
	"hide_empty" =&gt; false,
	"taxonomy" =&gt; $taxonomyName,
);

//retrieve terms
$terms = get_terms($args);

//printing term name
foreach($terms as $term){
	echo $term-&gt;name." &lt;br /&gt;";
}</code></pre>



<p>I will create a tutorial about adding Custom Taxonomies in WordPress; you better read it.</p>



<h2 class="wp-block-heading" id="resources"><a href="#resources" title="">Continue learning about WordPress Taxonomies</a></h2>



<p>A Professional WordPress Developer never stops learning. If you are interested in more information about taxonomies, I recommend visiting the <a href="https://wordpress.org/support/article/taxonomies/" title="">WordPress official page of Taxonomies</a> and <a href="https://developer.wordpress.org/plugins/taxonomies/" target="_blank" rel="noreferrer noopener">Taxonomies for Developers</a>.</p>



<p><a href="https://developer.wordpress.org/plugins/taxonomies/working-with-custom-taxonomies/">Working with custom taxonomies on WordPress&#8217;s official website</a> is also a great source of information for beginner developers.</p>



<p>StackExchange is a great place to <a href="https://wordpress.stackexchange.com/questions/ask" target="_blank" rel="noreferrer noopener">ask questions</a> or <a href="https://wordpress.stackexchange.com/questions/tagged/taxonomy" target="_blank" rel="noreferrer noopener">research other developers&#8217; issues with taxonomies in WordPress</a>.</p><p>The post <a href="https://mehdinazari.com/query-wordpress-categories-tags-taxonomies/">How to Query WordPress Categories, Tags & Custom Taxonomies!</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/query-wordpress-categories-tags-taxonomies/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Query Posts by Category, Tag, Custom Attribute, ETC</title>
		<link>https://mehdinazari.com/wordpress-query-posts/</link>
					<comments>https://mehdinazari.com/wordpress-query-posts/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Sat, 10 Jul 2021 13:14:30 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<category><![CDATA[WordPress plugin development for beginners]]></category>
		<category><![CDATA[WordPress tutorials for beginners]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=300</guid>

					<description><![CDATA[<p>Learn how to List Posts in WordPress using Category name, Tag name, Custom attributes, Post type, Publish date, Random posts, etc. For post listing in WordPress, we use get_posts function to retrieve any WordPress post with desired attributes. Listing posts is one of the primary parts of developing WordPress. In this tutorial, I will show [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/wordpress-query-posts/">How to Query Posts by Category, Tag, Custom Attribute, ETC</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Learn how to List Posts in WordPress using Category name, Tag name, Custom attributes, Post type, Publish date, Random posts, etc. For post listing in WordPress, we use get_posts function to retrieve any WordPress post with desired attributes.</p>



<span id="more-300"></span>



<p>Listing posts is one of the primary parts of developing WordPress. In this tutorial, I will show you the correct way of listing posts in WordPress (Programmatically).</p>



<h2 class="wp-block-heading">Retrieve posts in WordPress using <code>get_posts</code> function</h2>



<p><code>get_posts</code> function is responsible for getting WordPress posts in an array.</p>



<p>This function accepts an argument (array) which we use to describe what posts exactly do we want to get in the returning array.</p>



<p>Let&#8217;s look at this function syntax.</p>



<h3 class="wp-block-heading"><code>get_posts</code> function syntax in WordPress</h3>



<p>Simple get_posts syntax:</p>



<pre><code class="language-php">get_posts($args)</code></pre>



<p><code>$args</code> parameters is an <code>Array</code> and it can be Null. It means that it&#8217;s optional to specify arguments for <code>get_posts</code> function.</p>



<p>Now check out the list of available arguments for this function.</p>



<h3 class="wp-block-heading">Available arguments for <code>get_posts</code> function in WordPress</h3>



<p><code>get_posts</code> function arguments:</p>



<ul class="wp-block-list">
<li>numberposts</li>



<li>category</li>



<li>post_type</li>



<li>post_status</li>



<li>meta_query</li>



<li>meta_key</li>



<li>meta_value</li>



<li>post_parent</li>



<li>s</li>



<li>tax_query</li>



<li>date_query</li>



<li>paged</li>



<li>orderby</li>



<li>sort_order</li>



<li>posts_per_page</li>



<li>offset</li>



<li>include</li>



<li>exclude</li>



<li>suppress_filters</li>
</ul>



<h4 class="wp-block-heading"><code>numberposts</code> argument in get_posts function</h4>



<p>This argument specifies the number of posts you want to retrieve.</p>



<p>It accepts an integer value.</p>



<p>You can pass <code>-1</code> value to receive all posts in an array.</p>



<p>Default value for <code>numberposts</code> argument is <code>5</code>.</p>



<h4 class="wp-block-heading"><code>category</code> argument</h4>



<p>Value can be from the type of Integer or String.</p>



<p>When you pass an integer for the category, it refers to the category ID.</p>



<p>You can pass series of comma-separated IDs.</p>



<p>Default value for <code>category</code> argument is <code>0</code>.</p>



<h4 class="wp-block-heading"><code>post_type</code> argument</h4>



<p>WordPress has different post types, they are regular <code>posts</code> and <code>pages</code>. WordPress also lets developers add their own post types.</p>



<p>If you installed the Woocommerce plugin, another post type named <code>product</code> will be added to the list.</p>



<p><code>post_type</code> argument specifies the type of the post. the default value for this argument posts, not pages. this means if you do not specify post_type, posts will be retrieved not other post types like pages, products, or other custom post types (if available).</p>



<h4 class="wp-block-heading"><code>post_status</code> argument</h4>



<p>The status of posts you want to retrieve.</p>



<p>WordPress developers can add their own statuses as well.</p>



<p>Value of post_status can be one of these (or a custom post type added by a plugin):</p>



<ul class="wp-block-list">
<li>publish </li>



<li>future </li>



<li>pending </li>



<li>draft </li>



<li>auto-draft </li>



<li>private </li>



<li>trash </li>



<li>inherit </li>
</ul>



<h4 class="wp-block-heading"><code>meta_query</code> argument</h4>



<p>This argument helps you retrieve posts using custom fields relations.</p>



<p><code>meta_query</code> value is an array of arrays.</p>



<h4 class="wp-block-heading"><code>meta_key</code> argument</h4>



<p>This argument also helps you to retrieve posts using custom fields.</p>



<p><code>meta_key</code> + <code>meta_value</code> and <code>meta_compare</code> can give you posts with a specific custom field.</p>



<p><code>meta_key</code> is the name of the custom field you want to retrieve, but you must provide a value for the <code>meta_value</code> parameter as well.</p>



<h4 class="wp-block-heading"><code>meta_value</code> argument</h4>



<p>This argument specifies the value of <code>meta_key</code> you want to retrieve.</p>



<h4 class="wp-block-heading"><code>meta_compare</code> argument</h4>



<p>This argument specifies the relation between <code>meta_key</code> and <code>meta_value</code> you&#8217;ve provided.</p>



<p>If you do not specify this argument&#8217;s value, the default comparison relation will be equality (=).</p>



<h4 class="wp-block-heading"><code>post_parent</code> argument</h4>



<p>This argument specifies the parent ID of a post (page or whatever).</p>



<p>This parameter receives an integer. but the default value is NULL.</p>



<h4 class="wp-block-heading"><code>s</code> argument</h4>



<p>If you want to search inside posts, like finding a word in the titles or contents, you can use the <code>s</code> argument.</p>



<h4 class="wp-block-heading"><code>tax_query</code> argument</h4>



<p>This argument will help developers retrieve posts in specific taxonomy (category or custom taxonomy).</p>



<p><strong>Value is from type array</strong>, and the syntax is like below. You need to specify <code>taxonomy</code>, <code>field</code>, and <code>terms</code>.</p>



<p><code>tax_query</code> value for categories:</p>



<pre><code class="language-php">array(
	array(
		"taxonomy" =&gt; "category",
		"field"    =&gt; "slug",
		"terms"    =&gt; "category-slug-here, another-slug"
	)
)
</code></pre>



<h4 class="wp-block-heading"><code>date_query</code> argument</h4>



<p>This argument will help you query posts based on dates.</p>



<p>The value type of this argument is an array with specific keys:</p>



<ul class="wp-block-list">
<li><code>year</code></li>



<li><code>month</code></li>



<li><code>week</code></li>



<li><code>day</code></li>



<li><code>hour</code></li>



<li><code>minute</code></li>



<li><code>second</code></li>



<li><code>after</code></li>



<li><code>before</code></li>



<li><code>inclusive</code></li>



<li><code>compare</code></li>



<li><code>column</code> (default: post_date)</li>



<li><code>relation</code> (OR or AND).</li>
</ul>



<h4 class="wp-block-heading"><code>paged</code> argument</h4>



<p>Pagination ability in sets of posts is available using <code>paged</code> argument.</p>



<p><code>paged</code> is specifying which page of the posts list must be retrieved.</p>



<h4 class="wp-block-heading"><code>orderby</code> argument</h4>



<p>This argument will specify the order of the posts you want to retrieve, and it can be one of these values:</p>



<ul class="wp-block-list">
<li><code>ID</code></li>



<li><code>author</code></li>



<li><code>title</code></li>



<li><code>name</code></li>



<li><code>type</code></li>



<li><code>date</code></li>



<li><code>modified</code></li>



<li><code>parent</code></li>



<li><code>rand</code></li>



<li><code>comment_count</code></li>
</ul>



<h4 class="wp-block-heading"><code>sort_order</code> argument</h4>



<p>The sort order can be <code>ASC</code> for ascending or <code>DESC</code> for descending order.</p>



<h4 class="wp-block-heading"><code>posts_per_page</code> argument</h4>



<p>This argument is an alias for <code>numberposts</code> but with a little difference.</p>



<p><code>posts_per_page</code> is specifying the number of posts per page, but <code>numberposts</code> is specifying the whole post set number (which does not matter for you anyway! usually you want posts on the page we are in)</p>



<p>You can practically use <code>posts_per_page</code> or <code>numberposts</code> to specify the number of posts you want to retrieve.</p>



<p>The default value for <code>posts_per_page</code> argument is defined on your WordPress settings page.</p>



<h4 class="wp-block-heading"><code>offset</code> argument</h4>



<p>This argument specifies how many posts you want to ignore before you start with your post list.</p>



<p>For example, if you have 20 posts, when you set offset to 5, you will ignore the first 5 post items and get the posts from 6 to whatever you specified.</p>



<h4 class="wp-block-heading"><code>include</code> argument</h4>



<p>For those who want to include specific post ids or slugs to the query, WordPress added <code>include</code> argument to the list.</p>



<p>This argument tells the <code>get_posts</code> function to retrieve posts only from these IDs or slugs.</p>



<h4 class="wp-block-heading"><code>exclude</code> argument</h4>



<p>If developers want to exclude specific post IDs or slugs from retrieving, they can use <code>exclude</code> argument.</p>



<p>This argument&#8217;s value can be an ID or slug of a post (comma-separated IDs or slugs).</p>



<h4 class="wp-block-heading"><code>suppress_filters</code> argument</h4>



<p>This argument helps developers to prevent filters from altering the query. The default value for <code>suppress_filters</code> is <code>true</code>.</p>



<h3 class="wp-block-heading">What is the data structure returned from <code>get_posts</code> function in WordPress?</h3>



<p>When you run the <code>get_posts</code> function, if it finds any post matching required arguments, it will return an <a href="https://developer.wordpress.org/reference/functions/get_posts/#comment-2101" target="_blank" rel="noreferrer noopener">array of post objects</a>.</p>



<p>The post object will have the ID, Author, Date, Title, Excerpt, Status, Comment Status, Ping Status, Password, Slug, Comment Count, Type, ETC.</p>



<h5 class="wp-block-heading">The full structure of a post object</h5>



<pre><code class="language-php">WP_Post Object
(
    [ID]
    [post_author]
    [post_date] 
    [post_date_gmt] 
    [post_content] 
    [post_title] 
    [post_excerpt] 
    [post_status]
    [comment_status]
    [ping_status] 
    [post_password]
    [post_name]
    [to_ping]
    [pinged] 
    [post_modified]
    [post_modified_gmt]
    [post_content_filtered] 
    [post_parent] 
    [guid] 
    [menu_order]
    [post_type]
    [post_mime_type] 
    [comment_count]
    [filter]
)</code></pre>



<h2 class="wp-block-heading">Query WordPress posts using <code>get_posts</code> function examples</h2>



<p>I will continue this tutorial with a few promised examples of using <code>get_posts</code>. you can use these codes in your theme or your <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">WordPress plugin development</a>.</p>



<h3 class="wp-block-heading">Query posts by Category ID</h3>



<p><code>category</code> argument can help you retrieve posts with category ID.</p>



<p> As I told you before, You can pass series of comma-separated IDs for multiple categories.</p>



<pre><code class="language-php">//set category id to 1
$categoryId = 1;

//set arguments for the category
$args = array(
	"category"=&gt;$categoryId,
);

//query posts
$posts = get_posts($args);

//print post titles
foreach ($posts as $post){
	echo "Title: ".$post-&gt;post_title." &lt;br /&gt;";
}</code></pre>



<h3 class="wp-block-heading">Query Posts by Category Slug</h3>



<p>The best way to get posts by category slug in WordPress is to first get the ID of the category, then use <code>category</code> argument for that ID.</p>



<p>We use <code>get_category_by_slug</code> function in WordPress to get the category object.</p>



<p>Working Example for a category named &#8220;uncategorized&#8221;:</p>



<pre><code class="language-php">$categorySlug = "uncategorized";

//get the category from wordpress
$category = get_category_by_slug($categorySlug);

//check if the category exists
if($category){

	//set category id to term_id (category is a term)
	$categoryId = $category-&gt;term_id;

	//set the arguments for the categoryId
	$args = array(
		"category"=&gt;$categoryId,
	);

	//query posts
	$posts = get_posts($args);

	//printing post titles
	foreach ($posts as $post){
		echo "Title: ".$post-&gt;post_title." &lt;br /&gt;";
	}
}</code></pre>



<h3 class="wp-block-heading">Query Posts by Tag Slug</h3>



<p>tax_query argument will help us retrieve posts using tag slug.</p>



<p><code>taxonomy</code> key of <code>tax_query</code> array item must be set to <code>post_tag</code>, the <code>field</code> must be set to <code>slug</code> and <code>terms</code> is what we looking for (value, the tag slug).</p>



<pre><code class="language-php">//set tag slug
$tagSlug = "test";

//set the arguments for the tag
$args = array(
	'tax_query'      =&gt; array(
		array(
			'taxonomy'  =&gt; 'post_tag',
			'field'     =&gt; 'slug',
			'terms'     =&gt; sanitize_title( $tagSlug )
		)
	)
);

//query posts
$posts = get_posts($args);

//printing post titles
foreach ($posts as $post){
	echo "Title: ".$post-&gt;post_title." &lt;br /&gt;";
}</code></pre>



<h3 class="wp-block-heading">Query Posts by Custom Attribute</h3>



<p>We have two options to do this:</p>



<p>The first one is to use <code>meta_key</code> and <code>meta_value</code> arguments of <code>get_posts</code>.</p>



<p>This code retrieves all posts with a custom field named &#8220;featured&#8221; set to &#8220;yes&#8221;:</p>



<pre><code class="language-php">//set the arguments for the custom field named "featured" with value "yes"
$args = array(
	'meta_key' =&gt; 'featured',
	'meta_value' =&gt; 'yes',
	'meta_compare' =&gt; '=',//optional!
);

//query posts
$posts = get_posts($args);

//printing post titles
foreach ($posts as $post){
	echo "Title: ".$post-&gt;post_title." &lt;br /&gt;";
}</code></pre>



<p>The second one is to use <code>meta_query</code> argument which can help us use multiple custom attributes.</p>



<p>For example, the below code will retrieve posts with two custom attributes (featured &amp; top) set to yes value:</p>



<pre><code class="language-php">//for featured and top custom fields set to yes
$args = array(
	'meta_query' =&gt; array(
		array(
			'key' =&gt; 'featured',
			'value'   =&gt; 'yes',
			'compare' =&gt; '='//optional!
		),
		array(
			'key' =&gt; 'top',
			'value'   =&gt; 'yes',
			'compare' =&gt; '='//optional!
		),
	)
);

//query posts
$posts = get_posts($args);

//printing post titles
foreach ($posts as $post){
	echo "Title: ".$post-&gt;post_title." &lt;br /&gt;";
}</code></pre>



<h3 class="wp-block-heading">Query posts by Publish Date</h3>



<p>WordPress publish date for posts can be set automatically or manually through the WordPress admin panel when you are editing the post. (You can also <a href="https://mehdinazari.com/new-post-after-a-while/">set publish date for WordPress posts programmatically</a>)</p>



<p>WordPress lets developers use <code>query_dates</code> argument to retrieve posts with a date specification.</p>



<p>We will retrieve posts older or newer than a specified date:</p>



<h4 class="wp-block-heading">Post older than the Date</h4>



<p>The working code for retrieving posts before &#8220;30-07-2021&#8221;:</p>



<pre><code class="language-php">//set arguments for dates before 30-07-2021
$args = array(
	'date_query' =&gt; array(
		array(
			'before' =&gt; '30-07-2021'
        )
    )
);

//query posts
$posts = get_posts($args);

//printing post titles
foreach ($posts as $post){
	echo "Title: ".$post-&gt;post_title." &lt;br /&gt;";
}</code></pre>



<h4 class="wp-block-heading">Posts newer than the Date</h4>



<p> The working  code for retrieving posts after &#8220;30-07-2021&#8221;:</p>



<pre><code class="language-php">//set arguments for dates before 30-07-2021
$args = array(
	'date_query' =&gt; array(
		array(
			'after' =&gt; '30-07-2021'
        )
    )
);

//query posts
$posts = get_posts($args);

//printing post titles
foreach ($posts as $post){
	echo "Title: ".$post-&gt;post_title." &lt;br /&gt;";
}</code></pre>



<h3 class="wp-block-heading">Query posts by Post Type</h3>



<p><code>post_type</code> argument can help us retrieve posts of a specific type, like pages:</p>



<pre><code class="language-php">//set the post type
$postType = "page";

//set arguments for post type
$args = array(
	'post_type' =&gt; $postType
);

//query posts
$posts = get_posts($args);

//printing post titles
foreach ($posts as $post){
	echo "Title: ".$post-&gt;post_title." &lt;br /&gt;";
}</code></pre>



<h3 class="wp-block-heading">Query posts with a word inside</h3>



<p>We use <code>s</code> agument to search for a world inside posts.</p>



<p>The working code to search &#8220;test&#8221; word inside posts is this:</p>



<pre><code class="language-php">//set the word to search
$search = "test";

//set arguments for search
$args = array(
	's' =&gt; $search
);

//query posts
$posts = get_posts($args);

//printing post titles
foreach ($posts as $post){
	echo "Title: ".$post-&gt;post_title." &lt;br /&gt;";
}</code></pre>



<h3 class="wp-block-heading">Query random posts</h3>



<p>We have to set the <code>orderby</code> argument to <code>rand</code>, if we want to retrieve posts in random order:</p>



<pre><code class="language-php">//set order for random posts
$args = array(
	'orderby' =&gt; 'rand'
);

//query posts
$posts = get_posts($args);

//printing post titles
foreach ($posts as $post){
	echo "Title: ".$post-&gt;post_title." &lt;br /&gt;";
}</code></pre>



<h2 class="wp-block-heading">Where can I find more information about query posts in WordPress?</h2>



<p>The first place to find information about anything is the <a href="https://developer.wordpress.org">WordPress official website</a>. Specific pages you may want to explore are the <a href="https://developer.wordpress.org/reference/functions/get_posts/">get_posts function page</a>, and the <a href="https://developer.wordpress.org/reference/classes/wp_post/">WP_Post class page</a>.</p>



<p>If you faced any problem using <a href="https://developer.wordpress.org/reference/functions/" target="_blank" rel="noreferrer noopener">WordPress functions</a>, you can <a href="https://wordpress.stackexchange.com/questions/ask" target="_blank" rel="noreferrer noopener">ask your questions on WordPress StackExchange</a>.</p>



<p>If you want to continue learning WordPress, I recommend you read my tutorial:</p>



<p><a href="https://mehdinazari.com/wordpress-action-filter-hooks-tutorial/">WordPress Action and Filter Hooks Tutorial (+10 Examples)</a></p><p>The post <a href="https://mehdinazari.com/wordpress-query-posts/">How to Query Posts by Category, Tag, Custom Attribute, ETC</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/wordpress-query-posts/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WordPress Action and Filter Hooks Tutorial (+10 Examples)</title>
		<link>https://mehdinazari.com/wordpress-action-filter-hooks-tutorial/</link>
					<comments>https://mehdinazari.com/wordpress-action-filter-hooks-tutorial/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Fri, 09 Jul 2021 11:19:43 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<category><![CDATA[WordPress Tips]]></category>
		<category><![CDATA[WordPress Actions]]></category>
		<category><![CDATA[WordPress Filters]]></category>
		<category><![CDATA[WordPress Hooks]]></category>
		<category><![CDATA[WordPress plugin development for beginners]]></category>
		<category><![CDATA[WordPress tutorials for beginners]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=173</guid>

					<description><![CDATA[<p>In this WordPress tutorial for beginner developers, I will explain WordPress Actions and WordPress Filters and how you can use these WordPress Hooks in your theme or plugin, easy and understandable. This tutorial also contains +10 helpful examples for those who want to see this WordPress tutorial in action. First, I guess it&#8217;s better to [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/wordpress-action-filter-hooks-tutorial/">WordPress Action and Filter Hooks Tutorial (+10 Examples)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>In this WordPress tutorial for beginner developers, I will explain WordPress Actions and WordPress Filters and how you can use these WordPress Hooks in your theme or plugin, easy and understandable. This tutorial also contains +10 helpful examples for those who want to see this WordPress tutorial in action.</p>



<span id="more-173"></span>



<p>First,  I guess it&#8217;s better to explain what is a WordPress Hook (Actions or Filters) and why WordPress Hooks are essential to developers.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>WordPress let developers hang their custom functions to its core functions throughout WordPress Hooks. WordPress Hooks are two parts: WordPress Actions and WordPress Filters.</p>
</blockquote>



<h2 class="wp-block-heading">What are WordPress Hooks?</h2>



<p>WordPress developers can modify WordPress functionalities and returning content by using Hooks.</p>



<p>Hooks can hang a custom function to a WordPress core function.</p>



<p>The developer can set function execution order (A critical parameter when you want to hook multiple functions).</p>



<p>Hooks are often easy to use. to understand them better, we categorize them into two parts: Actions and Filters.</p>



<p>Use&nbsp;<strong>WordPress Actions</strong>&nbsp;when you want to&nbsp;<strong>run a function</strong>&nbsp;at the exact moment when a core function is executing.</p>



<p>Use&nbsp;<strong>WordPress Filters</strong>&nbsp;when you want to&nbsp;<strong>modify WordPress returning content</strong>&nbsp;at the exact moment when core content is returning.</p>



<h3 class="wp-block-heading">Why are WordPress Hooks necessary for developers? (sometimes non-developers too!)</h3>



<p>Two years ago, <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">In an article</a>, I told developers:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Actions and Filters are the primary way to connect with WordPress.</p>
</blockquote>



<p>If any developer wants to use WordPress at its total capacity, they better learn how to work with WordPress Hooks.</p>



<p>WordPress is a complete system for blogging, but when you want to add custom functionalities, especially when there is no plugin for it, you may need to modify WordPress core functions and control its behaviour.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Developers can use WordPress Hooks to control WordPress behaviour when this system is processing a web page.</p>
</blockquote>



<h3 class="wp-block-heading">What is the difference between WordPress Actions and Filters?</h3>



<p>The difference between WordPress Actions and Filters is that the&nbsp;<strong>actions are concerned with Events, and filters are concerned with Contents</strong>.</p>



<p>When I said&nbsp;<strong>Events</strong>, I meant occurrences like user log in, saving a post, predefined actions (custom actions defined by you), etc.</p>



<p>When I said&nbsp;<strong>Content</strong>, I meant the Data printed (or used in another way that is not printable) by WordPress on a webpage (or maybe just on the server). For example, title, short description and the full content of a post.</p>



<h2 class="wp-block-heading">WordPress Action Hooks</h2>



<h3 class="wp-block-heading">What are Action Hooks in WordPress?</h3>



<p>Action Hooks will attach a function to a WordPress core function which is executing when an Event occurs while WordPress is processing a web page.</p>



<p>For example, when you want to execute a function on the server when the user just logged in, you can use <code>wp_login</code> action (keep reading for the code).</p>



<h3 class="wp-block-heading">How to work with Action Hooks in WordPress?</h3>



<p>If you read this tutorial carefully, I said WordPress Hooks attaches a custom function to a core function. So you need a way to tell WordPress that &#8220;<strong>I have a function</strong>&#8221; and &#8220;<strong>I want to run this function after a core function that I know&#8221;.</strong></p>



<h4 class="wp-block-heading">1- Declare the custom function</h4>



<p> <s>-&gt;</s>  Copy this code to your current WordPress theme function.php file. <strong>Or</strong> you can create a simple plugin to run codes on WordPress using this tutorial: <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">How to create a Hello World plugin for WordPress in 3 Steps</a></p>



<pre><code class="language-php">if(!function_exists('make_user_login_awesome')){
      function make_user_login_awesome(){
            echo "You just logged in, what can we do now?";
            die();
      }
}</code></pre>



<h4 class="wp-block-heading">2- Tell WordPress which core function you want to run this function after</h4>



<p>When you want to tell WordPress that you need to run a function after another, you can use:</p>



<pre><code class="language-php">add_action("core function", "custom function", priority, number_of_acceptable_arguments)</code></pre>



<p>In the previous step, you just created a <strong>NOT attached</strong> function.</p>



<p>Let&#8217;s attach it to the <code>wp_login</code>, which is a core function that executes when a user just logged in.</p>



<p>This will be the <strong>Whole Code after attaching</strong> the function:</p>



<pre><code class="language-php">if(!function_exists('make_user_login_awesome')){
      function make_user_login_awesome(){
            echo "You just logged in, what can we do now?";
            die();
      }
      add_action('wp_login', 'make_user_login_awesome', 20, 0);//this line is just added to attach function
}</code></pre>



<h4 class="wp-block-heading">The above codes explain</h4>



<p>In the first line, you can see we checked if any function named <code>make_user_login_awesome</code> exists or not.</p>



<p>If it does not exist, we declare the function.</p>



<p>In the  <code>make_user_login_awesome</code> function, we told the server to <code>die()</code>, because we want to see this text printed after login: &#8220;You just logged in, what can we do now?&#8221;</p>



<p>Now we attach this function to the <code>wp_login</code> action. using this code:</p>



<pre><code class="language-php">add_action('wp_login', 'make_user_login_awesome', 20, 0);</code></pre>



<p>You can see <code>add_action</code> function accepts three arguments (actually it&#8217;s four).</p>



<p>In this particular order:</p>



<ol class="wp-block-list">
<li>Name of the WordPress core action that we want to attach a function to.</li>



<li>Name of our function that we want it to attach.</li>



<li>The priority of execution</li>
</ol>



<p>we passed <code>wp_login</code>, <code>make_user_login_awesome</code>, and <code>20</code> as parameters to <code>add_action</code> function.</p>



<p>When you insert the full code to your <code>function.php</code> or the custom plugin you created for this practice, you can log in to WordPress (admin panel or frontend) then you will see the result.</p>



<h3 class="wp-block-heading">How to define a custom Action, execute it and attach a custom function to it</h3>



<p>WordPress made this functionality available for developers to predefine actions and fire them at the right moment of page processing.</p>



<p>This means that <strong>you can create custom Actions for yourself and attach custom functions to them</strong>.</p>



<p>Let&#8217;s see how you can do that&#8230;</p>



<p><strong>Creating a new Action in WordPress is just like attaching a function</strong>. We use <code>add_action</code> function.</p>



<p> Use this function to create a new Action Hook in WordPress:</p>



<pre><code class="language-php">add_action("custom_action_name", "custom_function_name", priority, number_of_acceptable_arguments);</code></pre>



<p><code>custom_action_name</code> will be the name of your custom Action.</p>



<p><code>custom_function_name</code> is the name of the function we define (we will, keep reading&#8230;)</p>



<p><code>priority</code> will be the order of execution of our Action  (Integer).</p>



<p><code>number_of_acceptable_arguments</code> is the number of arguments that our custom function accepts (Integer).</p>



<h4 class="wp-block-heading">Copiable example to try</h4>



<p>Just copy this in your function.php or custom module you created:</p>



<pre><code class="language-php">if(!function_exists('make_user_login_awesome')){
      function custom_function_name($arg1, $arg2){
      	  die("Custom Action is Here! ".$arg1." ".$arg2);
      }
      add_action('custom_action_name', 'custom_function_name', 10, 2);

      do_action('custom_action_name', 'value1', 'value2');
}</code></pre>



<p>If you open WordPress, you will see the message:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Custom Action is Here! value1 value2</p>
</blockquote>



<p>This means that our code is working.</p>



<p>You can comment out the last line (do_action(&#8230;.)) to disable this action.</p>



<h4 class="wp-block-heading">Attaching a custom function to a custom Action Hook</h4>



<p>In the last example, we defined a custom Action Hook and executed it.</p>



<p>Now is the time for a little more complicated example.</p>



<p>Do you remember how to attach a custom function to a core Hook? We will do the same thing for this custom made Action.</p>



<p>Use this code as the example:</p>



<pre><code class="language-php">function custom_function_name($arg1, $arg2){
	die("Custom Action is Here! ".$arg1." ".$arg2);
}
add_action('custom_action_name', 'custom_function_name',10,2 );

function custom_attached_function($arg1, $arg2){
	echo "I just want to say hi... and... \n";
}
add_action('custom_action_name', 'custom_attached_function', 9, 2);//9 is important number here!

do_action('custom_action_name', 'value1', 'value2');</code></pre>



<p>This will display this text after opening the WordPress:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>I just want to say hi&#8230; and&#8230;  Custom Action is Here! value1 value2 </p>
</blockquote>



<p>You can play with this code. <strong>Try changing orders of execution, name of the functions, acceptable arguments</strong>, etc.</p>



<h3 class="wp-block-heading">How to remove an Action Hook</h3>



<p>WordPress made this available for developers to remove Action Hooks just like adding them.</p>



<p>Developers can use <code>remove_action</code> function to remove an Action Hook, easy and fast.</p>



<p>This means that you can unhook a function from a Action Hook.</p>



<p>now we can unhook it with this syntax:</p>



<pre><code class="language-php">remove_action('action_name', 'function_name_to_remove');</code></pre>



<p>In an example, we added a welcome page for users after login, we called the function <code>make_user_login_awesome</code>.</p>



<p>Full code to unhook <code>make_user_login_awesome</code> from <code>wp_login</code> Action Hook:</p>



<pre><code class="language-php">if(!function_exists('make_user_login_awesome')){
      function make_user_login_awesome(){
            echo "You just logged in, what can we do now?";
            die();
      }
      add_action('wp_login', 'make_user_login_awesome', 20, 0);//this line is just added to attach function

      remove_action('wp_login', 'make_user_login_awesome');//this line is doing the trick!
}</code></pre>



<h3 class="wp-block-heading">4 examples of WordPress Action Hooks</h3>



<h4 class="wp-block-heading">1- Disable WordPress for gusts and show a custom message (like maintenance messages)</h4>



<p>This is an easy one, there is a WordPress Action Hook named <code>init</code> that will be executed when WordPress is loaded (NOT completely) but nothing is printed yet.</p>



<p>In the <code>init</code> stage, the user is authenticated.</p>



<p>Use this example to disable WordPress completely but not for logged in users:</p>



<pre><code class="language-php">if(!function_exists('my_maintenance_message')){
	function my_maintenance_message(){
		if(!get_current_user_id() &amp;&amp; $GLOBALS['pagenow'] !== 'wp-login.php')
			die("This website is under construction!");
	}

	add_action('init','my_maintenance_message',10);
}</code></pre>



<p>After inserting this code, WordPress will show maintenance messages to those who are not logged in.</p>



<p>If you see nothing changed, log out from the admin panel.</p>



<p>We excluded the login page from this message, so you can log in again.</p>



<h4 class="wp-block-heading">2- Redirect users to a specific post after login </h4>



<p>You can redirect users after login into any post you want. you have to know the post id or slug.</p>



<p>We&#8217;ll use <code>wp_login</code> action for this matter.</p>



<p>Use this code:</p>



<pre><code class="language-php">if(!function_exists('redirect_me_after_login')){
	function redirect_me_after_login(){
		$postId = 1;
		wp_redirect(get_permalink($postId));
		exit();
	}

	add_action('wp_login','redirect_me_after_login',10);
}</code></pre>



<p>After running this example, you can see after login, the user will redirect to a post with id 1.</p>



<p>You can change the id by changing the value of the parameter <code>$postId</code>.</p>



<h4 class="wp-block-heading">3- Display a welcome message, then redirect the user to a specific post after login</h4>



<p>For this one, we have to use some JavaScript code.</p>



<p>First, we have to print the welcome message, after x seconds we must redirect the user to a specific post.</p>



<p>JavaScript will handle the redirect part, WordPress will do the rest.</p>



<p>Use this code to show maintenance message then redirect the user to post with id 1.</p>



<pre><code class="language-php">if(!function_exists('redirect_me_after_login')){
	function redirect_me_after_login(){
		$postId = 1;
		$timerInMilliSeconds = 5000;//5 seconds!
		$html = "&lt;p&gt;Welcome to our website!&lt;/p&gt;";
		$html .= "&lt;script&gt;setTimeout(function(){window.location.href='".get_permalink($postId)."'},".$timerInMilliSeconds.")&lt;/script&gt;";
		echo $html;
		exit();
	}

	add_action('wp_login','redirect_me_after_login',10);
}</code></pre>



<p>You can set the timer with <code>$timerInMilliSeconds</code> variable.</p>



<h4 class="wp-block-heading">4- Add an Admin Notice to the WordPress admin panel</h4>



<p>Admin notices in WordPress are the messages you can see in your WordPress admin panel.</p>



<p>Some messages are success messages, some are warnings.</p>



<p>Sometimes admin notices are dismissable, sometimes they are not.</p>



<p>In this example, I show you how you can display a WordPress dismissable warning message for admins.</p>



<pre><code class="language-php">if(!function_exists('my_admin_notice_message')){
	function my_admin_notice_message() {
		?&gt;
		&lt;div class="notice notice-warning is-dismissible"&gt;
			&lt;p&gt;This is just an example!&lt;/p&gt;
		&lt;/div&gt;
		&lt;?php
	}
	add_action( 'admin_notices', 'my_admin_notice_message' );
}</code></pre>



<p>You can control the message&#8217;s UI by changing classes in the HTML code.</p>



<p>For example, if you want to display a success message, you can replace <code>notice-warning</code> with <code>notice-success</code>.</p>



<p><code>is-dismissible</code> class makes this Admin Notice a dismissible message.</p>



<p>You must see the result on all admin pages.</p>



<p>Something like this on top of the page:</p>


<div class="wp-block-image">
<figure class="aligncenter"><img loading="lazy" decoding="async" width="1024" height="53" src="https://mehdinazari.com/wp-content/uploads/2021/07/admin-notice-1024x53.jpg" alt="Admin Notice Example" class="wp-image-244" srcset="https://mehdinazari.com/wp-content/uploads/2021/07/admin-notice-1024x53.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2021/07/admin-notice-300x16.jpg 300w, https://mehdinazari.com/wp-content/uploads/2021/07/admin-notice-768x40.jpg 768w, https://mehdinazari.com/wp-content/uploads/2021/07/admin-notice-800x41.jpg 800w, https://mehdinazari.com/wp-content/uploads/2021/07/admin-notice.jpg 1080w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Admin Notice Example</figcaption></figure>
</div>


<h2 class="wp-block-heading">WordPress Filter Hooks</h2>



<h3 class="wp-block-heading">What are Filter Hooks in WordPress?</h3>



<p>Filter Hooks in WordPress let developers <strong>modify the Data</strong> processed by this CMS.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Developers can use Filter Hooks to modify WordPress Data at runtime.</p>
</blockquote>



<p>They can change the value returned by the core WordPress to generate new value.</p>



<p>Developers must attach a function to a Filter Hook and modify the values returned by the hook, then return the new values for the next process.</p>



<p>For example when you want to use <code>the_title</code> Filter Hook, which is responsible for generating post title, you must get the title in a parameter, modify it, then return it using PHP <code>return</code>.</p>



<p>Something like this will prepend a text in all post titles:</p>



<pre><code class="language-php">if(!function_exists('prepend_word_for_titles')){
	function prepend_word_for_titles( $title, $id = null ) {
		return "Article: ".$title;
	}
	add_filter( 'the_title', 'prepend_word_for_titles', 10, 2 );
}</code></pre>



<h3 class="wp-block-heading">How to work with Filter Hooks in WordPress?</h3>



<h4 class="wp-block-heading">1- Declare the custom function, receive the value, modify, then return it</h4>



<p>To modify Data in WordPress, you must create a custom function to get data, modify and then return it.</p>



<p>Let&#8217;s do it with an example.</p>



<p>I want to write a function to receive comment text, modify it, then return it.</p>



<p>This will be the function in our <code>functions.php</code> or plugin:</p>



<pre><code class="language-php">function prepend_word_for_comments( $commentText) {
		return "Commented: ".$commentText;
}</code></pre>



<p>Note: this function will do nothing until we attach it to <code>comment_text</code> Filter Hook.</p>



<h4 class="wp-block-heading">2- Attach the custom function to a Filter Hook</h4>



<p>Now it&#8217;s time to attach this custom function we wrote to comment_text Filter Hook.</p>



<p>It&#8217;s really easy to do that. We use <code>add_filter</code> function for this matter.</p>



<p><code>add_filter</code> syntax is like this:</p>



<pre><code class="language-php">add_filter('filter_hook_name','custom_function_name',priority)</code></pre>



<p>Now we apply this syntax for our custom function:. you can copy/paste this code to see the result in the comments list:</p>



<pre><code class="language-php">if(!function_exists('prepend_word_for_comments')){
	function prepend_word_for_comments($commentText) {
		return "Commented: ".$commentText;
	}
	add_filter( 'comment_text', 'prepend_word_for_comments', 10 );
}</code></pre>



<h3 class="wp-block-heading">How to define a custom Filter Hook in WordPress</h3>



<p>like Action Hooks, WordPress developers can create custom Filter Hooks.</p>



<p>You can create your own text filter for any text. you have to just apply your filter for those texts using <code>apply_filter</code> function.</p>



<p>Important: if you use <code>add_filter</code> function with a unique filter name (which is not used by WordPress yet), the function will be added as a filter hook in WordPress.</p>



<p>For example, I want to define a function named <code>prepend_word_for_any_text</code> and add it as a filter hook.</p>



<p>This function will receive any text, prepend another text to it, then return it again.</p>



<p>To define this function as a filter, we use this code in your <code>functions.php</code> or plugin:</p>



<pre><code class="language-php">if(!function_exists('prepend_word_for_any_text')){
	function prepend_word_for_any_text($text) {
		return "Prepended: ".$text;
	}
	add_filter( 'prepend_word_for_any_text', 'prepend_word_for_any_text' );//define filter
}</code></pre>



<p>Because <code>prepend_word_for_any_text</code> is not defined yet, our add_filter will be added as a filter hook in WordPress.</p>



<p>Now it&#8217;s time to use our custom filter hook.</p>



<p>To use this filter hook you just need to echo <code>apply_filter</code> anywhere you want:</p>



<pre><code class="language-php">echo apply_filters("prepend_word_for_any_text","The text");</code></pre>



<h3 class="wp-block-heading">How to remove Filter Hook</h3>



<p>Developers can remove Filters just like adding them. there is a <code>remove_filter</code> function available for this matter.</p>



<p><code>remove_filter</code> function syntax in WordPress:</p>



<pre><code class="language-php">remove_filter('filter_name', 'function_name_to_remove');</code></pre>



<p>In the previous example, we prepended a word to all comment texts. no to unhook this function from <code>comment_text</code> filter, you can use this code:</p>



<pre><code class="language-php">if(!function_exists('prepend_word_for_comments')){
	function prepend_word_for_comments($commentText) {
		return "Commented: ".$commentText;
	}
	add_filter( 'comment_text', 'prepend_word_for_comments', 10 );

	remove_filter( 'comment_text', 'prepend_word_for_comments');//this line is doing the trick
}</code></pre>



<h3 class="wp-block-heading">+4 examples of WordPress Filter Hooks </h3>



<p>Use these practices to learn more about WordPress Filter Hooks:</p>



<h4 class="wp-block-heading">1- Filter a specific word in post titles</h4>



<p>To filter (replace the word with something else) a word in all post titles, developers can use <code>post_title</code> Filter Hook in WordPress.</p>



<p><code>post_title</code> Filter Hook is responsible to generate the post title for all posts.</p>



<p>in this example, we use &#8216;test&#8217; word, you can change it to whatever you want.</p>



<p>Full code to filter a specific word:</p>



<pre><code class="language-php">if(!function_exists('filter_word_in_titles')){
	function filter_word_in_titles( $title, $id = null ) {
		$filterWord = "test";
		return str_replace($filterWord,"***",$title);
	}
	add_filter( 'the_title', 'filter_word_in_titles', 10, 2 );
}</code></pre>



<h4 class="wp-block-heading">2- Hide commenters names using WordPress Filter Hooks</h4>



<p>If you are interested in hiding commenters names in comments list, you can use this code:</p>



<pre><code class="language-php">if(!function_exists('hide_commenter_name')){
	function hide_commenter_name($author, $comment_ID ) {
		return "";
	}
	add_filter( 'comment_author', 'hide_commenter_name', 10, 2 );
}</code></pre>



<h4 class="wp-block-heading">3- Change all author names to something specific</h4>



<p>This one is easy, just like previous example. you can just do it with a few changes:</p>



<pre><code class="language-php">if(!function_exists('hide_commenter_name')){
	function hide_commenter_name($author, $comment_ID ) {
		$word = "A great person";
		return $word;
	}
	add_filter( 'comment_author', 'hide_commenter_name', 10, 2 );
}</code></pre>



<h4 class="wp-block-heading">4- Wrap post titles in h1 tag using Filter Hooks</h4>



<p>To do this, you better check if you already added a tag around titles in your theme.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Note: this is just for test, do not execute this codes on a live website.</p>
</blockquote>



<p>Use this code to add H1 tags around post titles:</p>



<pre><code class="language-php">if(!function_exists('add_h1_tag_to_titles')){
	function add_h1_tag_to_titles( $title, $id = null ) {
		return '&lt;h1&gt;'.$title.'&lt;/h1&gt;';
	}
	add_filter( 'the_title', 'add_h1_tag_to_titles', 10, 2 );
}</code></pre>



<h2 class="wp-block-heading">+10 Tips for beginner developers when they want to use WordPress Actions and Filters</h2>



<h3 class="wp-block-heading">1- Always remember the Action and Filter Hooks are the primary ways to connect with WordPress</h3>



<p>When you are developing WordPress, there are a few places where you can apply your modifications.</p>



<p>For example, you can edit texts in the places where they are printed, and avoid using Filter Hooks, but think about it for a second&#8230;</p>



<p>If you use Filter Hooks to modify Data, you will benefit from advantages.</p>



<h4 class="wp-block-heading">WordPress Hooks advantages</h4>



<ul class="wp-block-list">
<li>Write once, it will happen everywhere</li>



<li>Easy to manage with the order of execution</li>



<li>Readability</li>



<li>It looks professional</li>
</ul>



<h3 class="wp-block-heading">2- Read about Actions and Filters on WordPress official website</h3>



<p>WordPress official website is a great source for information.</p>



<p>I know it can sometimes be challenging to understand guidance on official websites (any product really!), but you always can find great help in them.</p>



<p>WordPress official website contains thousands of helpful pages that can help developers to find the correct way of developing this CMS.</p>



<p>Use this page to get started with WordPress:</p>



<p><a href="https://codex.wordpress.org/Getting_Started_with_WordPress" target="_blank" rel="noreferrer noopener" aria-label="Getting Started with WordPress on the official website (opens in a new tab)">Getting Started with WordPress on the official website</a></p>



<h3 class="wp-block-heading">3- There is a list of hooks on the WordPress official website</h3>



<p>For developers, there is a page on WordPress official website that can be the leading page to understanding WordPress Hooks more.</p>



<p>You can visit this page to get more information:</p>



<p><a href="https://developer.wordpress.org/reference/hooks" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">WordPress Hooks on the official website</a></p>



<h3 class="wp-block-heading">4- Make a list of interesting WordPress Hooks</h3>



<p>There are some WordPress Hooks that you use a lot in your developing time. You better notice these hooks and list them in a notepad (notebook?).</p>



<p>Save interesting hooks in a list and save the working example code with it, in future, you will just copy/past codes to achieve your goals.</p>



<h3 class="wp-block-heading">5- Make sure you understood the difference between Actions and Filters</h3>



<p>If you are not sure you understand the difference between Actions and Filters, you better start this tutorial once again.</p>



<p>For those who need a reminder:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>actions are concerned with Events, and filters are concerned with Contents</p>
</blockquote>



<p>If you want to fire a function after an Event, you must use Action Hooks.</p>



<p>If you want to edit Content (Data), you must use Filter Hooks.</p>



<h3 class="wp-block-heading">6- You can do anything with WordPress Hooks, DO NOT feel restricted</h3>



<p>WordPress Hooks are easy to use, but they can do a lot!</p>



<p>Developers can use filters to modify WordPress to the core!</p>



<p>They can even modify SQL queries used by WordPress to retrieve or save Data.</p>



<p>You should never feel restricted when you are using WordPress Action and Filters because WordPress creators thought about almost everything you need to modify this CMS.</p>



<h3 class="wp-block-heading">7- Keep practising with creative ideas</h3>



<p>I like those developers who want to learn how stuff works with working examples. Those who want to execute codes and see the result.</p>



<p>If you are a beginner developer, the best way to hack it is to practice it.</p>



<p>In this tutorial, I&#8217;ve tried to teach what I learned over the years with working examples, but there are more examples in real projects.</p>



<p>I recommend you to think about some ideas that you can apply them using WordPress Hooks, practice them, try to memorize important ones.</p>



<h3 class="wp-block-heading">8- Ask your questions on Stackoverflow</h3>



<p>Stackoverflow is the best place to ask questions about technical stuff. This website is also a great source of information for developers.</p>



<p>First, search your question in Stackoverflow to check if this issue already been posted or not, then if not, ask it with all information you can give to helpers.</p>



<p>Tell helpers what you&#8217;ve tried and what was the result. Good questions will get answers quickly.</p>



<p>Stackoverflow has a special community for WordPress developers, use this link to navigate to this great community:</p>



<p><a href="https://wordpress.stackexchange.com/" target="_blank" rel="noreferrer noopener" aria-label="WordPress Development Stack Exchange (opens in a new tab)">WordPress Development Stack Exchange</a></p>



<h3 class="wp-block-heading">9- Never try to edit WordPress core function directly from files</h3>



<p>WordPress core files must always stay untouched.</p>



<p>If you try to modify WordPress core files, you will lose all of your work in the next WordPress update.</p>



<p>It does not matter what you want to do, WordPress made a way for you to achieve that without needing to edit core files.</p>



<p>I advise against editing WordPress core files, even if you think you know what you want to do.</p>



<p>Always remember WordPress Hooks are the means for you to modify WordPress functionality without breaking things or losing codes in the next update.</p>



<h3 class="wp-block-heading">10- Stay updated and track version changelogs</h3>



<p>Even if you are a <a href="https://mehdinazari.com">professional WordPress developer</a>, you must always stay updated.</p>



<p>WordPress is constantly changing, you can track these changes on the WordPress official website.</p>



<p>Read version changelogs carefully, sometimes your codes will be deprecated due to version updates.</p><p>The post <a href="https://mehdinazari.com/wordpress-action-filter-hooks-tutorial/">WordPress Action and Filter Hooks Tutorial (+10 Examples)</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/wordpress-action-filter-hooks-tutorial/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Create a Hello World Plugin for WordPress [2023]</title>
		<link>https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/</link>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Sun, 28 Jul 2019 13:55:12 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress plugin development for beginners]]></category>
		<category><![CDATA[WordPress tutorials for beginners]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=11</guid>

					<description><![CDATA[<p>This WordPress plugin development tutorial teaches how to create a plugin for WordPress with a simple example of building a hello world plugin in WordPress. In this short tutorial, I will show you how to create a custom WordPress plugin and print the &#8220;Hello world&#8221; text inside its admin page. This article also contains ten [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">How to Create a Hello World Plugin for WordPress [2023]</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>This WordPress plugin development tutorial teaches how to create a plugin for WordPress with a simple example of building a hello world plugin in WordPress.</p>



<span id="more-11"></span>



<p>In this short tutorial, I will show you how to create a custom WordPress plugin and print the &#8220;Hello world&#8221; text inside its admin page. This article also contains ten helpful tips for beginner WordPress developers.</p>



<p>If&nbsp;you do not know this already, <strong>WordPress plugins are stored inside the <code>wp-content/plugins</code> folder</strong>, which can be accessed from your WordPress root directory.</p>



<p>In 2023 there will be around 60,500 plugins available to download from <a href="https://wordpress.org/plugins/" target="_blank" rel="noopener" title="">WordPress&#8217;s official plugins directory</a>.</p>



<p>In this simple tutorial, we want to create a simple WordPress plug-in and put it inside the plugins folder, then activate it from the WordPress admin panel (wp-admin).</p>



<p>Creating a simple &#8220;Hello World&#8221; plugin in WordPress can be done in 3 easy steps:</p>



<ol class="wp-block-list">
<li><strong>creating the plugin&#8217;s main file</strong></li>



<li><strong>writing plugin headers</strong> in the created file (headers: information about the plugin and the author)</li>



<li><strong>writing functions to display &#8220;Hello World&#8221;</strong> text inside an admin page in the WordPress panel</li>
</ol>



<p>So here we go:</p>



<h2 class="wp-block-heading">1- Create your hello world plugin main file</h2>



<p>The plugin&#8217;s main file will contain all of our headers and functions that <strong>will be discovered by WordPress automatically</strong>. this file must be inside a folder with the same name in the <code>wp-content/plugins</code> directory.</p>



<p>in this tutorial, I&#8217;m going to call this plugin &#8220;Hello World&#8221;, so go ahead and:</p>



<p><s>-&gt;</s> create <strong>a &#8220;hello-world&#8221; folder inside the <code>wp-content/plugins</code></strong> directory of your WordPress installation (using FTP or file manager). </p>



<p><s>-&gt;</s> create a <strong>file named hello-world.php inside this hello-world folder</strong> that you just created.</p>



<h2 class="wp-block-heading">2- Write plugin headers for this hello world plugin</h2>



<p>headers are information about the module (plugin). <strong>without the headers, WordPress can NOT discover your plugin</strong>.</p>



<p><strong>Plugin Name is required in plugin headers</strong>, and other headers are optional.</p>



<p>This means that <strong>you can only set a name for a plugin and activate it</strong>, but you can also write complete information about this plugin to be displayed on the plugins page inside the admin panel of WordPress.</p>



<p>You can write your information as the author of the plugin inside headers for others to see if they&#8217;ve installed your plugin.</p>



<p>This is the full code of a proper header for the WordPress hello world plugin. You can edit this information based on yours.</p>



<p><s>-&gt;</s> these codes will go to the top of your <strong>hello-world.php</strong> file:</p>



<pre><code class="language-php">&lt;?php
/**
 * Hello World
 *
 * @package     HelloWorld
 * @author      Mehdi Nazari
 * @copyright   2019 Mehdi Nazari
 * @license     GPL-2.0-or-later
 *
 * @wordpress-plugin
 * Plugin Name: Hello World
 * Plugin URI:  https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress
 * Description: This plugin prints "Hello World" inside an admin page.
 * Version:     1.0.0
 * Author:      Mehdi Nazari
 * Author URI:  https://mehdinazari.com
 * Text Domain: hello-world
 * License:     GPL v2 or later
 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 */
</code></pre>



<p>Now you have a folder inside the plugin&#8217;s directory named &#8220;hello-world&#8221; inside that, you have a file named &#8220;<strong>hello-world.php</strong>&#8220;, and inside that file, you have the above code.</p>



<p>At this point, <strong>you can activate your plugin</strong>, and WordPress will be ok with it.</p>



<p>After login into the admin dashboard (wp-admin), you can navigate to the plugins page by clicking on its menu item.</p>



<p>Or replace your website name with this URL:<br /><code>http://sitename.com/wp-admin/plugins.php</code></p>



<p>Find the hello world plugin in the plugins list. You can <strong>activate the plugin by clicking on the &#8220;Activate&#8221; button under the plugin&#8217;s name</strong>:</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="85" src="https://mehdinazari.com/wp-content/uploads/2019/07/hello-world-wp-plugin-1024x85.jpg" alt="WordPress hello world plugin in plugins list" class="wp-image-65" srcset="https://mehdinazari.com/wp-content/uploads/2019/07/hello-world-wp-plugin.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2019/07/hello-world-wp-plugin-300x25.jpg 300w, https://mehdinazari.com/wp-content/uploads/2019/07/hello-world-wp-plugin-768x64.jpg 768w, https://mehdinazari.com/wp-content/uploads/2019/07/hello-world-wp-plugin-800x66.jpg 800w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">WordPress hello world plugin in the plugins list</figcaption></figure>



<p>to display the &#8220;Hello World&#8221; text, you must create an admin page and display this text inside it.</p>



<h2 class="wp-block-heading">3- Create an admin page for the hello world plugin</h2>



<p>if you <strong>create a menu page for the hello-world plugin, its menu item will be automatically created, and you can access it from the </strong>WordPress menu list.</p>



<p><s>-&gt;</s> to create an admin page and a menu item for the hello-world plugin, copy this code and paste it at the bottom of the <strong>&#8220;hello-world.php&#8221; file</strong>:</p>



<pre><code class="language-php">
function display_hello_world_page() {
  echo '<h1>Hello World!</h1>';
}
function hello_world_admin_menu() {
  add_menu_page(
        'Hello World',// page title
        'Hello World',// menu title
        'manage_options',// capability
        'hello-world',// menu slug
        'display_hello_world_page' // callback function
    );
}
add_action('admin_menu', 'hello_world_admin_menu');
</code></pre>



<p>now <strong>you can see the Hello World menu item inside the admin menu list if you just refresh the </strong>admin page (no reactivation is required). like this:</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="424" src="https://mehdinazari.com/wp-content/uploads/2019/07/hellow-world-menu-item-1024x424.jpg" alt="Hello World menu item in admin panel" class="wp-image-56" srcset="https://mehdinazari.com/wp-content/uploads/2019/07/hellow-world-menu-item.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2019/07/hellow-world-menu-item-300x124.jpg 300w, https://mehdinazari.com/wp-content/uploads/2019/07/hellow-world-menu-item-768x318.jpg 768w, https://mehdinazari.com/wp-content/uploads/2019/07/hellow-world-menu-item-800x331.jpg 800w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Hello World menu item in the admin panel</figcaption></figure>



<p>After clicking the &#8220;Hello World&#8221; menu item, you will navigate to its admin page, where you can see the &#8220;Hello World!&#8221; text that we printed using PHP&#8217;s echo command. like this:</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1024" height="424" src="https://mehdinazari.com/wp-content/uploads/2019/07/hello-world-admin-page-1024x424.jpg" alt="Hello World admin page in admin panel" class="wp-image-58" srcset="https://mehdinazari.com/wp-content/uploads/2019/07/hello-world-admin-page.jpg 1024w, https://mehdinazari.com/wp-content/uploads/2019/07/hello-world-admin-page-300x124.jpg 300w, https://mehdinazari.com/wp-content/uploads/2019/07/hello-world-admin-page-768x318.jpg 768w, https://mehdinazari.com/wp-content/uploads/2019/07/hello-world-admin-page-800x331.jpg 800w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Hello World admin page in the admin panel</figcaption></figure>



<h3 class="wp-block-heading">above codes explain:</h3>



<p>First, we declared a function named <code>display_hello_world_page()</code> to display the &#8220;Hello World!&#8221; text using the PHP&#8217;s echo command.</p>



<p>to make this function work as a page, we must register this function as the callback function of WordPress&#8217;s function <code>add_menu_page()</code>. which is a WordPress core function used to create admin pages and menu links.</p>



<p>to execute the function <code>add_menu_page()</code>, we must fire it using an action.</p>



<p>to create an action in WordPress, we use <code>add_action()</code> function.</p>



<p><code>add_action()</code> function will take two parameters; the first parameter declares when the action is firing, while the second parameter declares what function must be fired.</p>



<p><code>add_action('admin_menu', 'hello_world_admin_menu')</code> is saying to WordPress that we want to run <code>hello_world_admin_menu()</code> when <code>admin_menu</code> action is running by WordPress.</p>



<p>With this add_action, our add_menu_page function will run when WordPress is trying to create admin menus.</p>



<p><code>add_menu_page()</code> is a WordPress core function that takes 7 parameters and creates an admin menu page for you (easy, right?).</p>



<p>These 7 parameters are &#8220;page title&#8221;, &#8220;menu title&#8221;, &#8220;capability&#8221;, &#8220;menu slug&#8221;, &#8220;callback function&#8221;, &#8220;icon url&#8221; and &#8220;position in menu&#8221;.</p>



<p><strong>page title</strong>: this will be displayed on browser tabs.</p>



<p><strong>menu title</strong>: this will be displayed as a menu name inside the WordPress panel.</p>



<p><strong>capability</strong>: this one determines what kind of admin user can access this page.</p>



<p><strong>menu slug</strong>: with this parameter, you can set an address for your admin page.</p>



<p><strong>callback function</strong>: what function do you want to run when this page is called? we will print &#8220;Hello World!&#8221; in this function.</p>



<p><strong>icon URL</strong>: if you want to use another icon other than the gear, you can write its URL here.</p>



<p><strong>position in the menu</strong>: this is optional; if you want to position this item at a specific location in the WordPress menu, you can put the number here.</p>



<p>we did not use the last two parameters in our hello-world plugin and let it be the default.</p>



<p>you can <a aria-label="read more about add_menu_page function in WordPress official (opens in a new tab)" href="https://developer.wordpress.org/reference/functions/add_menu_page/" target="_blank" rel="noreferrer noopener">read more about the <code>add_menu_page</code> function in WordPress&#8217;s official</a> documents.</p>



<p>Also, <strong>these tutorials can help you</strong> develop a perfect WordPress plugin:</p>



<ul class="wp-block-list">
<li><a href="https://mehdinazari.com/activate_plugin-wordpress-function/" target="_blank" rel="noopener" title="">Learn how to activate a plugin automatically</a></li>



<li><a href="https://mehdinazari.com/get-plugin-directory-path-wordpress/" target="_blank" rel="noopener" title="">Learn how to get a plugins directory path</a></li>



<li><a href="https://mehdinazari.com/add_settings_section-wordpress-function/" target="_blank" rel="noopener" title="">Learn how to add a custom setting section</a></li>



<li><a href="https://mehdinazari.com/add-custom-shortcode-wordpress/" target="_blank" rel="noopener" title="">Learn how to add a custom shortcode</a></li>



<li><a href="https://mehdinazari.com/wordpress-query-posts/" target="_blank" rel="noopener" title="">Learn how to get posts</a></li>



<li><a href="https://mehdinazari.com/query-wordpress-categories-tags-taxonomies/" target="_blank" rel="noopener" title="">Learn how to get categories, tags (taxonomies)</a></li>



<li><a href="https://mehdinazari.com/join-custom-tables-with-wordpress-posts-query/" target="_blank" rel="noopener" title="">Learn how to extend WordPress posts query</a></li>
</ul>



<p>If you want to develop flawless WordPress plugins, read these ten tips:</p>



<h2 class="wp-block-heading">10 Things to remember when creating WordPress plugins as a beginner</h2>



<p>if you are creating a WordPress plugin for the first time, you better keep a few things in mind. Here is the list:</p>



<h3 class="wp-block-heading">1- You can include PHP files in your main plugin file</h3>



<p>Like any other PHP script, you can include other PHP files in the main file. so you can include other PHP files inside your plugin&#8217;s main file (in our case hello-world.php file)</p>



<p>You can categorize and put your functions in different files to keep your codes clean and simple. You have to include them in your main file.</p>



<p>for example, you can split our hello-world.php file into two files like this:</p>



<p><s>-&gt;</s> create a file named <strong>functions.php</strong> next to your hello-world.php file.</p>



<p>Add these codes to this new <strong>functions.php</strong> file:</p>



<pre><code class="language-php">&lt;?php
add_action('admin_menu', 'hello_world_admin_menu');
function hello_world_admin_menu() {
  add_menu_page(
        'Hello World',// page title
        'Hello World',// menu title
        'manage_options',// capability
        'hello-world',// menu slug
        'display_hello_world_page' // callback function
    );
}

function display_hello_world_page() {
  echo '<h1>Hello World!</h1>';
}</code></pre>



<p><s>-&gt;</s> change your <strong>hello-world.php</strong> file&#8217;s content to this:</p>



<pre><code class="language-php">&lt;?php
/**
 * Hello World
 *
 * @package     HelloWorld
 * @author      Mehdi Nazari
 * @copyright   2019 Mehdi Nazari
 * @license     GPL-2.0-or-later
 *
 * @wordpress-plugin
 * Plugin Name: Hello World
 * Plugin URI:  https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress
 * Description: This plugin prints "Hello World" inside an admin page.
 * Version:     1.0.0
 * Author:      Mehdi Nazari
 * Author URI:  https://mehdinazari.com
 * Text Domain: hello-world
 * License:     GPL v2 or later
 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 */
include_once("functions.php");
//or use include(),require(),require_once()
</code></pre>



<p><strong>everything must stay the same</strong> after this change. we just made our codes a little more clear.</p>



<h3 class="wp-block-heading">2- You can use the MVC approach in creating WordPress plugins</h3>



<p>Yes, you can create WordPress plugins using the MVC approach.</p>



<p>You have two ways to do this. First, <strong>you can create your folder structure and classes</strong>.</p>



<p>Or you can use the <a aria-label="WP-MVC plugin (opens in a new tab)" href="http://wpmvc.org/" target="_blank" rel="noreferrer noopener">WP-MVC plugin</a>, which provides MVC folder structure and default classes for you, and you can extend them to achieve what you want.</p>



<p>WP-MVC will take care of file includes if you use it right, and it has helpful functions too.</p>



<p>Someday i will create a full guide for plugin development using  WP-MVC.</p>



<h3 class="wp-block-heading">3- Actions and filters are the primary way to connect with WordPress</h3>



<p><strong>Action and filter hooks are the most important part of the WordPress API</strong>. if you want to be a WordPress developer, you better know how they work.</p>



<p><strong>An action hook will be triggered when an action happens</strong>. Like triggering a function when the user is just logged in (or failed).</p>



<p><strong>Filters hook will be used to control WordPress core functions</strong> flow or change its functions output.</p>



<p>I created a full tutorial about WordPress action and filter hooks. read it here:</p>



<p><a href="https://mehdinazari.com/wordpress-action-filter-hooks-tutorial/" target="_blank" rel="noreferrer noopener" aria-label="WordPress Action and Filter Hooks Tutorial (+10 Examples) (opens in a new tab)">WordPress Action and Filter Hooks Tutorial (+10 Examples)</a></p>



<h3 class="wp-block-heading">4- Not all functions need to be inside a plugin</h3>



<p>You can also <strong>write your functions inside your template functions.php file</strong>.</p>



<p>If you do not have lots of code and functionalities in your plugin, you can write these codes inside<strong> </strong><code>function.php</code> file of our template. These functions will act the same as they are in a plugin.</p>



<p>Use action and filter hooks inside your template&#8217;s functions.php file.</p>



<p><strong>functions.php file is located in <code>wp-content/themes/yourtheme</code> directory</strong>.</p>



<p>By yourtheme, I mean your currently active theme folder.</p>



<h3 class="wp-block-heading">5- Advanced WordPress plugin development can be a lot more complicated</h3>



<p>If you want to create a plugin that can modify some functionality in WordPress, it will not take long and it will not be complicated in most cases.</p>



<p>But not all WordPress plugins are easy to create; sometimes, it will take months to create a WordPress plugin that works and has no bugs or issues.</p>



<p>Personally, I worked sometimes for a few months on a single plugin.</p>



<p>It depends on how much WordPress functions can help you achieve what you want. Sometimes you must write thousands of lines of code to achieve your needs.</p>



<p>To speed up your plugin development process, you better use <a href="https://mehdinazari.com/tools-for-wordpress-developers-designers/" target="_blank" rel="noopener" title="">assistant tools for developers</a>.</p>



<h3 class="wp-block-heading">6- You must always be concerned about the security of your WordPress plugin</h3>



<p>When it comes to security, you should always think twice.</p>



<p>The main difference between an expert and a beginner developer is that the expert will always code securely and check the security of his scripts.</p>



<h4 class="wp-block-heading">Some of the best practices for WordPress plugin development security for beginners:</h4>



<ol class="wp-block-list">
<li>sanitize and validate user input values</li>



<li>use &#8220;wp nonce&#8221; to prevent CSRF attacks on forms</li>



<li>check file extensions in upload forms</li>



<li>log important actions done by users</li>



<li>use secure external PHP libraries</li>



<li>check admin privileges on your custom functions (use user_can() function)</li>
</ol>



<h3 class="wp-block-heading">7- Keep your WordPress plugin files and codes nice and simple</h3>



<p>After a few days of developing a WordPress plugin, codes can get messy and hard to understand, especially if your code is only in one file.</p>



<p>The best practice for coding clean is to separate different functions based on usage.</p>



<p>For example, put all your mathematical functions in a file named <code>math_helper.php</code> and include it where you want to use it.</p>



<p>Using the MVC approach is the best way to keep codes clean and functions separated. That&#8217;s why <a aria-label="WP MVC is awesome (opens in a new tab)" href="http://wpmvc.org/" target="_blank" rel="noreferrer noopener">WP MVC is awesome</a>.</p>



<p>By default, WordPress is not MVC. But you can code in MVC if you want. You need to create folders and files for it.</p>



<p>WP MVC plugin already took care of folder structure, and file includes. You can try it for your next WordPress plugin development.</p>



<h3 class="wp-block-heading">8- In WordPress plugin development, you can save data in a Database easily, but be careful</h3>



<p>WordPress provides a global object named <code>$wpdb</code>, you can always call this object and use it by writing <code>global $wpdb;</code> code in your function. Something like this:</p>



<pre><code class="language-php">&lt;?php
function insertDataToDatabase(){
  global $wpdb;
  $table_name = $wpdb-&gt;prefix . "custom_table";
  $wpdb-&gt;insert($table_name, array('name' =&gt; "Test", 'email' =&gt; "test@test.com") ); 
}</code></pre>



<p><code>$wpdb</code> object contains all of the database functions that you need.</p>



<p>in the above code, we used <code>insert()</code> function of <code>$wpdb</code> object to insert our data to custom_table table in the database.</p>



<p>You should be careful when working with a database, especially when saving user inputs.</p>



<p>Remember this: <strong>never trust the user&#8217;s input</strong>.</p>



<p>If you are inserting data with a direct query to the database, you must always sanitize the user&#8217;s input and validate its data type.</p>



<p>you can use <code>sanitize_text_field()</code> function of WordPress to sanitize text fields; also, WordPress provides a sanitize function for all data types. For instance, <code>sanitize_email()</code> sanitizes the user&#8217;s email input.</p>



<h3 class="wp-block-heading">9- Toxic functions and infinitive loops inside a WordPress plugin can break your website</h3>



<p>like any other PHP script, toxic functions can break the whole system.</p>



<p>Like any other PHP script, toxic functions can break the whole system.</p>



<p>By using the term &#8220;toxic functions&#8221; I mean functions that use lots of resources and can cause recourse shortage for your hosting server.</p>



<p>Infinitive loops inside a WordPress plugin or theme can break the system easily and cause lots of trouble for the host server.</p>



<p>Infinitive loops are programming loops that will never end.  Because of a lack of break conditions or wrong conditions, these loops will run until your server is out of resources like CPU power or RAM. </p>



<p>You better learn how to handle frequently used functions like <a href="https://mehdinazari.com/wordpress-query-posts/">query posts using get_posts in an efficient way</a>.</p>



<h3 class="wp-block-heading">10- You can use CSS, jQuery, and JavaScript to create stunning layouts for your WordPress plugins</h3>



<p>there are 3 ways you can add custom CSS and JS codes to your plugin&#8217;s admin page.</p>



<ol class="wp-block-list">
<li>use inline CSS and JS codes</li>



<li>including CSS and JS using <code>&lt;style&gt;</code> and <code>&lt;script&gt;</code> tags on pages</li>



<li>including external CSS and JS using WordPress <code>wp_enqueue_style()</code> and <code>admin_enqueue_scripts()</code> functions.</li>
</ol>



<p>After including your custom CSS and JS codes, you can use them to stylize your WordPress plugin&#8217;s page.</p>



<p>you can include CSS and JS frameworks like Bootstrap and create your layout based on them.</p>



<p>jQuery is enabled by default on the WordPress admin page. you can write jQuery codes and run them without including the jQuery library. (it&#8217;s already included)</p><p>The post <a href="https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress/">How to Create a Hello World Plugin for WordPress [2023]</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Set Post Publish Date Programmatically in WordPress</title>
		<link>https://mehdinazari.com/new-post-after-a-while/</link>
					<comments>https://mehdinazari.com/new-post-after-a-while/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Mon, 10 Jun 2019 19:36:36 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<category><![CDATA[WordPress Plugin Development]]></category>
		<category><![CDATA[WordPress Tips]]></category>
		<guid isPermaLink="false">https://mehdinazari.com/?p=6</guid>

					<description><![CDATA[<p>You can set publish date for posts in the WordPress admin panel but sometimes you may want to set a post publishing date programmatically. for example, when you have lots of unpublished posts and you want to publish these posts on different dates in the future, you can set the publish date for each post [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/new-post-after-a-while/">How to Set Post Publish Date Programmatically in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>You can set publish date for posts in the WordPress admin panel but sometimes you may want to set a post publishing date programmatically. for example, when you have lots of unpublished posts and you want to publish these posts on different dates in the future, you can set the publish date for each post programmatically inside a loop (bulk publishing date setting for WordPress posts), using WordPress update post function.</p>



<span id="more-6"></span>



<p>The short answer for the &#8220;How to set date and time for a WordPress post programmatically&#8221; question is here:</p>



<pre><code class="language-php">$id = 1;
$date_time = "2021-12-31 23:59:59";//[Y-m-d H:i:s]
wp_update_post(
    array (
        'ID' =&gt; $id,
        'post_date' =&gt; $date_time,
        'post_date_gmt' =&gt; get_gmt_from_date( $date_time )
    )
);</code></pre>



<p>The above codes will update a post with the id number 1 and set the post publishing date.</p>



<p>Here is more explanation if you are interested:</p>



<p><code>wp_update_post()</code> function can update a post in WordPress, using an array of attributes with value.</p>



<p>You must pass the id of the post you wish to update, using the <code>ID</code> attribute.</p>



<p>You can set <code>post_date</code> and <code>post_date_gmt</code> to change the post publishing date to whatever you want.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Proper structure for <code>post_date</code> attribute is <code>Y-m-d H:i:s</code></p>
</blockquote>



<p>If you want to know how to <a href="https://mehdinazari.com/wordpress-query-posts/">query posts in WordPress</a> using publish date, you can read my tutorial:</p>



<p><a href="https://mehdinazari.com/wordpress-query-posts/">WordPress Query Posts by Category, Tag, Custom attribute, and more!</a></p><p>The post <a href="https://mehdinazari.com/new-post-after-a-while/">How to Set Post Publish Date Programmatically in WordPress</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/new-post-after-a-while/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>I&#8217;m Mehdi Nazari, a WordPress Developer.</title>
		<link>https://mehdinazari.com/hello-world/</link>
					<comments>https://mehdinazari.com/hello-world/#respond</comments>
		
		<dc:creator><![CDATA[Mehdi Nazari]]></dc:creator>
		<pubDate>Fri, 08 Feb 2019 12:37:03 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Test driven development tips]]></category>
		<guid isPermaLink="false">http://mehdinazari.com/?p=1</guid>

					<description><![CDATA[<p>Hi everyone; my name is Mehdi Nazari, and I&#8217;m a WordPress developer. I created this blog to write helpful WordPress articles for beginner and experienced developers. I&#8217;m a full-stack developer with over 12 years of experience developing themes and plugins for WordPress CMS. I learned HTML &#38; CSS in 2007 and created a few static [&#8230;]</p>
<p>The post <a href="https://mehdinazari.com/hello-world/">I’m Mehdi Nazari, a WordPress Developer.</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hi everyone; my name is Mehdi Nazari, and I&#8217;m a WordPress developer. I created this blog to write helpful WordPress articles for beginner and experienced developers.</p>



<span id="more-1"></span>



<p>I&#8217;m a full-stack developer with over 12 years of experience developing themes and plugins for WordPress CMS.</p>



<p>I learned HTML &amp; CSS in 2007 and created a few static websites at the time. I started programming C++ in 2008, but soon I learned PHP, which seemed interesting.</p>



<p>I started developing WordPress in 2009 when WordPress was version 2. before that, I worked with Joomla! and PHP nuke (a really old CMS!).</p>



<p>as a Full Stack developer, I&#8217;m also experienced in creating mobile applications. I started developing android applications in 2015 and iOS applications in 2018.</p>



<p>I decided to create this blog to help other developers overcome WordPress issues and help beginners start developing WordPress plugins and themes.</p>



<p>In the future, I will write helpful tutorials about WordPress plugins and theme development, WordPress management tricks, and WordPress SEO tips.</p><p>The post <a href="https://mehdinazari.com/hello-world/">I’m Mehdi Nazari, a WordPress Developer.</a> first appeared on <a href="https://mehdinazari.com">Mehdi Nazari: WordPress Developer</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://mehdinazari.com/hello-world/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
