This code is designed to add a button to specific posts using the get_post_meta
function. How do I alter the get_post_meta
function to display this button on a specific post? I have already tried changing its $post->ID
parameter to '1464', which is the post ID I want to use.
function custom_listify_single_job_listing_actions_after() {
global $post;
$url = get_post_meta( $post->ID, 'your_custom_meta_key', true );
echo '<a href="' . esc_url( $url ) . '" class="button">My Button</a>';
}
add_filter( 'listify_single_job_listing_actions_after', 'custom_listify_single_job_listing_actions_after' );
If you only want to run this code on a specific post, you need to add an if
statement to check for that post ID.
Your code would need to look similar to this:
if($post->ID == 1464){
$url = get_post_meta( $post->ID, 'your_custom_meta_key', true );
echo '<a href="' . esc_url( $url ) . '" class="button">My Button</a>';
}
This simply wraps the get_post_meta()
function and echo
statement so that both of these only run on the post you want them to. Any other post will ignore the code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.