WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating my first ever plugin, its purpose is to show a notice when some conditions are met, I created the function in jQuery and initially I had to manually edit the file everytime I wanted to change the notice message, so I decided to create a settings page so that the user could edit the message from the front end.

Thanks to another member on stackxchange I was able to use wp localize to show the custom message saved in the wp options instead. however, I now find my self having to structure the message being shown such as;




I don't want to create many options so I thought I could try and serialize the data but I dont know how to.

In the settings page I have a single textbox for the user to enter the message.

<textarea name="msg_data" id="msg_data" cols="40" rows="10" />
<?php echo get_option('notice_data'); ?>

Here is the localize

$custom_notice = get_option('notice_data', 'default_value');
  wp_localize_script( 'lu_ban', 'custom_notice', $custom_notice);

My goal is to create three different inputs, one for title, one for body message and one for image path, can anyone help me out please.


share|improve this question
Like this? – toscho Jul 11 '13 at 1:38
Thanks for the link, I am going to have a look – Jose David Garcia Llanos Jul 11 '13 at 1:42

To store Data use this Code : save the serialize values

$title    = 'Your Title Value';
$message  = 'Your message HTML..';
$image    = 'http://www.domain.com/yourimage.jpg';

$notice_data = array('title'   => $title, 
                     'message' => $message,
                     'image'   => $image

if(get_option('notice_data') === FALSE){
    add_option('notice_data',  $notice_data );
    update_option('notice_data', $notice_data );

Now you can get the serialize values and use in your code

$notice_data =   get_option('notice_data')  ;  

echo $notice_data['title'];

share|improve this answer
add/update option serializes data automatically, all you need to do is pass an array. using serialize/unserialize here is redundant. – Milo Jul 11 '13 at 5:09
Yes that's TRUE. – Shahinul Islam Jul 11 '13 at 5:14
@ShahinulIslam please update you answer, remove serialize/unserialize – Ravinder Kumar Jul 11 '13 at 7:17
My serialized data looks like a:2:{s:5:"Title";s:11:"custom message";s:7:"Message";s:20:"Hello testing testing";} how do I now return it to a form, I tried <?php echo get_option('notice_data[Title]'); ?> but it doesnt work – Jose David Garcia Llanos Jul 11 '13 at 17:16
Jose David Garcia Llanos - you can unserialize($notice_data) to make that serialize data into array. I update the answer. – Shahinul Islam Jul 11 '13 at 20:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.