Can't change <p> tag in the_content using string replace
php, wordpress
Solution
You need to use `apply_filters('the_content')` to have Wordpress newlines with paragraphs.
<?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);
?>
See the codex entry for the_content. Its in the alternative usage section.
Problem
I am struggling to get a simple string replace to work in wordpress the_content function. ``` <?php $phrase = the_content(); $find = '<p>'; $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;">'; $newphrase = str_replace($find, $replace, $phrase); echo $newphrase; ?> ``` It just seems to echoing `<p>` still. Instead of `<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;">`