I want the conditional to be applied and that it is only displayed on pages, but it does not work, what is wrong?
function luc_add_cutom_fields_to_content( $content ) {
$custom_fields = get_post_custom();
$content .= "<div class='cta-div'>";
if( isset( $custom_fields['luc_name'] ) ) {
$content .= '<h3> '. $custom_fields['luc_name'][0] . '</h3>';
}
if( isset( $custom_fields['luc_description'] ) ) {
$content .= '<p> ' . $custom_fields['luc_description'][0] . '</p>';
}
if( isset( $custom_fields['luc_action'] ) ) {
$content .= '<a href=" ' . $custom_fields['luc_link'][0] . ' ">' . $custom_fields['luc_action'][0] . '</a>';
}
$content .= '</div>';
return $content;
}
if( is_page() ) {
add_filter( 'the_content', 'luc_add_cutom_fields_to_content' );
}
is_page()
too early while not ready yet. Use thisadd_filter( 'the_content', function($c){ return is_page() ? luc_add_cutom_fields_to_content($c) : $c; });