最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论