WordPress© allows you to customize many of its features. Most can be changed on-the-fly by changing the settings in wp-admin, the WordPress administration console. So, if you want your own custom features that effect text or images on your pages, you can add these features by implementing WordPress Custom Fields.
Implementation
- Make sure your page is using one of the templates in your theme by editing your page in wp-admin and selecting a template under Page Attributes.
- Create your custom fields by editing your page in wp-admin and adding new custom fields under the Custom Fields section.
- Edit the template to display custom fields by replacing your targeted text or image with:
get_post_meta($post->ID, 'YourCustomFieldNameHere', TRUE);
Now, all you need to do to make a change is modify the value for that Custom Field.
Text Example
Let’s say you have a blog about job hunting and somewhere on your home page you provide a tip that you change on a daily basis. Here’s the code in the template:
My Tip of the Day ~
<span>At least a day before your interview, drive to the location of your interview so you know where it is and you can determine the time it will take to get there.</span>
Here’s all you have to do:
- Ensure your home page is using a template. If not, go back to step #1 of Implementation above.
- Create a custom field called “Tip_of_the_Day”. The initial value should be “At least a day before your interview, drive to the location of your interview so you know where it is and you can determine the time it will take to get there.” without the quotes.
- Edit the code in the template to:
My Tip of the Day ~ <span><?php echo get_post_meta($post->ID, 'Tip_of_the_Day', TRUE); ?></span>
- The next day, change the value of Tip_of_the_Day to the new Tip.
You’re done!!!
Image Example
The steps to change an image are the same as the Text Example. Let’s say you have a background image on the home page that you prefer to change periodically so the site is fresh for your customers. Here’s the code in the template:
<img src="blue_large_background.gif" />
After you’ve created your custom field named “Background_Image” with a value of blue_large_background.gif, change the code to:
<img src="<?php echo get_post_meta($post->ID, 'Background_Image', TRUE); ?>" />
Now, when you want to freshen up your home page, just change the value of your custom field!