Escaping Custom Meta Data And Prefixing Custom Meta ID

wordpress
themeforest

#1

Hi There,
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:

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

N. B. I have been developing a one page WordPress theme.

Thanks in advance. :slight_smile:


#2

Use esc_url() or esc_url_raw() for Links.
What you’ve done is correct.