mercredi 15 juin 2016

Formating paragraphs in WordPress issue

I'm creating a plugin that will help me to automate sending a newsletter. When I publish a new blog post, I want to send a HTTP request to newsletter provider's API.

I have a template which HTML code in WP looks like the following:

Hello,

We've published a new <a href="{post.url}">blog post.</p>

{post.name}

<em>{post.desc}</em>

If you like it, let us know.

Best regards.

I've a small function that will replace {post.url} with the permalink, {post.name} with the blog post name and {post.desc} is actually the first X characters of the content.

The problem is that WordPress's editor does not add paragraphs and I need them.

I've found that there is a function called wpautop(); and it adds paragraphs, so it looks really nice. I can easily replace {post.url} and {post.name} but cannot replace {post.desc} because it adds paragraphs too. So my HTML code looks like the following:

<p>Hello,</p>
<p>We've published a new <a href="http://ift.tt/1sGXVf8">blog post.</p>
<p><a href="http://example.net">Hello World</a></p>
<p><em><p>This is our blog post description. We show only first X characters</p></em></p>
<p>If you like it, let us know.</p>
<p>Best regards.</p>

As you can see, there is a paragraph in paragraph and it makes the mess. I need somehow to avoid it, but not sure how, because I'm not so familiar with native WP functions. Maybe I could do someting with regex, but..

Thanks everyone.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire