Add Text Field Under General Settings in WordPress

In this article, i’ll try to show you the way for adding text field(s) under general settings which may help you to make dynamic control for many necessary option for WordPress site.

To Find the General Settings:

Go to Dashboard-> Settings -> General where you can see Settings Administration Screen and controls for most effective & necessary information like Site Title, Tagline, URL, Admin-email etc.

wp-general-settings

 

Now, if we want to add more settings control for our site suppose any links, or any message, or data we can make it very easily without plugin. Just need to follow few steps to do this things.

Here i am showing to add ‘copyright message’ in General Settings. So you just need a text field to do this. Please add this below code to your functions.php file:

 

 add_filter('admin_init', 'my_general_settings_register_fields'); 

function my_general_settings_register_fields() { 
register_setting('general', 'copyright_message', 'esc_attr'); 
add_settings_field('copyright_message', '<label for="copyright_message">'.__('Copyright Message' , 'copyright_message' ).'</label>' , 'my_general_copyright_message', 'general'); } 

function my_general_copyright_message() { 
$copyright_message = get_option( 'copyright_message', '' ); 
echo '<input id="copyright_message" style="width: 35%;" type="text" name="copyright_message" value="' . $copyright_message . '" />'; }

Now, you refresh your dashboard and go to Settings -> General page. You can see a text field added in bottom there. You can add your copyright message in there and click “Save changes”. To get this data in front (in footer.php) page there are two ways:

$copyrightMessage=get_settings('copyright_message');
OR
$copyright_message = get_option( 'copyright_message', '' );

Both will work. Just pick any suitable one and print the variable $copyrightMessage in your html.

That’s it. If you need any further clarification please drop a comments.

Thanks.

This post has already been read 7264 times!

Mehedi Hasan

Cool WordPress Developer having much agile experience to develop any kind of WordPress sites & plugins. Also good in troubleshooting, fixing & making any kind of tweaks for WP site.

More Posts

Mehedi Hasan

Cool WordPress Developer having much agile experience to develop any kind of WordPress sites & plugins. Also good in troubleshooting, fixing & making any kind of tweaks for WP site.