Skip Navigation

[Resolved] Conflict with Yoast Plugin

This thread is resolved. Here is a description of the problem and solution.

Problem: When I add the following code with Yoast active, I see a server error 500 on my site:

function add_schema_person_shortcode() {
$person_name = array_filter( array (
'givenName' => types_render_field( "schema-person-given-name", array () ),
) );
if ( ! empty( $person_name ) ) {
echo 'success';
}
}

add_shortcode( 'schema-person-shortcode', 'add_schema_person_shortcode');

Solution: Add some conditional code that prevents the function from being called before it exists:

function add_schema_person_shortcode() {
  if( function_exists( 'types_render_field' ) ){
    $person_name = array_filter(
      array (
        'givenName' => types_render_field( "schema-person-given-name", array () ),
      )
    );
    if ( ! empty( $person_name ) ) {
      echo 'success';
    }
  }
}
 
add_shortcode( 'schema-person-shortcode', 'add_schema_person_shortcode');
This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by AtefR7377 6 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#626966

Hi,
I created a very simple function to check if a custom field is empty or filled.
if it is filled, the function echos the word "success".
However, when I fill in the custom field and want to update the post, the website goes gives an error 500 instantly.

i kept investigating the problem with my server provider, but there were no problems from the server side.
then after deactivating all plugins except the WP types suite, the function worked.

I kept activating the plugins one by one, then I discovered that when i activate the Yoast plugin, the problem happens.

i tried this on 3 wordpress installations on 2 servers. all give the same result.

so my question is, are you aware of or can you think of a reason as to why the following function that has the wp types custom fields would give an error with yoast?

I sent them a support ticket too, but has not received an answer:

function add_schema_person_shortcode() {
$person_name = array_filter( array (
'givenName' => types_render_field( "schema-person-given-name", array () ),
) );
if ( ! empty( $person_name ) ) {
echo 'success';
}
}

add_shortcode( 'schema-person-shortcode', 'add_schema_person_shortcode');

#627031

It could be that the types_render_field shortcode is triggered before the function is ready. You can try adding a conditional that tests the existence of the function like this:

function add_schema_person_shortcode() {
  if( function_exists( 'types_render_field' ) ){
    $person_name = array_filter(
      array (
        'givenName' => types_render_field( "schema-person-given-name", array () ),
      )
    );
    if ( ! empty( $person_name ) ) {
      echo 'success';
    }
  }
}

add_shortcode( 'schema-person-shortcode', 'add_schema_person_shortcode');

If this does not resolve the issue, please activate server logs to get more information about the source of the 500 error. Let me know what you find out.

#628592

Thanks a lot Christian. You are a true helper. you always help me solving my problems. Very much appreciated.