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. Is there 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, the 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 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?
We could help you better, if you showed us what you have tried already.
Here is a working example:
Now I’m wondering why you are allowed to install plugins but not to change the theme ⦠🙂
Does this work on something similar to
The shortcode Template is being called to render to shortcode…. that is in a post.