add to head element based on shortcode contents

Trying to write a plugin that adds to head element based on generated page contents.

A shortcut generates pagination, based on which I have to add a <link rel="next" .. attribute to . Unable to do so because the wp_head action executes after the do_shortcode_tag filter and there doesn’t seem to a filter for modifying head elements..

This is what I have tried.

  add_filter('do_shortcode_tag', function ($content) {
     global $nextLink ;
     $nextLink  = 'somelink.html' ; // calculated using $content
     var_dump($nextLink);  // correc link
     return $content;

add_action('wp_head', function () {
    global $nextLink ;
    var_dump($nextLink); // is null
    echo '<link rel="next" href="' . $nextLink . '" />';

but the wp_head always seems to execute after the do_shortcode_tag filter


Read more here: add to head element based on shortcode contents

Leave a Reply

Your email address will not be published. Required fields are marked *