Make Input Field Output Links

So, I added an input field to one of my post types.

What I'm trying to do is put a link (,, any link) into this field, and have it output on the front end into a button.

Below is my button. I would like it to go to the link I placed on the input field when I click the button.

<a href="" id="btn-book-now" class="btn-custom"><?php  echo __('Purchase Now','Vierra'); ?></a>

Here's the code for the metabox:


add_action( 'add_meta_boxes', 'cart_meta_box_add' );  
function cart_meta_box_add() {  
    add_meta_box( 'cart-meta-box-id', 'Put cart Here!', 'cart_meta_box_cb', 'Room', 'side', 'high' );  
function cart_meta_box_cb() {
    wp_nonce_field( basename( __FILE__ ), 'cart_meta_box_nonce' );
    $value = get_post_meta(get_the_ID(), 'cart_key', true);
    $html = '<label>cart: </label><input type="text" name="cart" value="'.$value.'"/>';
    echo $html;
add_action( 'save_post', 'cart_meta_box_save' );  
function cart_meta_box_save( $post_id ){   
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; 
    if ( !isset( $_POST['cart_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['cart_meta_box_nonce'], basename( __FILE__ ) ) ) return;
    if( !current_user_can( 'edit_post' ) ) return;  
    if( isset( $_POST['cart'] ) )  
        update_post_meta( $post_id, 'cart_key', esc_attr( $_POST['cart'], $allowed ) );


Thank you for the help!


It's the same function used in the admin: get_post_meta(). Assuming the button is being printed inside the loop *:

if( $field = get_post_meta( get_the_ID(), 'cart_key', true ) ) {
    <a href="<?php echo $field; ?>" id="btn-book-now" class="btn-custom">
        <?php echo __('Purchase Now','Vierra'); ?>

* Otherwise, you'd use $post->ID instead of get_the_ID().

Tags: PHP / Html / Wordpress

Similar questions

How to make menu output links absolute
The page and post links added to WordPress menus are relative in nature. I need a way to force them to be absolute without using the "Custom Link" option. Is there some function or maybe a modifier that I can use with wp_nav_menu() to accomplish this?
Make the width of an input field relative to its content
I want to display the url of the post in each post so visitors can easy share the URL. This means that the width of the input field in which the url is placed should be relative to the width of the URL. Is it possible to make the width of an input field relative to the content (the text that is in the value="") of that input filed? So the width of ...
How to add placeholder in buddypress registration ? How to make field description as input placeholder?
How to add placeholder in buddypress registration? Can we use field description as placeholder for input field? In register.php under bp-template.These two lines of code make xprofile How to edit them.Where these lines are connected.How to edit x-profile field.
How to make Wordpress custom field input text translatable with qTranslate X?
I have some wordpress custom fields (I'm not using ACF or any other plugin for this) and need to translate them using qTranslate X in wp-admin. The fields that I created with wp_editor are working, but I don't know how to make it work with default <input type="text"> for other custom fields that I have. Below, a piece of code that I'm using t...
How to make both up/down arrow in select input field in CSS?
I am working on a website (built on Wordpress, custom theme) in which I want to add up/down arrow in the select input field in CSS. The HTML code which I am using in order to create up/down arrow for the select input field is: Here is the complete fiddle for the above code. At this moment, it has only...
How to make Gravity Forms name field input only accept letters
How do I make the gravity form name field only accept letters, numbers should give an error.

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.