Q:

How to Escape Custom Meta Data And Prefix Custom Meta ID

Here is a code snippet where I tried to retrieve a custom meta data from a custom post type.
$p_client_link = get_post_meta( $post->ID, 'client_link', true );
<a href="<?php echo esc_url( $p_client_link); ?>"><?php the_post_thumbnail( 'client_logo' ); ?></a>

My queries are:

Q. esc_url( $p_client_link); ==  right/wrong? esc_url() or esc_attr()?
Q. custom meta id client_link. Is it necessary to add prefix with this custom meta id like ‘p_client_link’?
Q. Is it right to use esc_url() for any ‘href’ attribute value?

N. B. I have been developing a one page WordPress theme for themeforest submission.
Thanks in advance. :)

A:

esc_url() - The correct option. He will prepare a string for use in attributes. Doc: https://developer.wordpress.org/reference/functions/esc_url/
Adding a prefix is correct. You will secure your variables from overriding with other plug-ins.
yes

