2011-06-17, 01:28:27
RobA Wrote:I need to […] put in a plugin hook using some short code like (% whatever %).No you don’t.
Code:
add_action('index-pretemplate','changeContent');
function changeContent() {
global $content;
$content = 'My plugin content!';
}
RobA Wrote:This means my plugin parse gets called every page.Not necessarily. When your plugin file is being loaded the current page slug is already accessible.
Normally the slug is figured out with the following code (from index.php):
Code:
if (isset($_GET['id'])){
$id = str_replace ('..','',$_GET['id']);
$id = str_replace ('/','',$id);
$id = lowercase($id);
} else {
$id = "index";
}
Code:
if (isset($_GET['id'])){
$id = str_replace ('..','',$_GET['id']);
$id = str_replace ('/','',$id);
$id = lowercase($id);
} else {
$id = "index";
}
if ($id=='mypluginslug') {
add_action('index-pretemplate','changeContent');
function changeContent() {
global $content;
$content = 'My plugin content!';
}
}
ccagle8 Wrote:Couldn’t you use a check with return_page_slug()return_page_slug() is not available to plugins until inside the index-pretemplate hook. So if you are concerned about adding a filter to pages where the filter should not be executed that won’t work. (Or it will, but it will be a very roundabout kind of way.)
“Don’t forget the important ˚ (not °) on the a,†says the Unicode lover.
Help us test a key change for the core! ¶ Problems with GetSimple? Be sure to enable debug mode!
Help us test a key change for the core! ¶ Problems with GetSimple? Be sure to enable debug mode!