NW Tech
NW Tech

Reputation: 328

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 assume this can be done with PHP, but I'm not sure. Thanks for any input!

Upvotes: 0

Views: 6486

Answers (3)

Adrian
Adrian

Reputation: 1539

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 :)

Upvotes: 0

GaryDevenay
GaryDevenay

Reputation: 2415

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

Upvotes: 2

powtac
powtac

Reputation: 41040

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);

Upvotes: 1

Related Questions