8

I'm trying to render meta, icons, and app store code in the head from my plugin, but it got rejected by the WordPress plugin review team:

Please use wp_enqueue commands

This is what I'm trying to add:

add_action('wp_head', array(&$this, 'add_meta'));

public function add_meta() {
    global $post;

    $url = $_SERVER['HTTP_HOST'] . rtrim($_SERVER['REQUEST_URI'], '/');

    // Smart App Banner for Safari and iOS
    echo '<meta name="apple-itunes-app" content="app-id=' . $this->getOption('iOSID') . ', app-argument=' . 'http://' . $url . '">';

    // Google App Indexing
    echo '<link rel="alternate" href="android-app://' . $this->getOption('AndroidID') . '/' . 'http/' . $url . '" />';
    echo '<link rel="alternate" href="ios-app://' . $this->getOption('iOSID') . '/' . 'http/' . $url . '" />';

    // App Icons
    echo '<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">';
    echo '<link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192">';
    echo '<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">';
    echo '<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">';
    echo '<link rel="manifest" href="/manifest.json">';
    echo '<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">';
    echo '<meta name="msapplication-TileColor" content="#da532c">';
    echo '<meta name="msapplication-TileImage" content="/mstile-144x144.png">';
}

However, I don't see a way these special link and meta tags can be done with wp_enqueue_style. What's the correct "WordPress" way of doing this from a plugin?

TruMan1
  • 33,665
  • 59
  • 184
  • 335
  • I would probably ask the WordPress review team.. you could say, "I'm trying to do what `wp_site_icon()` is doing, which is (also) hooked to `wp_head`. So what's wrong with my code?"... well you get the idea. – Sally CJ May 31 '18 at 02:21
  • I don't understand why it was rejected, that's how WP itself prints `` and `` tags... Is that all the code you're using in `wp_head` action hook? I've checked WP base code and that's about it, there's no special enqueue... – brasofilo May 31 '18 at 04:22
  • are you creating a class for it? – Rajkumar Gour Jun 06 '18 at 04:58

3 Answers3

0

It depends on which kind of content you want to include in .

Scripts and styles need to be registered and/or enqueued using the proper WP functions:

  • wp_enqueue_script()

  • wp_enqueue_style()

Any other type of content can be hooked up using the wp_head action hook:

function hook_metacontent() {
    echo '<meta name="apple-itunes-app" content="app-id=' . $this->getOption('iOSID') . ', app-argument=' . 'http://' . $url . '">';

    // Google App Indexing
echo '<link rel="alternate" href="android-app://' . $this->getOption('AndroidID') . '/' . 'http/' . $url . '" />';
    echo '<link rel="alternate" href="ios-app://' . $this->getOption('iOSID') . '/' . 'http/' . $url . '" />';

    // App Icons
    echo '<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">';
    echo '<link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192">';
    echo '<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">';
    echo '<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">';
    echo '<link rel="manifest" href="/manifest.json">';
    echo '<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">';
    echo '<meta name="msapplication-TileColor" content="#da532c">';
    echo '<meta name="msapplication-TileImage" content="/mstile-144x144.png">';
}
add_action('wp_head', ‘hook_metacontent');
patilnitin
  • 1,151
  • 10
  • 14
0

What's the correct "WordPress" way of doing this from a plugin?

The correct WordPress hook you're looking is specifically wp_head for hooking the meta data, as like this:

add_action( 'wp_head', 'add_meta' );

function add_meta() {

    // Post object if needed
    global $post;

    // Page conditional if needed
    if( is_page() ){}

    ?>

        <meta name="someName" content="someContent" />

    <?php

}

Note: If you need to remove a default hook, this file will give you the priority for which to use to remove the hook.

0

What's the correct "WordPress" way of doing this from a plugin?

You already did it the right way. If the WordPress review team said or says it's not, then ask them why — or even how exactly you should code the function. =)

Nonetheless, you might want to check this out: https://stackoverflow.com/a/8086420/9694859