{"id":1713,"date":"2019-04-21T20:45:47","date_gmt":"2019-04-21T17:45:47","guid":{"rendered":"https:\/\/esfirum.com\/?p=1713"},"modified":"2021-11-30T10:51:12","modified_gmt":"2021-11-30T07:51:12","slug":"best-wordpress-snippets","status":"publish","type":"post","link":"https:\/\/esfirum.com\/en\/blog\/best-wordpress-snippets\/","title":{"rendered":"Best WordPress snippets"},"content":{"rendered":"<p><strong>Snippet<\/strong> is a short piece of code that performs a specific function and can be reused in development.<\/p>\n<p>Regarding CMS WordPress &#8211; the use of snippets will significantly speed up the creation of a website and help the wordpress-developer &#8220;not reinvent the wheel&#8221; in solving their problems.<\/p>\n<p>In this article, we will look at the best, in our opinion, snippets for CMS WordPress, which are used by the developers of our company.<\/p>\n<h2>Get_template_part() output via Shortcode<\/h2>\n<p>Very often there are situations when you need to insert a piece of code into the WordPress editor. For example, you wrote a paragraph of text, after which you want to put a manually written slider.<\/p>\n<p>How to insert the created slider into the finished code so as not to break anything? Of course &#8211; using a <strong>shortcode<\/strong>. The WordPress repository provides a large number of different sliders that can be embedded into your code using a construction like <strong>[slick-slider]<\/strong>. But what if we want to use our own custom slider, which we have been writing for so long? Everything is very simple.<\/p>\n<p>We register a new shortcode in <strong>functions.php<\/strong> that will return us a template with our slider or any other code fragment you need. To do this, we use the function &#8211; <strong>get_template_part()<\/strong>, then get the contents of the current buffer and clean it up with the function &#8211; <strong>ob_get_clean<\/strong>. Now in the editor we can call the short code &#8211; <strong>[slider]<\/strong>, which in turn will pull up the <strong>slider-part.php<\/strong> template. Don&#8217;t forget that we don&#8217;t use <strong>get_header()<\/strong> and <strong>get_footer()<\/strong> in this file!<\/p>\n<pre class=\"lang:default decode:true\">function slider-shortcode( $attr ) {\r\n\tob_start();\r\n\tget_template_part( 'slider-part' );\r\n\treturn ob_get_clean();\r\n}\r\n\r\nadd_shortcode( 'slider', 'slider-shortcode' );\r\n<\/pre>\n<h2>Standard WordPress Loop<\/h2>\n<p>The backbone of WordPress website development is a standard loop that displays all posts. This is a frequently used snippet, it takes a long time to write and you have to look at the code often in order to understand how it looks. Here he is<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;\r\n\t&lt;?php the_title(); ?&gt;\r\n&lt;?php endwhile; else : ?&gt;\r\n\t&lt;p&gt;&lt;?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?&gt;&lt;\/p&gt;\r\n&lt;?php endif; ?&gt;<\/pre>\n<p>Loop that outputs posts with custom post type<\/p>\n<p>You have created your own type of records, now you need to display these records somehow. This is where wp_query{} comes to the rescue. This is a PHP class that receives records from the database according to the parameters that we give it. We specify the parameters in the $args array.<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php $args=array(\r\n'post_type' =&gt; 'artist',\r\n'post_status' =&gt; 'publish',\r\n'posts_per_page' =&gt; -1,\r\n);\r\n\r\n$my_query = null;\r\n$my_query = new WP_Query($args);if( $my_query-&gt;have_posts() ) {\r\n\twhile ($my_query-&gt;have_posts()) : $my_query-&gt;the_post();\r\n\t\tthe_title();\r\n\tendwhile;}\r\nwp_reset_query(); ?&gt;<\/pre>\n<h2>Displaying posts using Bootstrap 3 or 4<\/h2>\n<p>Probably the most frequently asked question on stackoverflow. We all know that in bootstrap 3-4 &#8211; columns need to be split in rows &#8211; &lt;div class=\u201drow\u201d&gt;&lt;\/div&gt;. The problem is that the standard WordPress loop will display all the posts that are in the database and that&#8217;s it. We need to somehow break this cycle so that every 3 posts (imagine that we have a grid of 3 columns) are split side by side (row). For this we use wp_query. And now the most magical and simple thing &#8211; we just wrap every 4 elements of the loop in &lt;div class=\u201drow\u201d&gt;&lt;\/div&gt; using a simple construction:<\/p>\n<pre class=\"lang:default decode:true \">if($i % 4 == 0) { ?&gt;\r\n\t&lt;div class=\"row\"&gt;\r\n&lt;?php } ?&gt;<\/pre>\n<p>Now we need to close div. We close with this construction:<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php $i++; if($i != 0 &amp;&amp; $i % 4 == 0) { ?&gt;\r\n\t&lt;\/div&gt;&lt;!--\/.row--&gt;\r\n\t&lt;div class=\"clearfix\"&gt;&lt;\/div&gt;\r\n&lt;?php } ?&gt;<\/pre>\n<p>Add\u00a0 &lt;div class=&#8221;clearfix&#8221;&gt;&lt;\/div&gt; so that Bootstrap 3, which is still on float, breaks columns in rows.<\/p>\n<p>Ready code:<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php $args=array(\r\n'post_type' =&gt; 'portfolio',\r\n'post_status' =&gt; 'publish',\r\n'posts_per_page' =&gt; -1,\r\n);\r\n$my_query = null;\r\n$my_query = new WP_Query($args);if( $my_query-&gt;have_posts() ) {\r\n\r\nwhile ($my_query-&gt;have_posts()) : $my_query-&gt;the_post();\r\n\tif($i % 4 == 0) { ?&gt;\r\n\t&lt;div class=\"row\"&gt;\r\n\t\t&lt;?php } ?&gt;\r\n\t\t&lt;div class=\"col-md-3\"&gt;\r\n\t\t\t&lt;?php the_title(); ?&gt;\r\n\t\t&lt;\/div&gt;\r\n\t\t&lt;?php $i++; if($i != 0 &amp;&amp; $i % 4 == 0) { ?&gt;\r\n\t&lt;\/div&gt;&lt;!--\/.row--&gt;\r\n\t&lt;div class=\"clearfix\"&gt;&lt;\/div&gt;\r\n&lt;?php } endwhile; wp_reset_query(); }?&gt;<\/pre>\n<h2>Connecting styles and scripts in WordPress<\/h2>\n<p>There are several options for including scripts and styles in a theme. Let&#8217;s consider the most popular ones:<\/p>\n<h3>Connecting directly in &lt;head&gt; of the page<\/h3>\n<p>I think that almost every developer who included style files wanted to immediately get into header.php and connect the style using the standard construction:<\/p>\n<pre class=\"lang:default decode:true \">&lt;link rel=\"stylesheet\" href=\"&lt;?php echo get_template_directory_uri(); ?&gt;\/styles.css\"&gt;<\/pre>\n<p>This option will work, but it is wrong to do so, since some caching plugins such as WP Total Cache will not be able to see and process the styles connected in this way.<\/p>\n<h3>Connecting in functions.php<\/h3>\n<p>Let&#8217;s consider the correct option, which we recommend using in development. We will use a function that is included in the functions.php file:<\/p>\n<pre class=\"lang:default decode:true \">function <em>name<\/em>(){\r\n\twp_enqueue_style( 'foundation-min-css', get_template_directory_uri() . '\/css\/style.css', array(), '1.0.0', 'all');\r\n\twp_enqueue_script('app-js', get_template_directory_uri() . '\/js\/app.js', array(), '1.0.0', true);\r\n}\r\n\r\nadd_action( 'wp_enqueue_scripts', '<em>name<\/em>' );<\/pre>\n<p>wp_enqueue_style &#8211; function that registers the stylesheet<\/p>\n<p>wp_enqueue_script &#8211; function that registers js files<\/p>\n<p>You can read more about these functions in <a href=\"https:\/\/codex.wordpress.org\/\">official documentation<\/a>.<\/p>\n<p>After registering the styles, we need to call our function. For this we use &#8211; add_action &#8211; wp_enqueue_scripts.<\/p>\n<h2>Registration and display of the menu in theme<\/h2>\n<p>One of the most frequently asked questions in Google searches from wordpress developers. How do I display the &#8220;menu&#8221;? How do I register it? Everything is very simple. First, let&#8217;s add a function that will create the menu we need and display it in the WordPress admin area. In the function, we pass an array with the number of &#8220;menus&#8221; that we need. In the example we will create one menu &#8211; topmenu<\/p>\n<pre class=\"lang:default decode:true \">register_nav_menus(array('top'=&gt;'topmenu'));<\/pre>\n<p>We registered the &#8220;menu&#8221;, added several items of this &#8220;menu&#8221; to the admin panel. Next, you need to bring it out somewhere.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1718 size-full\" src=\"https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/menu.jpg\" alt=\"\u0412\u044b\u0432\u043e\u0434 \u043c\u0435\u043d\u044e \u0432 \u0430\u0434\u043c\u0438\u043d \u043f\u0430\u043d\u0435\u043b\u044c wordpress\" width=\"1040\" height=\"656\" srcset=\"https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/menu.jpg 1040w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/menu-300x189.jpg 300w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/menu-768x484.jpg 768w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/menu-1024x646.jpg 1024w\" sizes=\"auto, (max-width: 1040px) 100vw, 1040px\" \/><\/p>\n<p>In the subject &#8211; we insert the following code using the wp_nav_menu function. We pass to the array &#8211; the menu that needs to be displayed + wrap it in the classes and tags we need.<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php wp_nav_menu( array (\r\n\t'menu' =&gt; 'topmenu',\r\n\t'items_wrap' =&gt; '&lt;ul class=\"mobile_menu text-left main_menu\" data-dropdown-menu&gt;%3$s&lt;\/ul&gt;'\r\n)); ?&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2707 size-large\" src=\"https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/esfirum-menu-1024x484.jpg\" alt=\"esfirum \u043c\u0435\u043d\u044e \u0441\u0430\u0439\u0442\u0430\" width=\"1024\" height=\"484\" srcset=\"https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/esfirum-menu-1024x484.jpg 1024w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/esfirum-menu-300x142.jpg 300w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/esfirum-menu-768x363.jpg 768w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/esfirum-menu-1536x727.jpg 1536w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/esfirum-menu.jpg 1600w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<h2>How to limit the number of characters in a function the_excerpt()<\/h2>\n<p>Function the_excerpt() displays all the content that we will put in the short content of the post. Very often you need to display all its content in the post itself, and for example, on the category page, where we have a grid with posts, display only the first 20 characters, hide the rest under dots (&#8230;)<\/p>\n<p>To do this, create a function in functions.php<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1720 size-full\" src=\"https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/excerpt.jpg\" alt=\"\u0432\u044b\u0432\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 the excerpt\" width=\"1200\" height=\"410\" srcset=\"https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/excerpt.jpg 1200w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/excerpt-300x103.jpg 300w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/excerpt-768x262.jpg 768w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/excerpt-1024x350.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<pre class=\"lang:default decode:true \">function excerpt($limit) {\r\n\t$excerpt = explode(' ', get_the_excerpt(), $limit);\r\n\tif (count($excerpt)&gt;=$limit) {\r\n\tarray_pop($excerpt);\r\n\t$excerpt = implode(\" \",$excerpt).'...';\r\n\t} else {\r\n\t$excerpt = implode(\" \",$excerpt);\r\n\t}\r\n\t$excerpt = preg_replace('`[[^]]*]`','',$excerpt);\r\n\treturn $excerpt;\r\n}<\/pre>\n<p>We transfer our &#8211; get_the_excerpt() and check if it matches the specified number of characters, add 3 dots and return a variable with our content. Now in the place we need &#8211; we call the function and pass into it the number of characters that we need.<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php echo excerpt(20) ?&gt;<\/pre>\n<h2>Adding a panel with options using Advanced Custom Fields PRO<\/h2>\n<p>Very often we have to add the ability for the client to change the content that is used on all pages of the site. For example: logo, phone numbers, e-mail, etc.<\/p>\n<p>We can use standard WordPress meta fields for this, but I find they are extremely awkward, with an unattractive design. For this, it is best to use the plugin &#8220;ACF PRO&#8221; (you can read more about this plugin in our article <a href=\"https:\/\/esfirum.com\/en\/blog\/top-10-plaginov-dlya-cms-wordpress\/\" rel=\"\">\u00abBest WordPress plugins\u00bb<\/a>).<\/p>\n<p>First, we need to register our options panel in functions.php.<\/p>\n<pre class=\"lang:default decode:true \">if( function_exists('acf_add_options_page') ) {\r\n\tacf_add_options_page(array(\r\n\t\t'page_title'\u00a0\u00a0\u00a0\u00a0 =&gt; 'Theme Settings',\r\n\t\t'menu_title'\u00a0\u00a0\u00a0 =&gt; 'Theme Settings',\r\n\t\t'menu_slug'\u00a0\u00a0\u00a0\u00a0 =&gt; 'theme-general-settings',\r\n\t));\r\n}<\/pre>\n<p>Specify the page title, menu title, slug in the array.<\/p>\n<p>After that, in the ACF plugin panel, add our group of fields. Below on the page, we indicate that it belongs to our options panel &#8211; theme settings.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1721 size-full\" src=\"https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/acf-example.jpg\" alt=\"\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u043f\u0430\u043d\u0435\u043b\u0435 acf custom fields \u0433\u0440\u0443\u043f\u043f\u044b \u043f\u043e\u043b\u0435\u0439\" width=\"1419\" height=\"325\" srcset=\"https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/acf-example.jpg 1419w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/acf-example-300x69.jpg 300w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/acf-example-768x176.jpg 768w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/acf-example-1024x235.jpg 1024w\" sizes=\"auto, (max-width: 1419px) 100vw, 1419px\" \/><\/p>\n<p>In the admin panel, we will have a menu item that is responsible for our panel with settings. We fill in all the data. In our case, this is a logo and a phone.<\/p>\n<p>Next, we need to display in the subject, in the place we need, the fields that we have created. This is done simply:<\/p>\n<p>&lt;?php echo get_field(\u2018logo\u2019, \u2018options\u2019) ?&gt; &#8211;\u00a0will return us the url to the image<\/p>\n<p>&lt;?php echo get_field(\u2018tel-1\u2019, \u2018options\u2019) ?&gt; &#8211; will return us the text, in this case the phone number that we provided on the options page.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1722 size-full\" src=\"https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/logo-front-example.jpg\" alt=\"\u0432\u044b\u0432\u043e\u0434 \u043f\u043e\u043b\u0435\u0439 ACF custom fields \u0432 \u043d\u0443\u0436\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435\" width=\"1741\" height=\"712\" srcset=\"https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/logo-front-example.jpg 1741w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/logo-front-example-300x123.jpg 300w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/logo-front-example-768x314.jpg 768w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/logo-front-example-1024x419.jpg 1024w\" sizes=\"auto, (max-width: 1741px) 100vw, 1741px\" \/><\/p>\n<h3>Disable all WordPress updates<\/h3>\n<p>There are times when you need to protect the client from unnecessary actions in the administrative panel. If the client has full access to the admin panel and to all of its sections, there is a danger that a person not knowing the specifics of the CMS WordPress updates all plugins and the core itself. In this case, conflicts between new versions of plugins and the WP core itself may arise. To avoid such problems, you need to turn off updates. This is done quite simply &#8211; we add several filters to the functions.php file<\/p>\n<pre class=\"lang:default decode:true \">\/\/ WordPress updates\r\nadd_filter('pre_site_transient_update_core',create_function('$a', \"return null;\"));\r\nwp_clear_scheduled_hook('wp_version_check');\r\n\r\n\/\/ plugins updates\r\nremove_action( 'load-update-core.php', 'wp_update_plugins' );\r\nadd_filter( 'pre_site_transient_update_plugins', create_function( '$a', \"return null;\" ) );<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1723 size-full\" src=\"https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/updates.jpg\" alt=\"\u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 wordpress updates\" width=\"764\" height=\"232\" srcset=\"https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/updates.jpg 764w, https:\/\/esfirum.com\/wp-content\/uploads\/2019\/04\/updates-300x91.jpg 300w\" sizes=\"auto, (max-width: 764px) 100vw, 764px\" \/><\/p>\n<h3>How to register Custom post type<\/h3>\n<p>Above, we looked at how to display posts with a custom post type. We will now look at how to create a custom post type to display in the admin panel.<\/p>\n<p>The problem is this: in WordPress there are Posts and Pages &#8211; usually posts are used for News or Blogs. Pages &#8211; for static pages. Let&#8217;s say we need to create a custom post type &#8211; Products. To do this, go to the functions.php file and register our custom post<\/p>\n<pre class=\"lang:default decode:true \">\/\/ Register Custom Post Type\r\nfunction custom_post_type() {\r\n\r\n\t$labels = array(\r\n\t'name'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; _x( 'Post Types', '\u0422\u043e\u0432\u0430\u0440\u044b', 'text_domain' ),\r\n\t'singular_name'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; _x( 'Post Type', '\u0422\u043e\u0432\u0430\u0440', 'text_domain' ),\r\n\t'menu_name'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( '\u0422\u043e\u0432\u0430\u0440\u044b', 'text_domain' ),\r\n\t'name_admin_bar'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( '\u0422\u043e\u0432\u0430\u0440\u044b', 'text_domain' ),\r\n\t'archives'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'Item Archives', 'text_domain' ),\r\n\t'attributes'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'Item Attributes', 'text_domain' ),\r\n\t'parent_item_colon'\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'Parent Item:', 'text_domain' ),\r\n\t'all_items'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'All Items', 'text_domain' ),\r\n\t'add_new_item'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'Add New Item', 'text_domain' ),\r\n\t'add_new'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'Add New', 'text_domain' ),\r\n\t'new_item'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'New Item', 'text_domain' ),\r\n\t'edit_item'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'Edit Item', 'text_domain' ),\r\n\t'update_item'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'Update Item', 'text_domain' ),\r\n\t'view_item'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'View Item', 'text_domain' ),\r\n\t'view_items'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'View Items', 'text_domain' ),\r\n\t'search_items'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'Search Item', 'text_domain' ),\r\n\t'not_found'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'Not found', 'text_domain' ),\r\n\t'not_found_in_trash'\u00a0\u00a0\u00a0 =&gt; __( 'Not found in Trash', 'text_domain' ),\r\n\t'featured_image'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'Featured Image', 'text_domain' ),\r\n\t'set_featured_image'\u00a0\u00a0\u00a0 =&gt; __( 'Set featured image', 'text_domain' ),\r\n\t);\r\n\t$args = array(\r\n\t'label'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'Post Type', 'text_domain' ),\r\n\t'description'\u00a0\u00a0\u00a0\u00a0 =&gt; __( 'Post Type Description', 'text_domain' ),\r\n\t'labels'\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; $labels,\r\n\t'supports'\u00a0\u00a0\u00a0\u00a0 =&gt; false,\r\n\t'taxonomies'\u00a0\u00a0\u00a0\u00a0 =&gt; array( 'category', 'post_tag' ),\r\n\t'hierarchical'\u00a0\u00a0\u00a0 =&gt; false,\r\n\t'public'\u00a0\u00a0\u00a0\u00a0 =&gt; true,\r\n\t'show_ui'\u00a0\u00a0\u00a0 =&gt; true,\r\n\t'show_in_menu'\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; true,\r\n\t'menu_position'\u00a0\u00a0 =&gt; 5,\r\n\t'show_in_admin_bar'\u00a0\u00a0\u00a0\u00a0 =&gt; true,\r\n\t'show_in_nav_menus'\u00a0\u00a0\u00a0\u00a0 =&gt; true,\r\n\t'can_export'\u00a0\u00a0 =&gt; true,\r\n\t'has_archive'\u00a0 =&gt; true,\r\n\t'exclude_from_search'\u00a0\u00a0 =&gt; false,\r\n\t'publicly_queryable'\u00a0\u00a0\u00a0 =&gt; true,\r\n\t'capability_type'\u00a0 =&gt; 'page',\r\n\t);\r\n\tregister_post_type( 'post_type', $args );\r\n\r\n}\r\nadd_action( 'init', 'custom_post_type', 0 );<\/pre>\n<p>Don&#8217;t be intimidated by the sheer number of options. Basically, these are translations and headings of menu items such as \u201cAdd Product\u201d, \u201cAll Products\u201d, etc.<\/p>\n<p>Description of each of the array parameters &#8211; you can find in the official WordPress documentation<\/p>\n<p><a href=\"https:\/\/codex.wordpress.org\/Function_Reference\/register_post_type\">https:\/\/codex.wordpress.org\/Function_Reference\/register_post_type<\/a><\/p>\n<p>Take a close look at the array parameters $args. After registering a custom type, you will see a \u201cProducts\u201d section in your menu.<\/p>\n<p>We will be grateful for your comments and questions, it will inspire us to write new interesting articles!<\/p>","protected":false},"excerpt":{"rendered":"<p>Snippet is a short piece of code that performs a specific function and can be reused in development. Regarding CMS <span class=\"view-full-post\"><a href=\"https:\/\/esfirum.com\/en\/blog\/best-wordpress-snippets\/\" class=\"view-full-post-btn\">&#8230;<\/a><\/span><\/p>\n","protected":false},"author":4,"featured_media":1730,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-1713","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"acf":[],"_links":{"self":[{"href":"https:\/\/esfirum.com\/en\/wp-json\/wp\/v2\/posts\/1713","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/esfirum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/esfirum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/esfirum.com\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/esfirum.com\/en\/wp-json\/wp\/v2\/comments?post=1713"}],"version-history":[{"count":0,"href":"https:\/\/esfirum.com\/en\/wp-json\/wp\/v2\/posts\/1713\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/esfirum.com\/en\/wp-json\/wp\/v2\/media\/1730"}],"wp:attachment":[{"href":"https:\/\/esfirum.com\/en\/wp-json\/wp\/v2\/media?parent=1713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/esfirum.com\/en\/wp-json\/wp\/v2\/categories?post=1713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/esfirum.com\/en\/wp-json\/wp\/v2\/tags?post=1713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}