Skip to main content
additional info regarding `the_title()`
Source Link
Mat
  • 1.6k
  • 1
  • 10
  • 17

If in doubt, check the documentation first: https://www.advancedcustomfields.com/resources/get_field/

Check if value exists

This example shows how to check if a value exists for a field.

$value = get_field( 'text_field' );

if ( $value ) {
    echo $value;
} else {
    echo 'empty';
}

So, in for your case you would need to use:

<?php

$short_testimonial = get_field( 'short_testimonial' );

if ( $short_testimonial ) {
    echo $short_testimonial;
} else {
    the_title();
}

?>

Also, you should note, as others have mentioned, that you don't need to echo the_title() as it echoes itself...

If in doubt, check the documentation first: https://www.advancedcustomfields.com/resources/get_field/

Check if value exists

This example shows how to check if a value exists for a field.

$value = get_field( 'text_field' );

if ( $value ) {
    echo $value;
} else {
    echo 'empty';
}

So, in for your case you would need to use:

<?php

$short_testimonial = get_field( 'short_testimonial' );

if ( $short_testimonial ) {
    echo $short_testimonial;
} else {
    the_title();
}

?>

If in doubt, check the documentation first: https://www.advancedcustomfields.com/resources/get_field/

Check if value exists

This example shows how to check if a value exists for a field.

$value = get_field( 'text_field' );

if ( $value ) {
    echo $value;
} else {
    echo 'empty';
}

So, in for your case you would need to use:

<?php

$short_testimonial = get_field( 'short_testimonial' );

if ( $short_testimonial ) {
    echo $short_testimonial;
} else {
    the_title();
}

?>

Also, you should note, as others have mentioned, that you don't need to echo the_title() as it echoes itself...

Source Link
Mat
  • 1.6k
  • 1
  • 10
  • 17

If in doubt, check the documentation first: https://www.advancedcustomfields.com/resources/get_field/

Check if value exists

This example shows how to check if a value exists for a field.

$value = get_field( 'text_field' );

if ( $value ) {
    echo $value;
} else {
    echo 'empty';
}

So, in for your case you would need to use:

<?php

$short_testimonial = get_field( 'short_testimonial' );

if ( $short_testimonial ) {
    echo $short_testimonial;
} else {
    the_title();
}

?>