Skip to content
scribu edited this page Jan 18, 2011 · 29 revisions

How can I edit custom fields?

Since custom fields can be used in so many ways, you have to make some code replacements in your theme:

Replace something like this:

<?php echo get_post_meta($post->ID, 'my_key', true); ?>

with this:

<?php editable_post_meta(get_the_ID(), 'my_key', 'textarea'); ?>

The third parameter is optional and allows you to pick which type of field you want: input, textarea or rich.

If you have a custom field with multiple values, you can use get_editable_post_meta(). For example:

<ul>
<?php
$values = get_editable_post_meta(get_the_ID(), 'my_key');
foreach ( $values as $value )
	echo '<li>' . $value . '</li>';
?>
</ul>

How can I make theme images editable?

Again, you have to modify your theme's code. Replace something like this:

<img src="<?php bloginfo('template_url'); ?>/images/header_1.jpg" width="970" height="140" alt="<?php bloginfo('name'); ?> header image 1" title="<?php bloginfo('name'); ?> header image 1" />

with this:

<?php editable_image('header-1', 
	get_bloginfo('template_url') . '/images/header_1.jpg', 
	array('width' => 970, 'height' => 140, 'alt' => get_bloginfo('name'))); 
?>

The editable_image() template tag is located in fields/other.php.