I want to create a shortcode to style existing content on a page.
function myShortcode(){
$mycontent = '<div class = "columnstyle">';
$mycontent .= ...existing content wrapped in a <p> tag...
$mycontent .= '</div>';
return $mycontent;
}
add_shortcode('columnstyle', 'myShortcode');
The existing ‘p’ tag:
<p class='first'>blah blah blah</p>
How do I assign $(‘.first’) to $mycontent? I don’t think this is working…
$mycontent .= $('.first');
Update:
I knew $(‘.first’) is a javascript variable as I didn’t know how to reference it in PHP. The next function I am going to carry out is:
function myShortcode_call(){
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$('.first').before("<?php echo do_shortcode('[columnstyle]'.myShortcode().'[/columnstyle]');?>");
});
</script>
<?php
}
add_action('thesis_hook_after_html','myShortcode_call');
The result is to style the content “blah blah blah” on the page with the short code [columnstyle].
I think this is what you want. Are you working with wordpress?
http://codex.wordpress.org/Function_Reference/do_shortcode