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;
  },1);

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

but the wp_head always seems to execute after the do_shortcode_tag filter

help!

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


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: