For Multisite user website and for the customization for your client website, you have to make some modification in the WordPress core file, especiaaly modification and customization with Custom fields. Today we are comling a list of excellent resources for the utilization of custom field along with a list of tips and trick for its usages, so you can extend the features of WordPress powered websites for your clients and users.
WordPress Custom Fields Tutorials, Tips and Tricks
There are limitless features which you can get from WordPress Custom fields by using WordPress Plugins or through customizing your themes file like WordPress frameworks: Theme frameworks extend the WordPress platform in a way that lets designers streamline additional features and functionality for their themes. Following are the best themes provider for Custom fields: Genesis Framework, Themify, upthemes, iThemeBuilder. There are lots of themes which can enhance the utilizing the custom fields for single post for customers and for multi-site users according to the requirements as follows:
Adding Custom Fields for User Profiles
You can add this custom field by using user_contactmethods filter and change it as you need it, add following piece of code in your theme’s function.php file as I have tried it in U-Design WordPress Theme:
// adding custom fields to WP user profile function wparena_profiles( $contactmethods ) { // Add Twitter $contactmethods['blog_title'] = 'Blog Title'; // Add Google profile $contactmethods['google'] = 'Google+ URL'; // Add Twitter $contactmethods['twitter'] = 'Twitter ID'; //add Facebook $contactmethods['facebook'] = 'Facebook Profile URL'; return $contactmethods; } add_filter('user_contactmethods','wparena_profiles',10,1); // end of adding custom fields to WP user profile
Source: Adding Custom Fields in WordPress User Profiles – Tip for Multi-Authors Blogs
How to: Set post expiration date/time on your WordPress blog
Do you regret that WordPress haven’t a feature to publish a post during only 2 days, or one week? Here is a very nice code that you can use in your WordPress theme, to enable the possibility of creating post expiration based on date and time.
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> $expirationtime = get_post_custom_values('expiration'); if (is_array($expirationtime)) { $expirestring = implode($expirationtime); } $secondsbetween = strtotime($expirestring)-time(); if ( $secondsbetween > 0 ) { // For exemple... the_title(); the_excerpt(); } endwhile; endif; ?>
Source: How to: Set a post’s expiration date and time on your WordPress blog
How to: Manually define to show full post or excerpt on your homepage
Do you use excerpts or full posts on your blog excerpts? Personnally, I think they’re both good. The only problem is that you can’t, by default, use both excerpts and full posts on your blog homepage. Here’s a code to do it.
On your index.php file, replace your current loop by this one:
<?php if (have_posts()) : while (have_posts()) : the_post(); $customField = get_post_custom_values("full"); if (isset($customField[0])) { //Custom field is set, display a full post the_title(); the_content(); } else { // No custom field set, let's display an excerpt the_title(); the_excerpt(); endwhile; endif; ?>
Source: How to: Manually define whether to show full posts or excerpts on your home page
Display the Digg Button only when the custom field is present
<?php // check for digg button for single page $digg = get_post_meta($post->ID, 'Digg', $single = true); // if there's a single page digg button if($digg !== '') { ?> <script type="text/javascript"> (function() { var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0]; s.type = 'text/javascript'; s.async = true; s.src = 'http://widgets.digg.com/buttons.js'; s1.parentNode.insertBefore(s, s1); })(); </script> <a></a> <?php } // end if statement // if there's not a digg button else { echo ''; } ?>
Source: How to Add a Digg Button Using Custom Fields
How to: Display your current mood on your posts
Open your single.php file (You can also modify your index.php file) and paste the following code anywhere within the loop:
$customField = get_post_custom_values("mood"); if (isset($customField[0])) { echo "Mood: ".$customField[0];
Source: How to: Display your current mood on your posts
Add Meta Descriptions To Your Posts
Open your header.php file. Paste the following code anywhere within the <head> and </head> tags:
<meta name="description" content=" <?php if ( (is_home()) || (is_front_page()) ) { echo ('Your main description goes here'); } elseif(is_category()) { echo category_description(); } elseif(is_tag()) { echo '-tag archive page for this blog' . single_tag_title(); } elseif(is_month()) { echo 'archive page for this blog' . the_time('F, Y'); } else { echo get_post_meta($post->ID, "Metadescription", true); }?>">
Sources: Unique meta description and meta keyword tags in your WordPress themes
How to: Link to some external ressource in post title
The first thing to do is to open your functions.php file and paste the following code:
function print_post_title() { global $post; $thePostID = $post->ID; $post_id = get_post($thePostID); $title = $post_id->post_title; $perm = get_permalink($post_id); $post_keys = array(); $post_val = array(); $post_keys = get_post_custom_keys($thePostID); if (!empty($post_keys)) { foreach ($post_keys as $pkey) { if ($pkey=='url1' || $pkey=='title_url' || $pkey=='url_title') { $post_val = get_post_custom_values($pkey); } } if (empty($post_val)) { $link = $perm; } else { $link = $post_val[0]; } } else { $link = $perm; } echo '<h2><a href="'.$link.'" rel="bookmark" title="'.$title.'">'.$title.'</a></h2>'; }
Once done, open your index.php file and replace the standard code for printing titles:
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
by a call to our newly created print_post_title() function:
<?php print_post_title() ?>
Now, whenever you feel like let your post title leave your blog and point someplace else, just scroll down in your post writing screen, create or select a custom key named url1 or title_url or url_titleand put that external URL in value box.
Sources: Hacking WordPress theme: external URL for post title
How to: Link to an external resource in the post’s title
How to: Embed CSS in your posts with a custom field
open your header.php file and insert the following code between the <head> and </head> html tags:
<?php if (is_single()) { $css = get_post_meta($post->ID, 'css', true); if (!empty($css)) { ?> <style type="text/css"> <?php echo $css; ?> </style> <?php } } ?>
Source: How to: Embed CSS in your posts with a custom field
How to: Redifine title tag with a custom field
Open your header.php file for edition. find the <title> tag, and replace it by the following code:
<title> <?php if (is_home () ) { bloginfo('name'); } elseif ( is_category() ) { single_cat_title(); echo ' - ' ; bloginfo('name'); } elseif (is_single() ) { $customField = get_post_custom_values("title"); if (isset($customField[0])) { echo $customField[0]; } else { single_post_title(); } } elseif (is_page() ) { bloginfo('name'); echo ': '; single_post_title(); } else { wp_title('',true); } ?> </title>
Source: How to: Redefine the title tag with a custom field
Disable Search Engine Indexing For Individual Posts
To achieve, first get the ID of the post you’d like to be not indexed by search engines. In this exemple, I assume your post id is 17.
Open your header.php file and paste the following code between the <head> and </head> tags:
<?php if ($post->ID == 17) { echo '<meta name="robots" content="noindex">'; }
Source: How to: disable search engine indexing of a single post
How to: Easily get the value of a custom field
You have to paste it on your theme functions.php file. If your theme doesn’t have a file named functions.php, create one.
function get_custom_field_value($szKey, $bPrint = false) { global $post; $szValue = get_post_meta($post->ID, $szKey, true); if ( $bPrint == false ) return $szValue; else echo $szValue; }
Now, to call the function and get your custom field value, use the following code:
<?php if ( function_exists('get_custom_field_value') ){ get_custom_field_value('featured_image', true); } ?>
First, we use the php function_exists() function to make sure the get_custom_field_value function is defined on our theme. If it is, we use it. The first argument is the custom field name (here,featured_image) and the second let you echo the value (true) or get it for further use in php (false).
Sources: Useful custom functions for WordPress
How to: Easily get the value of a custom field
Rewrite Guest Author’s name with Custom Fields
Open your functions.php file and paste the codes below
add_filter( 'the_author', 'guest_author_name' ); add_filter( 'get_the_author_display_name', 'guest_author_name' ); function guest_author_name( $name ) { global $post; $author = get_post_meta( $post->ID, 'guest-author', true ); if ( $author ) $name = $author; return $name; }
Source: How to rewrite Guest Author Name with Custom Fields in WordPress
Display Custom Fields Outside the Loop in WordPress
All you have to do is display the custom fields like this:
<?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid, 'Your-Custom-Field', true); wp_reset_query(); ?>
Source: How to Display Custom Fields outside the loop in WordPress
You will need to open your single.php or page.php file and find the following code:
<?php get_sidebar(); ?>
Replace it with the following:
<?php global $wp_query; $postid = $wp_query->post->ID; $sidebar = get_post_meta($postid, "sidebar", true); get_sidebar($sidebar); wp_reset_query(); ?>
Source: Display Different Sidebar for Each WordPress Post
Manipulating the RSS feed content with Custom Fields
Did you ever want to add a specific content just for your RSS readers in a specific post? Well this can also be done with custom fields. In this first example, we will show you how you can use custom field to display specific text/object in your WordPress RSS Feed. This trick will allow you to show different text, advertisement, image, or anything else for each post.
Source: Completely Manipulate Your WordPress RSS Feeds
WordPress, add content to its RSS feed!
More Custom Field Tutorials and Hacks
Following are the list of useful resources that unveil the power of WordPress Custom Fields and you can find them very helpful to extend the Website features.
How to use WordPress Custom Fields
WordPress gives an author the ability to add extra data to each written post and page. This data is called meta-dataand is stored in custom fields.
Using WordPress Custom Fields: Introduction
This tutorial series will cover more advanced uses later in the series. Mostly, he covered what he thought practical uses of custom fields.
Add Thumbnails to WordPress with Custom Fields
You can find detailed article about how to add Thumbnails with custom fields to your WordPress post. Gave you detail about what is Custom field and how to use it to display Custom Thumbnails to particular post.
Using WordPress Custom Fields
WordPress has the ability to allow post authors to assign custom fields to a post. This arbitrary extra information is known as meta-data. This meta-data can include bits of information such as:
- Mood: Happy
- Currently Reading: Cinderella
- Listening To: Rock Around the Clock
- Weather: Hot and humid
With some extra coding, it is possible to achieve more complex actions, such as using the metadata to store an expiration date for a post.
A Tutorial on WordPress Custom Field
In this article, writer review how easy it is to customize the background color, image and article title color of a particular blog entry by using custom field tags.
WordPress Custom Fields, Part I: The Basics
Write have shared some delicious tips and tricks to help you get the most out of everything that custom fields have to offer.
WordPress Custom Fields, Part II: Tips and Tricks
In this follow-up article, writer have reviewed the basics of custom fields and then jump into a few custom-field tips and tricks.
An Easy Way to Get the Contents of a Custom Field
you do any hardcore WordPress coding, then you’re probably aware of Custom Fields and the unlimited possibilities they offer you as a WordPress designer or developer.
Display Inline Ads with Custom Fields and WordPress
Manually display ads to specific post with custom fields without using and WordPress Plugin.
How to Add Videos to Your WordPress Sidebar
YouTube has become a bit of a phenomenon on the Internet, and everyone’s rushing to embed videos into their blogs. This is actually a fairly neat thing, especially if you blog a lot about videos or have videos that will emphasize the importance of your posts.
WordPress Custom Fields: Listing a Series of Posts
Do you write long series of posts? Do you have a bunch of articles that definitely need to be linked together? This WordPress custom fields technique will allow you to do that without a lot of hassle. Basically, this is a simple, customized related posts script. It checks to see whether a post is in a series, then lists all the posts in the series.
In Praise of WordPress Template Tags, Part II: The Magazine Layout
Learn how you can use Custom fields to display Template tags with your post.
Creating Custom Write Panels in WordPress
How you can create custom write panel by using WordPress using custom fields.
Custom post title with lead graphic background
This tutorial’s website is offline this time but you can get access through Google Cache. The first step to setting yourself apart from the rest of the typical title + content blogs is a little style. Adding a photo or image behind a posts title can help to lure a reader into viewing the main excerpt / permalink of yourpost.
WordPress: How To Display Multiple Values of a Custom Field Key
This article shows how you can use custom fields in situations where a post may have zero, one or multiple values of the same custom code. The example used in the tutorial is quotes. Some post may have none, while others may have several.
WordPress Tip: 3 Awesome Custom Field Tricks
If you want an easy way to include default custom fields into your Write panel, try Rhymed Code’s Custom Field GUI.
Jazz Up Your Site: 28 Ways To Use WordPress Custom Fields
You may see a few ideas on here that you hadn’t thought of before that would be useful on your site or for a client project.
How to Hide Your Plugin’s Custom Fields
This tutorial shows you how to keep your plugin’s custom fields from being manually edited in the post editor. Very handy, and it keeps things nice and neat!
How to Hide Certain Custom Fields From the Edit Post Page
Post meta is easily one of the most useful features in WordPress from a developer’s perspective. Adding custom content to a post provides the ability to accomplish countless goals quickly and easily.
How to Hide a WordPress Custom Field
You can easily make WordPress check the Custom Field. If it finds the Custom Field, WordPress displays your added Value; if it doesn’t find the Custom Field, then WordPress doesn’t display anything. For example, if your Key Name reads “My Mood is__” but you don’t add the Value “Happy” The Custom Field, with the search enabled, will not post to your blog.
Custom Field GUI for WP 2.1
I have updated Custom Field GUI plugin to resolve the issue of custom fields being deleted after a comment is posted. The issue is reported after the release of WP 2.1