• Resolved cncup

    (@cncup)


    Hi,

    Yoast SEO plugin has a filter to remove schema, that they say should be added in functions.php.

    add_filter( 'wpseo_json_ld_output', '__return_false' );

    The code is shown for completeness. The question is not about Yoast or the code. It works in functions.php. However when put in a WPCode snippet it doesn’t work. Why is that? I’m guessing it runs too late (?). I place it in the header with priority 0. Is there a way to make it run earlier?

    Or is it something else?

    Hope you can advise. Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @cncup,

    I recommend using the “Run Everywhere” location for that filter as that makes it run similarly with adding the code to functions.php.

    Thread Starter cncup

    (@cncup)

    Hi Mircea,

    Thank you for the reply.

    Yes it works in “Run Everywhere” when I also remove the condition “Type of page is Homepage”. Initially when setting the condition, the plugin changes the location automatically to “Frontend Conditional Logic”. It allows to change it back to “Run Everywhere” while the condition is still on, but apparently treats it underneath as “Frontend Conditional Logic”, hence the filter code doesn’t work as long as the condition is there.

    I can do without the condition and check in the code if it’s homepage, no problem. Just to know in general, is there a way to have the condition and also “Run Everywhere”? Not what is shown as saved but underneath truly.

    Thanks.

    Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @cncup.

    The plugin will save your snippet as Run Everywhere but the conditional logic for that will always fail as at the time when the Run Everywhere code is being executed all the details regarding the current page are not yet fully loaded.

    That is why we added the Frontend Conditional Logic location that is executed later, after all the details were loaded. Adding a condition inside the code to check if it’s the homepage will not work for the same reason unless you find a way to write the code that allows that, if possible.

    For reference, “Run Everywhere” uses the “plugins_loaded” action and the “Frontend Conditional Logic” location uses the “wp” action.

    Thread Starter cncup

    (@cncup)

    Thanks Mircea. Lucky you explained or I wouldn’t have known why my homepage check isn’t working. I resorted to using php’s $_SERVER and a check against the site url. It works.

    Thanks for the references too. Much appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Works in functions.php but not in a snippet – execution time?’ is closed to new replies.