Inject HTML meta tag inside wordpress tag using add_shortcode
Question
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
}
?>
0
actions, plugin-development, plugins, shortcode, wp-head
4 years
2020-05-21T14:10:24-05:00
2020-05-21T14:10:24-05:00 0 Answers
100 views
0
Leave an answer