I developed some wordpress plugins and custom themes clients. Best options is create custom option for wordpress theme is use wordpress api.

There are currently a some methods to create settings pages. You can create the entire form, or you can create sections and fields using the API. Each option, however, utilizes get_option() function which is provide by wordpress.

<?php echo get_option( $show, $default ); ?>

<h1><?php echo get_option('blogname'); ?></h1>

You can use the add option method which is so useful for creating the plugin or themes

<?php add_option($name, $value = '', $deprecated = '', $autoload = 'yes'); ?>

Example

<?php add_option("myhack_extraction_length", '255',
'Max length of extracted text in characters.', 'yes'); ?>

Update option is another useful function provided by wordpress

Usages

<?php update_option( $option_name, $newvalue ); ?>

Example

<?php
$option_name = 'myhack_extraction_length' ;
$newvalue = '255' ;
if ( get_option($option_name)  != $newvalue) {
update_option($option_name, $newvalue);
} else {
$deprecated=' ';
$autoload='no';
add_option($option_name, $newvalue, $deprecated, $autoload);
}
?>

Use above three function/methods, that are so useful for creating the plugins or themes.

Leave a Comment

Your email address will not be published. Required fields are marked *