I have a shortcode that iterates through a list of custom post types and, as part of displaying them, creates a block. In HTML5, it is illegal to have a style block outside the header (maybe in other versions too, but we are using HTML5).
I am looking for a way that my shortcode can insert its block into the head. Any suggestions?
This is the page: http://2011.solarteam.org/sponsors/gift-recognition/view-of-living-room
The shortcode is called twice on a page.
Once like this [interactive slug='sponsor-map-living-room' show="image"]Select an item to learn more about its sponsor.[/interactive]
to make the image.
Once like this [interactive slug='sponsor-map-living-room' show='list' headertitle='WaterShed Featured Sponsors: Living Room' /]
to make the list at the bottom.
I can't put it in the template because the template does not know which slug
goes on which page.
Here is a simplified version of the shortcode processing code:
<ul><?
foreach($map->points as $point){
$result = "";
if(!in_array($point->pointer_type, $all_styles['regular'])){
$all_styles['regular'][$point->pointer_type] = "
.pointer_style_" . $point->pointer_type . " {
width: " . $point->pointer_width(). "px;
height: " . $point->pointer_height(). "px;
background: transparent url('/images/interactive/pointers/" . $point->pointer_URL() . "');
}
";
}
ob_start(); ?>
<li class="tag_point sponsor_data_point pointer_style_<?php echo $point->pointer_type?>" id="point_<?php echo $point->ID ?>" data-in="#point_<?php echo $point->ID ?>_info" data-hover-style="pointer_s_style_<?php echo $point->selected_pointer_type?>" style="left:<?php echo $point->x - ($point->pointer_width()/2) ?>px;top:<?php echo $point->y - ($point->pointer_height()/2)?>px;">
<div class="tag_info" id="point_<?php echo $point->ID ?>_info">
<div class="donation-title"><?php echo $point->contribution ?></div>
<div class="donation-contribution"><?php echo $point->description ?></div>
</div>
<?
$result .= ob_get_clean();
$result .= "</li>\n";
echo $result;
}
?>
</ul>
<style type="text/css">
<?php echo join("\n", $all_styles['regular']); ?>
</style>
The <style>
tag is not allowed there in HTML5, so I want to get it into the head of the page.