I am trying to create a function to add data from two custom fields after the entry title. I get it to show correctly when these fields are filled in. The fields are a image source url and an url the image has to link to.
The problem is that it's taking up space even when the custom fields are empty. My php skills are not good enough to work out how to change this. I have added a check but now the fields are not showing up at all anymore.
Hope anybody can help me out with this. What I got so far is:
//Add custom field image after entry title
function headway_title_button()
{
$check = get_post_meta($post->ID, 'titel_knop');
if( !empty( $check[""] ) )
{
return printf(
'<div class="title-btn"><a href="%s" alt="%s"><img src="%s" /></a></div>'
,get_post_meta( get_the_ID(), 'titel_knop_url', true )
,get_the_title()
,get_post_meta( get_the_ID(), 'titel_knop', true )
);
}
else
{
return printf('<div style="display:none"></div>');
}
}
add_action( 'headway_after_entry_title', 'headway_title_button' );