5
votes

I'm sure this is simple, but I've searched Google for about 30 minutes with no luck. I'd like to know if it's possible to adjust the default class of paragraphs that are output by the_content in Wordpress.

I've read that you can add filters to the theme's functions.php file, but this particular use of WordPress isn't using a theme. Think of a static HTML site (5 pages) with a main content area on each page. Wordpress is literally only used to change the contents of those 5 content areas by the client editing any of the necessary 5 posts.

The problem is that the p tags that WordPress spits out don't have any classes applied to them. Can I change that in my query or anything? Ideally I'd be able to change the paragraph class that is output on each page individually.

Thoughts?

Thanks in advance for any help!

3

3 Answers

5
votes

Wrap your content with a div, and apply a class to that:

<div class="content">
    <? the_content(); ?>
</div>

And style it like so:

.content p { ... }
/* Page-specific */
.page-id-1 .content p { ... }
0
votes

The accepted answer didn't really answer the question for me, but I found this post which gave me what I needed—so my solution ended up being something like this:

<?php
$content = get_content();
$content = str_replace('<p', '<p class="default-class"', $content); ?>

<div class="wrapper"><?php echo $content ?></div>

That did the trick!

0
votes
function wph_add_class_for_p_tag($content) {
    $content = str_replace('<p>', '<p class="SomeClass">', $content);
    return $content;
}

add_filter('the_content', 'wph_add_class_for_p_tag', 9999);
add_filter('the_excerpt', 'wph_add_class_for_p_tag', 9999);