I am trying to add an inline style to my paragraph tags which are ouputted using the_content();

I’ve tried string replace, see question I did earlier. But it won’t because the_content echo’s it and does not return it. If I return the content using get_the_content();, it does not output in paragraph tags.

Can anyone help me with this?

4 Answers
4

Thanks to @papirtiger

Came up with this solution just to apply it to a specific content function.

I did not explain in my question that I only needed to work on a specific the_content, instead I think the above solutions are a global solutions, and both are great solutions from that point of view.

<?php 

    $phrase = get_the_content();
    // This is where wordpress filters the content text and adds paragraphs
    $phrase = apply_filters('the_content', $phrase);
    $replace="<p style="text-align: left; font-family: Georgia, Times, serif; font-size: 14px; line-height: 22px; color: #1b3d52; font-weight: normal; margin: 15px 0px; font-style: italic;">";

    echo str_replace('<p>', $replace, $phrase);

?>

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *