I created a quick WordPress shortcode so my writers can easily style out a subtitle in the Visual editor of a post:
function subtitle( $atts, $content = null ) {
return '<p class="subtitle">' . $content . '</p>';
}
I want to move this output to inside a specified elsewhere in the document, example:
<div id="output_here_please"></div>
<?php the_content(); /* It is returned here wherever they place the shortcode */ ?>
What is the best way to do this? Is there a PHP or WordPress function to use, or should I create a javascript to replace innerHTML (I tried this but didn’t know how to insert it AFTER the page loads).
Thanks
If your function is called subtitle like that, then they can insert it with:
The quick and dirty way of doing it is to declare a global variable – say
$subtitle_content
, and use it to store temporarily the html fragment you wish to display elsewhere.You may want to undefine that variable once it becomes unnecessary, as written in the commented out code above.
Documentation on
$GLOBAL
for your information.Note: