I want to check if Yoast SEO is installed in WordPress. I have activated Yoast SEO in my Test Environment, but it’s not working out.
In the wp-seo-main.php of Yoast, there’s this line on line 16:
define( 'WPSEO_VERSION', '3.4' );
So I thought, that’s a good line to check if Yoast is installed and running, so I did:
if ( defined( 'WPSEO_VERSION' ) ) {
echo '<script>alert("Yes, defined");</script>';
} else {
echo '<script>alert("No, undefined");</script>';
}
But it gives me “No, undefined”. How weird, because it should be defined.
Anyone got an idea? I’m totally out of ideas.
7
Answers
Or without extra inclusions, front end or back end:
Works with any plugin, just look into your plugins folder for your target:
plugin-folder/plugin-index-name.php
where the latter shuld resident the Plugin details at the top inside the file.Please Check Doc. reference
Inspired by Jonas Lundman’s answer I wrote this to handle also when Yoast premium is active.
Use below code:
This is what worked for me.
Thanks to all the others for doing a good job so far! But the question is also about a check if a plugin is installed and all your answers are only about checking if a plugin is active.
So I went to my playground and developed a correct check I want to show you by using functions WP already provided.
As you can see I’ve wrote two separate functions to check if
Yoast SEO
is installed and active so I just need to call it and check the return param:But if you want to skip this two extra functions, you can call the two check functions directly:
I hope this helps you to do a good installed & active check!
Check this, to get all active plugin names;