Add WordPress Meta box and Use Its Value on Front End Posts

What will We Get:

  1. Adding WordPress meta box function to create a input meta box for all post in a WordPress theme to get a hyperlink value and save it
  2. Using the meta box value in all posts to display hyperlink saved by meta box.

What will We Use

WordPress, CSS, HTML, PHP

How to Implement in WordPress

Adding meta boxes can be divided into three parts

  1. Adding Meta box to Post types
  2. Function to display forms fields on the posts
  3. Saving Meta box value
  4. Using saved meta box values

1. Adding Meta Box to Post Types

Following function will be added to function.php file of your WordPress which will add a meta box to all post types in your WordPress.



2. Function to display forms fields on the posts

This function will add form field to post edit screen where you will add the value to the meta box. This function should be added to function.php file.


ID, “meta-box-text”, true); ?>”> 


3. Saving Meta box value

Following function will do several things. It is responsible to check multiple validations before saving the values. These checks ensures that value saved correctly. after checking necessary conditions this function will save the values to WordPress database. This function also should be added to function.php file.
function save_custom_meta_box($post_id, $post, $update)
//Launch Multi check for validation and security

if (!isset($_POST["meta-box-nonce”]) || !wp_verify_nonce($_POST[["meta-box-nonce”](__FILE__)))
return $post_id;

if(!current_user_can(“edit_post”, $post_id))
return $post_id;

return $post_id;

if ( is_multisite() && ms_is_switched() ) {
return $post_id;

$slug = “post”;
if($slug != $post->post_type)
return $post_id;

// Update Values

// check that user added some value to Text box then save or update it
if(isset($_POST[“["meta-box-text”]r> {
$meta_box_text_value = $_POST[“me["meta-box-text”]update_post_meta($post_id, “meta-box-text”, $meta_box_text_value);


add_action(“save_post”, “save_custom_meta_box”, 10, 3);

[/php]4. Using saved meta box values

This is the last piece of code of our sample. Here we will retrieve the saved meta box value and use it. We can use this value for any purpose needed for our project. In this example you can write below code to your custom page template or post template single.php to display saved meta box value to show saved Download Link.
[php] //check if link is empty then do nothing

Download Link


Spread the love



  1. liga 1 indonesia - November 16, 2018 at 12:32 pm

    I love your blog.. very nice colors theme. Did you design this website yourself or did you hire
    someone to do it for you? Plz respond as I’m looking to design my own blog and would like to find out where u got this from. cheers.

  2. https://masakandananekakue.blogspot.com - November 18, 2018 at 2:19 pm

    I believe what you wrote made a bunch of sense. However, think about this, suppose you wrote a catchier post title? I am not suggesting your information is not solid., but suppose you added something that makes people want more? I mean Home – ULook Webdesign is kinda vanilla. You ought to look at Yahoo’s home page and watch how they create article headlines to get people
    to open the links. You might add a video or a related pic or two to get people excited about everything’ve written. In my opinion, it would bring your posts a little livelier.

  3. https://truoctran.com/chu-tich-la-liga-keu-goi-uefa-trung-phat-man-city-va-psg - November 20, 2018 at 11:51 am

    Hі colleagues, іts fantastic piece οf writing οn the topic of educationand fullʏ explained, keep іt up all thе tіme.

  4. lawyers in marbella - November 20, 2018 at 2:14 pm

    Appreciate the recommendation. Let me try it out.

Leave a Reply

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

Go to Top