admin管理员组

文章数量:1203187

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 2 years ago.

Improve this question

I'm writing a custom Wordpress theme and for a specific page I need to overwrite its meta-tags (printed by YoastSEO) with the meta-tags of another page I already know the ID of. I cannot just change the original page meta-tags because the replacement changes based off a custom field in the page.

I've tried this, but apparently wp_head() is unaffected by the_post()...

    <head>
    ...
    <?php
    if (...)
    {
        $meta_page = new WP_Query([ 'page_id' => $meta_page_id ]);
        while ( $meta_page->have_posts() )
        {
            $meta_page->the_post();
            wp_head();
        }
        wp_reset_postdata();
    }
    else wp_head() ?>
    ...
    </head>

Hope it's clear enough; first question here.
Thanks in advance.

本文标签: wp queryOverwrite YoastSEO metatags with another page39s