Add class to html element with PHP
Is there an easy way to automatically wrap any h2 element in the div class "entry-content" in another div class "entry-header"
So the end result would look something like:
<div class="entry-content">
<div class="entry-header">
<h2>Some Title</h2>
</div>
</div>
I a开发者_C百科ssume this can be done with PHP, but I'm not sure. Thanks for any input!
In terms of wordpress I would probably verge towards creating a shortcode such as
[header]Some Title[/header]
I would make the shortcode take the content and wrap the given code around it.
See some documentation here: http://codex.wordpress.org/Shortcode_API
ugly one:
$content = str_replace('<div class="entry-content">', '<div class="entry-content"><div class="entry-header">', $content);
$content = str_replace('</h2>', '</h2></div>', $content);
Can you do it in prototype ? This would be my easy solution:
var div = $('entry-content');
$(div).insert ({'top' : '<div class="entry-header">'} );
$(div).insert ({'bottom' : '</div>'} );
Maybe I'm missing somethig :)
精彩评论