wp query – Changing wp_head to a different post/page

The problem in short: I need to be able to replicate the experience of a post on a static page, including title and meta tags. To do this, I need to set the pages post data to the post I’m cloning. However, when I call setup_postdata before get_header, I still get the head info from the original page.

Longer: So, the reason I’m doing this is, a client wants to have a custom url structure that doesn’t include a slug or ID, but a meta value. I was able to pass these meta values to a page, but obviously still need to run the query that will pull the correct post info. I can clone the entire post, except for the dang wp_head. Is there a way to set the wp_head to use the post information from another post/page?

I’ve attempted to hook into wp_head and alter the global wp_query AND post variables, but no luck. Will the easiest way to do this be to manually recreate the head on that page not using wp_head?

php – Use wp_head hook on template page

I try to use the hook wp_head on a template page but this does not work

add_action('wp_head', 'to_head');

function to_head(){
    //do stuff

I place this code on a template part what is called by get_template_part( 'temp-parts/content/pages/catalog' );

Can you use the hook only on the functions.php or is there a way to use this on any page

javascript – Google Analytics Opt-Out Function Using wp_head + Remove Link When Clicked

The aim / goal here is to be allow the visitor to turn ON Google Analytics as opposed to turning it OFF. In other words; it should be OFF by default with the option to turn it on.

If turned on, the cookie stays active until the year 2100 or until the user him or herself removes the cookie from the browser.

The code I have does the opposite (turns the tracking OFF) and I’ve done some changes to the code in the hope of reversing it myself, but I don’t know how to make it inactive by default, allowing the user / visitor to turn it ON by choice.

I’m hoping for some insight / help on how to reverse this code and in the process, help others looking to accomplish the same.

The code I have might be incorrect or outdated and if so, please feel free to correct it. While reversing the code is one thing, the other is removing the DIV-tag (hooked into wp_head) once the cookie is set, making it “display: none” and bringing it back if the cookie does not exist.

I found this on the official GA site, but I’m not sure how to apply it so that it “runs on a global level, affecting the entire site”, but more importantly, runs before the opt-in script.

window('ga-disable-UA-XXXXXX-Y') = true;

This is the code that needs to be reversed (I’ve tried various versions without success):

add_action( 'wp_head', 'ga_opt_in', 1 );
function ga_opt_in(){   ?>

    var gaProperty = 'UA-XXX-X';
    var activateStr = 'ga-activate-' + gaProperty;
    if (document.cookie.indexOf(activatetr + '=true') > -1) {
        window(activateStr) = true;
    function GAoptIn() {
        document.cookie = activateStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
        window(activateStr) = true;

    <div class="ga-opt-in-link"><a href="javascript:GAoptIn()">Click here to turn Google Analytics Tracking ON</a></div>    

woocommerce – Get $ order at wp_head

I am trying to get the products bought in the order-received remarketing page dataLayer. The script must go in the html code section. How can i get the $order to use it in the section?

I can get the $order_id in woocommerce_thankyou but not in wp_head

tracking_thank_you_page ($ order_id) function {
<? php
add_action (& # 39; woocommerce_thankyou & # 39 ;, & # 39; tracking_thank_you_page & # 39;);

I have $order_id With the code above.

tracking_in_head function ($ order_id) {
<? php
add_action (& # 39; wp_head & # 39 ;, & # 39; tracking_in_head & # 39;);

I don't have access to $order_id in the wp_head

wp head – Get the contents of wp_head while in admin?

I'm writing an add-on that helps show a brand if the site has a noindex tag in the header.

I'm using the hook wp_head () twice like this:

                add_action (& # 39; wp_head & # 39 ;, function () {
ob_start ();
}, 0);

add_action (& # 39; wp_head & # 39 ;, function () {
$ siteHeaderOutput = ob_get_clean ();

// just one variable that I will use in a transient
$ siteHasNoIndex = "not established";

if (strpos ($ siteHeaderOutput, & # 39; noindex & # 39;)! == false) {
$ siteHasNoIndex = "without index";
} else {
$ siteHasNoIndex = "index ready";

// echo the header
echo $ siteHasNoIndex;

// then set a transient for the administration panel
set_transient (& #cash_s_index & # 39 ;, $ siteHasNoIndex, DAY_IN_SECONDS);

Right now I am using a transient to collect the header information in the administration panel to display the notice.

I'm doing this because admin_head will not render the actual site header.

I would try to use get_meta_tags (get_site_url ()) but it runs out. I think because there is a redirect caused by WP here.

Any idea if I can represent that header while I'm in the admin panel? If not, my plugin has to trust someone to visit the front end of the site so that the information is available on the server.

Thank you

php – add_action in wp_head accessible from the class

Given this code:

class test_class {

greeting function () {
echo? Howdy! The test is successful! & # 39 ;;

function greeting_head () {
// Close PHP tags
    <? php // Open PHP tags

add_action (& # 39; wp_head & # 39 ;, array (& # 39; test_class & # 39 ;, & # 39; greeting_head & # 39;));

greeting() It is undefined. How to access from the outside. proof class?

page template – Inserting an article: meta tags in html head-element, using get tags, not wp_head

I am trying to add code to a template file of mine, working with a raw theme that I generated from "". The file is a duplicate of single.php and is called single-post.php. Like the WP states in the Codex. I am trying to add my labels from my publication to the one from my pages for blog posts. I want to wrap them in the code of META tags, namely, the article: tags. Whatever you do, I keep getting the correct result, but there is no real information, no label names.

I'm not using wp_head in the template file. For custom reasons. Also, I've been trying without and with the loop present before my calls to get_tags. In addition, this is done with code that is not usable in headI know, but it does not matter, this happens no matter what I put there. You will have the goal labels later.

Basic WP code (supposedly for individual publications):

<? php

$ tags = get_tags ();
$ html = & # 39;

The title tag is still empty, title = & # 39; Label & # 39;.