wp head - Getting the contents of wp_head while in admin?

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

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

相关推荐

  • wp head - Getting the contents of wp_head while in admin?

    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

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信