Just created a custom field from scratch by following a tutorial. I have a field for a website link. Currently it outputs only raw text, no linking.

So how do I make this code hyperlink:

<li><strong>Website:</strong> '.$_imd_portfolio_website_output.'</li>

Full code:

function imd_portfolio_meta_box() {
    global $post;
    // get the custom field values as an array
    $values = get_post_custom( $post->ID );
    // extract the members of the $values array to their own variables (which you can see below, in the HTML code)
    extract( $values, EXTR_SKIP );

    // escape the output, just in case
    $allowed_html = array(
        'a' => array(
            'href' => array(),
            'title' => array()
        'em' => array(),
        'strong' => array()
    $_imd_portfolio_details_output = wp_kses($_imd_portfolio_details[0], $allowed_html);
    $_imd_portfolio_client_output = wp_kses($_imd_portfolio_client[0], $allowed_html);
    $_imd_portfolio_website_output = wp_kses($_imd_portfolio_website[0], $allowed_html);
    $_imd_portfolio_quote_output = wp_kses($_imd_portfolio_quote[0], $allowed_html);
    $output = '<div class="review-box">
        <ul class="review-box-list">
            <li><strong>Details:</strong> '.$_imd_portfolio_details_output.'</li>
            <li><strong>Client:</strong> '.$_imd_portfolio_client_output.'</li>
            <li><strong>Website:</strong> '.$_imd_portfolio_website_output.'</li>
    return $output;

Update: the problem is solved I've edit my code & change this line -

<li><strong>Website:</strong> '.$_imd_portfolio_website_output.'</li>

to this line-

<li><strong>Website:</strong><a href="http://'.$_imd_portfolio_website_output.'">'.$_imd_portfolio_website_output.'</a></li>

thanks everybody for help

1 Answer 1


You can do this by validating and wrapping a anchor tag. First check that in the input, which user has given any has prefix like http:// or www or not. If user has not given that then add the prefix with the input and place it at the href attribute of the anchor tag. I think it will do the work

  • can you tell me, where should I change my codes with adding the prefix? I'm still in the learning stage of PHP. here is my code: pastebin.com/kyjAs8Ba Aug 29, 2014 at 8:15
  • @user2802110 Please add your code as an edit to your question ^^ Aug 29, 2014 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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