Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8669573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:30:27+00:00 2026-06-12T18:30:27+00:00

I have a php implode function to list wordpress custom field keys which works

  • 0

I have a php implode function to list wordpress custom field keys which works great. The problem is I need to wrap the web urls in an href to make them clickable and can’t wrap my head around the function sytnax. The key value is in this format http://www.site.com, so I had it set up for a single entry like so:

<?php if(get_post_meta($post->ID, 'website', true)): ?>
    <strong>Website:</strong> <a href="http://<?php echo get_post_meta($post->ID, 'website', true); ?>" target="_blank"><?php echo get_post_meta($post->ID, 'website', true); ?></a>
<?php endif; ?>

but now we need to be able to hold multiple entries separated by a comma. Here is the code that works, but does not output a clickable url:

<?php
if( $website = get_post_meta($post->ID, 'website') ):
    $label = count( $website ) > 1 ? 'Websites' : 'Website';
    ?>
    <strong><?php echo $label; ?>:</strong> <?php echo implode( $website, ', ' ); ?><br />
    <?php
endif;
?>

This is what I’ve been playing with, which is clearly wrong

<?php echo '<a href="http://' . implode('" target="_blank">', $website) . "</a>" . ', '; ?><br />

Even if it did work, it would only output the url, not the text that is linked.

——————— EDIT ————————-

Kai’s answer was closest, so I marked it the answer, but it didn’t include the label variable. By marrying two of them I came up with this answer which works beautifully

<?php
    if( $website = get_post_meta($post->ID, 'website') ):
        $label = count( $website ) > 1 ? 'Websites' : 'Website';
        $links = array_map(
            function($url) {
                 $url = htmlspecialchars($url);
                 return sprintf ('<a href="http://%s">%s</a>', $url, $url);
            },
            $website);
        ?>
        <strong><?php echo $label; ?>:</strong> <?php echo implode(', ', $links); ?><br />
<?php endif ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:30:28+00:00Added an answer on June 12, 2026 at 6:30 pm

    You could seriously abuse implode in a manner similar to what you have tried yourself and make it work, but that’s really not a good idea.

    What you want is to move from a list of URLs to a list of anchor tags, which is possible with array_map:

    if ($website = get_post_meta($post->ID, 'website')) {
        $links = array_map(
            function($url) {
                 $url = htmlspecialchars($url);
                 return sprintf ('<a href="http://%s">%s</a>', $url, $url);
            },
            $website);
    
        echo implode(', ', $links);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following PHP function which will list the users from a MySql
I have the current PHP: $thisarray[] = #000; SetProfileField('usercss', $USER->id, implode(',',$thisarray)); Which writes #000
I have PHP function which checks to see if variables are set and then
I've been using implode function of php and suddenly I encounter a problem regarding
I have a wordpress page which has two loops like so... <?php global $post;
I have PHP script works without problems, like this : while($row4 = mysql_fetch_array($result4)) {
I'm building a custom WordPress theme and have a quick question regarding WordPress and
I have a problem regarding display PHP code (stored in a database) on a
I have a php MySql booking calendar, which shows whether the room is booked
As service provider has given me the following php code, which I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.