I'm writing a plugin that helps show a flag if the site has a noindex tag in the header.
I'm using the wp_head() hook twice like this:
add_action('wp_head', function() {
ob_start();
}, 0);
add_action('wp_head', function() {
$siteHeaderOutput = ob_get_clean();
// just a variable that i'll be using in a transient
$siteHasNoIndex = "not set";
if (strpos($siteHeaderOutput, 'noindex') !== false) {
$siteHasNoIndex = "no index";
} else {
$siteHasNoIndex = "index ready";
}
// echo the header
echo $siteHasNoIndex;
// then set a transient for the admin panel
set_transient('escode_has_index', $siteHasNoIndex, DAY_IN_SECONDS);
}, PHP_INT_MAX);
Right now I'm doing using a transient to pick up the header information in the admin panel to display the notice.
I'm doing this because admin_head won't render the actual site header.
I'd try using the get_meta_tags(get_site_url()) but it times out -- I think because there is a redirect caused by WP here.
Any idea if I can render that header while in the admin panel? If not my plugin has to rely on someone visiting the front end of the site in order for the information to become available in the backend.
Thanks
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745319615a4622382.html
评论列表(0条)