Take a look at the WP’s template hierarchy. When a page is requested WordPress searches for the file to load in a specific order. You can create a template specific to your custom post type. You would copy the file called single.php
and name the copy single-{post_type}.php
where “post_type” is the name of your CPT. This file would then load instead of single.php
every time a single custom post type page was requested.
As for only displaying the field, you could check if it has a value in an if()
statement. When you validate the feild’s value when the post is saved you can check if the user set anything, if they did not then you should set it to something falsy like an empty string.
Then the check in the template file would look something like this:
<?php
$meta_author = get_post_meta( $post->ID, 'dublin_core_author', true);
$meta_contributor = get_post_meta( $post->ID, 'dublin_core_contributor', true);
if ($meta_author != '' && $meta_contributor != '') :
echo '<p>
Auteur: ' . $meta_author . '<br>
Contributor: ' . $meta_contributor . '<br>
</p>';
endif;
?>
<!--Other template html-->