I want to add a meta tag like this one:
<meta name="key" content="value" />
to some of the pages in Wordpress. I know, I can add this into my template and it will show up. But the thing is, I am not allowed to even touch the template. It's totally template independent.
So, I have to add the meta tag only by doing something in my plugin code. I have tried wp_head
action hook, but it is not working. Any idea of a workaround or anything to get the meta tag inside the head tags of the pages dynamically.
What I'm doing
What I'm doing is a little different. There are two pages in my blog, Main Content Page and Summary Page. Both of these pages get data through shortcodes. So, the Main Content Page has a shortcode
[mainpage]
and the Summary Page has this shortcode in it
[summarypage]
The shortcode was added to main plugin file
add_shortcode( 'mainpage', 'mainPage' );
add_shortcode( 'summarypage', 'summaryPage' );
Now, in my plugin directory, I have two php files named mainpage.php
and summarypage.php
and they return html content.
In mainpage.php
function mainPage() {
// Code which generates html content
$mainpage .= 'content';
return $mainpage;
}
similarly, in summarypage.php
function summaryPage() {
// Code which generates HTML content
$summarypage .= 'content';
return $summarypage;
}
Since, $mainpage and $summarypage contains all that which go inside the page textarea box. I have no idea how to add some meta information to my main or summary pages. Using wp_head
inside the function mainPage()
and summaryPage()
doesn't work and rightly so.
So, how can I get a meta tag inside the head section of the page??