0

I am trying to hook a function to wp_head that adds some meta tags, but I does not work correctly. Here is my code:

add_action( 'wp_head', 'add_meta_tags' , 2, 1 );
do_action('add_meta_tags',$pick_data);
function add_meta_tags($pick_data) {
    $h=$pick_data[0]->h_team;
    $a=$pick_data[0]->a_team;
    echo '<meta property="og:title" content="'.$h.' vs '.$a.'" />' . "\n";


}

The function is executed, but the parameter ($pick_data) is not passed. So I am getting in my head:

<meta property="og:title" content=" vs " />

What am i doing wrong?

4

Please check also wp-includes/general-templates.php but wp_head() hooks 'wp_head' like this:

function wp_head() {
    do_action( 'wp_head' );
}

So I would change your code like this for example:

add_action( 'wp_head', 'my_prepare_pick_data' );
add_action( 'my_add_meta_tags', 'my_add_meta_tags' );

function my_prepare_pick_data() {
    $pick_data = new YourPickDataClass(); // change this as you like
    do_action( 'my_add_meta_tags', $pick_data );
}

function my_add_meta_tags( $pick_data ) {
    $h = $pick_data[0]->h_team;
    $a = $pick_data[0]->a_team;
    echo '<meta property="og:title" content="', $h, ' vs ', $a, '" />', "\n";
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.