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. 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. :)

1 Answer 1

  1. esc_url() - The correct option. He will prepare a string for use in attributes. Doc: https://developer.wordpress.org/reference/functions/esc_url/

  2. Adding a prefix is correct. You will secure your variables from overriding with other plug-ins.

  3. yes

  • Thanks much @TrubinE :) . As for 2 no., actually I would like to know about the meta id which we use in the admin panel, not the variable I took. ( $post->ID, 'client_link', true). This is the id 'client_link'. Thanks again :) Mar 20, 2017 at 15:40
  • I meant that id should be unique, the prefix to us in this helps
    – TrubinE
    Mar 20, 2017 at 16:39

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.