$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wp head - How to add meta tags inside single image page?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp head - How to add meta tags inside single image page?

matteradmin11PV0评论

Hello im trying to add custom meta tags from facebook share button inside image.php file , and i dont know why they dont display, this is how my code looks:

        function add_facebook_image_code(){
            ?>

                <meta property="og:url"           content="/<?=$post->post_name ?>/" />
                <meta property="og:type"          content="website" />
                <meta property="og:title"         content="example - <?=$post->post_title ?>" />
                <meta property="og:image"         content="<?=$post->guid ?>" />

            <?php

        }

        add_action('wp_head', 'add_facebook_image_code');

I add this code inside image.php, is it possible to do it only inside that file ?

Thanks and best regards.

Hello im trying to add custom meta tags from facebook share button inside image.php file , and i dont know why they dont display, this is how my code looks:

        function add_facebook_image_code(){
            ?>

                <meta property="og:url"           content="http://www.example/<?=$post->post_name ?>/" />
                <meta property="og:type"          content="website" />
                <meta property="og:title"         content="example - <?=$post->post_title ?>" />
                <meta property="og:image"         content="<?=$post->guid ?>" />

            <?php

        }

        add_action('wp_head', 'add_facebook_image_code');

I add this code inside image.php, is it possible to do it only inside that file ?

Thanks and best regards.

Share Improve this question asked Jan 14, 2019 at 23:57 MariuszMariusz 234 bronze badges 1
  • Ok i fix the problem, my code was inside loop (i know it was stupid ) it should be on top of page before get_header(); – Mariusz Commented Jan 15, 2019 at 0:11
Add a comment  | 

1 Answer 1

Reset to default 0

Probably because when the execution is hitting your code is already too late to hook on wp_head.

If you want to have your code in image.php, make sure you place it before get_header().

In any case, I would move the code to functions.php or dedicated file and maybe use is_attachment() to conditionally print the meta tags.

Post a comment

comment list (0)

  1. No comments so far