I am trying to add some meta-tag when shortcode [refresh url='http://stackoverflow.com']
tag is used.
I have done below code, but it is not working, I want to inject HTML code between "<head>
" tag only when the shortcode is used.
<?php
/*
* Plugin Name: Plugin
* Description: Plugin
* Version: 1.0
* Author: yolo yolo
* Author URI: https://example.com
*/
$url = '';
function metaRefresh( $atts = array() ) {
extract(shortcode_atts(array(
'url' => 'https://example.com',
), $atts));
return true;
}
add_shortcode('refresh', 'metaRefresh');
add_action('wp_head', 'injectHead', $url);
function injectHead($url){
?>
<meta http-equiv="refresh" content="<?php echo $url; ?>">
<?php
}
?>
post_content
, so this approach isn't possible.wp_head()
has already finished running. It looks like you're trying to allow editors to enter a redirect; you could set up custom postmeta with a URL input, and in the theme'sheader.php
file inside the<head>
you can have a conditional - if that postmeta isn't empty, output the meta tag with the URL from the postmeta.