{"id":27183,"date":"2020-09-15T16:00:23","date_gmt":"2020-09-15T10:30:23","guid":{"rendered":"https:\/\/www.the-next-tech.com\/?p=27183"},"modified":"2020-09-15T16:33:26","modified_gmt":"2020-09-15T11:03:26","slug":"wordpress-custom-fields-101-tips-tricks-and-hacks","status":"publish","type":"post","link":"https:\/\/www.the-next-tech.com\/review\/wordpress-custom-fields-101-tips-tricks-and-hacks\/","title":{"rendered":"WordPress Custom Fields 101: Tips, Tricks and Hacks"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Do you want to learn more about the custom fields of WordPress? Are you looking for valuable tips, tricks, and hack when using this feature? If yes, this post is for you.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A lot of people find <\/span><a href=\"https:\/\/elementor.com\/blog\/wordpress-custom-fields\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">custom fields<\/span><\/a><span style=\"font-weight: 400;\"> as a cool feature of WordPress. Why not? It lets you add more information not only to your WordPress posts but your pages as well. Besides, you can use this feature for storing important information and use it on your site later on.<\/span><\/p>\n<h2>WordPress Custom Fields Overview<\/h2>\n<p><span style=\"font-weight: 400;\">WordPress custom fields refer to the metadata used for adding additional post- or page-related information to what you are editing. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">With WP custom fields, you can repeatedly add the same data or information to multiple posts, even in content-heavy sites.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Using this feature makes it possible for you to create an area in the editor to add a particular type of data or information to every post or page. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">For example, you can incorporate a disclaimer for an affiliate content or a rating for product reviews.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This WordPress feature, as a default, is hidden. You can view it by clicking on the three-dot menu that is located at the screen\u2019s top right corner. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">After that, click \u201cOptions\u201d from the menu and check the \u201cCustom fields\u201d option under the Advanced Panels. Next is to click the \u201cEnable &amp; Reload\u201d button. The post editor reloads, and you will see the custom fields panel.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now, let\u2019s get into the tips, tricks, and hacks in <a href=\"https:\/\/www.the-next-tech.com\/development\/essential-tips-for-wordpress-beginners\/\">using WordPress<\/a> custom fields.<\/span><\/p>\n<h3>Add Custom Fields in WordPress<\/h3>\n<p><span style=\"font-weight: 400;\">Edit the post or page that you wish to add the custom field before you proceed to the custom meta box. Make sure to make a name for the custom field. After that, enter the value and save it by clicking the \u201cAdd Custom Field.\u201d\u00a0<\/span><\/p>\n<h3>Find Custom Field in Dropdown on Post Edit Screen<\/h3>\n<p><span style=\"font-weight: 400;\">If you cannot see the newly created custom field, then you can fix this issue by adding the following code to the site-specific plugin or functions.php of your theme:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"wp-image-27184 size-full aligncenter\" src=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145232\/Word-Press.png\" alt=\"\" width=\"521\" height=\"102\" srcset=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145232\/Word-Press.png 521w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145232\/Word-Press-300x59.png 300w\" sizes=\"(max-width: 521px) 100vw, 521px\" \/><\/p>\n<h3>Add Custom Fields with the Use of Advanced Custom Fields<\/h3>\n<p><span style=\"font-weight: 400;\">First, install and activate the Advanced custom field plugin. Once activated, visit the Custom Fields <\/span><b>\u00bb<\/b><span style=\"font-weight: 400;\">Field Groups page, then click on the button, \u201cAdd New\u201d. Make sure to provide a title for the field group before clicking on the \u201cAdd Field\u201d button.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Next is to provide a name for the custom field. Then, select a field type. As you scroll down, other options will appear. Feel free to change them ad add multiple fields to the field group. To save the changes, click on the \u201cPublish button.<\/span><\/p>\n<h3>Display Content Only<\/h3>\n<p><span style=\"font-weight: 400;\">Mind some specific custom-field keys that do not exist in all posts. You can use the following code to prevent incomplete, empty, or unwanted markup from destroying your page validity:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"aligncenter wp-image-27185 size-full\" src=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145229\/Word-Press-1.png\" alt=\"\" width=\"539\" height=\"177\" srcset=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145229\/Word-Press-1.png 539w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145229\/Word-Press-1-300x99.png 300w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145229\/Word-Press-1-20x8.png 20w\" sizes=\"(max-width: 539px) 100vw, 539px\" \/><\/p>\n<h3>Display A List of Key Values<\/h3>\n<p><span style=\"font-weight: 400;\">You can use the following basic code template to display a list of existing key values:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"wp-image-27186 size-full aligncenter\" src=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145226\/Word-Press-2.png\" alt=\"\" width=\"559\" height=\"401\" srcset=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145226\/Word-Press-2.png 559w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145226\/Word-Press-2-300x215.png 300w\" sizes=\"(max-width: 559px) 100vw, 559px\" \/><\/p>\n<h3>Check If the Custom Field Is Not Empty<\/h3>\n<p><span style=\"font-weight: 400;\">Before displaying the custom field, it\u2019s essential to check if it is not empty. You can do it by modifying the following code to see if data exists in the field:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"wp-image-27187 size-full aligncenter\" src=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145221\/Word-Press-3.png\" alt=\"\" width=\"601\" height=\"261\" srcset=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145221\/Word-Press-3.png 601w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145221\/Word-Press-3-300x130.png 300w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145221\/Word-Press-3-20x8.png 20w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145221\/Word-Press-3-30x13.png 30w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145221\/Word-Press-3-80x34.png 80w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Make sure to replace the \u201cMood\u201d with your desired field name.<\/span><\/p>\n<h3>Add Guest Author Name with the Use of Custom Fields<\/h3>\n<p><span style=\"font-weight: 400;\">First, add the following code in the site-specific plugin or the functions.php file of your theme:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"wp-image-27188 size-full aligncenter\" src=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145217\/Word-Press-4.png\" alt=\"\" width=\"558\" height=\"187\" srcset=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145217\/Word-Press-4.png 558w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145217\/Word-Press-4-300x101.png 300w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145217\/Word-Press-4-20x8.png 20w\" sizes=\"(max-width: 558px) 100vw, 558px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">If an author\u2019s name exists, then you need to replace it with the guest author\u2019s name. Next is to edit the post you wish to display it. Lastly, go to the custom fields meta box to add the guest author name.<\/span><\/p>\n<h3>Display Custom Fields Outside the Look<\/h3>\n<p><span style=\"font-weight: 400;\">In order for you to display the custom fields outside the loop, the following code will help you:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"wp-image-27189 size-full aligncenter\" src=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145214\/Word-Press-5.png\" alt=\"\" width=\"578\" height=\"104\" srcset=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145214\/Word-Press-5.png 578w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145214\/Word-Press-5-300x54.png 300w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145214\/Word-Press-5-570x104.png 570w\" sizes=\"(max-width: 578px) 100vw, 578px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Make sure to replace the key with your chosen field name.<\/span><\/p>\n<h3>Display Contributors to the Article<\/h3>\n<p><span style=\"font-weight: 400;\">Edit the post you wish to display the contributors or co-contributors. Next is to scroll down to the custom fields meta box. After that, add the author names as co-author custom fields.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Add the following code to the theme files you want to show the co-authors:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"wp-image-27190 size-full aligncenter\" src=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145210\/Word-Press-6.png\" alt=\"\" width=\"594\" height=\"273\" srcset=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145210\/Word-Press-6.png 594w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145210\/Word-Press-6-300x138.png 300w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145210\/Word-Press-6-20x8.png 20w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145210\/Word-Press-6-30x13.png 30w\" sizes=\"(max-width: 594px) 100vw, 594px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Add the following custom CSS in order for you to display the author names that are separated by commas:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"aligncenter wp-image-27191 size-full\" src=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145206\/Word-Press-7.png\" alt=\"\" width=\"580\" height=\"268\" srcset=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145206\/Word-Press-7.png 580w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145206\/Word-Press-7-300x139.png 300w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145206\/Word-Press-7-20x8.png 20w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145206\/Word-Press-7-30x13.png 30w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/p>\n<h3>Determine the Type of Content Appears On A Page<\/h3>\n<p><span style=\"font-weight: 400;\">You can use custom field values in determining which content type appears on a page. For example, let\u2019s check the custom field key-value called \u201chobbies.\u201d You can use the following codes:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"wp-image-27192 size-full aligncenter\" src=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145202\/Word-Press-8.png\" alt=\"\" width=\"592\" height=\"232\" srcset=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145202\/Word-Press-8.png 592w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145202\/Word-Press-8-300x118.png 300w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145202\/Word-Press-8-20x8.png 20w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145202\/Word-Press-8-30x13.png 30w\" sizes=\"(max-width: 592px) 100vw, 592px\" \/><\/p>\n<h3>Display Custom Header, Footer, and Sidebar<\/h3>\n<p><span style=\"font-weight: 400;\">Edit the post or page you wish to show a different sidebar. Next is to add the sidebar as a custom field. After that, edit the files like single.php. Look for the following code:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"wp-image-27194 size-full aligncenter\" src=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145157\/Word-Press-10.png\" alt=\"\" width=\"362\" height=\"40\" srcset=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145157\/Word-Press-10.png 362w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145157\/Word-Press-10-300x33.png 300w\" sizes=\"(max-width: 362px) 100vw, 362px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Make sure to replace it with the following code:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"wp-image-27193 size-full aligncenter\" src=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145159\/Word-Press-9.png\" alt=\"\" width=\"562\" height=\"133\" srcset=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145159\/Word-Press-9.png 562w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145159\/Word-Press-9-300x71.png 300w\" sizes=\"(max-width: 562px) 100vw, 562px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">In your theme folder, create a sidebar-wpbpage.php file. As a starting point, feel free to copy the code from the sidebar.php file of your theme.<\/span><\/p>\n<h3>Manipulate RRS Feed Title<\/h3>\n<p><span style=\"font-weight: 400;\">First, add the following code in the <a href=\"https:\/\/www.the-next-tech.com\/development\/5-best-wordpress-slider-plugins-in-2020\/\">site-specific plugin<\/a> or functions.php file of your theme:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"aligncenter wp-image-27195 size-full\" src=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145153\/Word-Press-11.png\" alt=\"\" width=\"595\" height=\"322\" srcset=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145153\/Word-Press-11.png 595w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145153\/Word-Press-11-300x162.png 300w\" sizes=\"(max-width: 595px) 100vw, 595px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">After that, edit the post you wish to display the extra text. Next is to add the guest_post and sponsored_post in custom fields.<\/span><\/p>\n<h3>Manipulate RRS Feed Content<\/h3>\n<p><span style=\"font-weight: 400;\">First, add the following code in the site-specific plugin or functions.php file of your theme:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"wp-image-27196 size-full aligncenter\" src=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145149\/Word-Press-12.png\" alt=\"\" width=\"596\" height=\"316\" srcset=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145149\/Word-Press-12.png 596w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145149\/Word-Press-12-300x159.png 300w\" sizes=\"(max-width: 596px) 100vw, 596px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Next is to create a custom field known as \u201ccool custom.\u201d After that, add any value and use it to display text, images, advertisements, and anything you want.<\/span><\/p>\n<p><strong>Set Expiration Date for Posts\u00a0<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">First, edit the theme files. After that, add and modify the loop like this:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"wp-image-27197 size-full aligncenter\" src=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145145\/Word-Press-13.png\" alt=\"\" width=\"596\" height=\"390\" srcset=\"https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145145\/Word-Press-13.png 596w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145145\/Word-Press-13-300x196.png 300w, https:\/\/s3.amazonaws.com\/static.the-next-tech.com\/wp-content\/uploads\/2020\/09\/19145145\/Word-Press-13-27x17.png 27w\" sizes=\"(max-width: 596px) 100vw, 596px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">After that, add the expiration custom field to the post. Add the time in mm\/dd\/yyyy 00:00:00 format.\u00a0<\/span><\/p>\n<h2>Conclusion<\/h2>\n<p><span style=\"font-weight: 400;\">In a nutshell, WordPress custom fields allow you to customize your posts or pages by adding additional information to them. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">By assigning different types of content to multiple custom fields, you can completely control when, where, and how to display important information. <\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Do you want to learn more about the custom fields of WordPress? Are you looking for valuable tips, tricks, and<\/p>\n","protected":false},"author":576,"featured_media":27309,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[43],"tags":[2442,248,2621,262,2630],"_links":{"self":[{"href":"https:\/\/www.the-next-tech.com\/rest\/wp\/v2\/posts\/27183"}],"collection":[{"href":"https:\/\/www.the-next-tech.com\/rest\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.the-next-tech.com\/rest\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.the-next-tech.com\/rest\/wp\/v2\/users\/576"}],"replies":[{"embeddable":true,"href":"https:\/\/www.the-next-tech.com\/rest\/wp\/v2\/comments?post=27183"}],"version-history":[{"count":6,"href":"https:\/\/www.the-next-tech.com\/rest\/wp\/v2\/posts\/27183\/revisions"}],"predecessor-version":[{"id":27338,"href":"https:\/\/www.the-next-tech.com\/rest\/wp\/v2\/posts\/27183\/revisions\/27338"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.the-next-tech.com\/rest\/wp\/v2\/media\/27309"}],"wp:attachment":[{"href":"https:\/\/www.the-next-tech.com\/rest\/wp\/v2\/media?parent=27183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.the-next-tech.com\/rest\/wp\/v2\/categories?post=27183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.the-next-tech.com\/rest\/wp\/v2\/tags?post=27183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}