I'm passing a text string from a backend input custom meta field to the front end and I'm using watopup to ensure that the integrity of the carriage returns are maintained...
Example being;
<p><strong>Name:</strong><br /> <?php echo $curauth->display_name; ?></p>
<p><strong>Looking For Role:</strong><br /> <?php echo $curauth->emp_status; ?></p>
<p><strong>Education Level:</strong><br /> <?php echo $curauth->education; ?></p>
<strong><p><strong>Background Description:</strong><?php echo wpautop ($curauth->brand_desc);?></p></strong>
<p><strong>Candidate Location:</strong><br /> <?php echo $curauth->state; ?></p>
<p><strong>Seeking Work Type:</strong><br /> <?php echo $curauth->work_type; ?></p>
The problem I'm having is this;
When using wpautop it inserts a paragraph line before the first string sentence. I do not want a blank line inserted at the beginning of the paragraph...
Screenshot example attached...
Cheers,
Sean.
Hariprasad Vijayan answers:
Hello,
Try this,
<p>Background Description:<br />
<?php $str_desc = wpautop ( $curauth->brand_desc ); echo substr($str_desc , 3); ?>
Hope it will work.
Sean Gartlan comments:
Hariprasad,
Yes you have it, thanks so much that works fine...
A big thanks to everyone who helped and made suggestions on this thread, it's much appreciated...
The community knowledge here is excellent...
Thanks,
Sean.
Sai kumar answers:
Hi,
You can remove the wp-autop by inserting remove_filter( 'the_content', 'wpautop' );
inside in your function.
remove_filter( 'the_excerpt', 'wpautop' );
Hope it helps you
Thanks
Sai
Sean Gartlan comments:
Sai,
If I remove wpautop then the paragraph will have no paragraph breaks...
I need to remove the first line break and maintain the paragraph break within the passed string variable...
Thanks,
Sean.
Ryan S answers:
Removing filter didn't to fix the issue because that affect any other that are working well, try this instead.
FROM
<p>Background Description:<?php echo wpautop ($curauth->brand_desc);?></p>
TO
<p>Background Description:</p>
<?php echo wpautop ( $curauth->brand_desc ); ?>
$curauth->brand_desc
is returned with paragraph in it if I'm not wrong and it also by default wrap with p, so what we need is simply remove any p wrapper.
Hope that helps
Sean Gartlan comments:
Thanks Ryan...
Your answer makes sense... I'll give it a go tonight and let you know how I got on... Thanks for your solution, much appreciated...
Cheers,
Sean.
Sean Gartlan comments:
Ryan,
Unfortunately it did not work...
I changed this <p><strong>Background Description:</strong><?php echo wpautop ($curauth->brand_desc);?></p>
to this;
<p><strong>Background Description:</strong></p><?php echo wpautop ( $curauth->brand_desc ); ?>
But I got the same result... Using your suggestion I get the following html output;
<p><strong>Background Description:</strong><br></p>
<p>No one is good at everything. As much as you may be in command of your core offering, chances are your messaging doesn't quite make the grade.</p>
<p>I help business people get their messages out clearly, concisely and accurately. My writing, editing and webinar management services help clients who struggle with content reach their target audiences with sharp, meaningful and relevant information.</p>
<p>Whether it's your blog, website, newsletter, book, social media accounts or more, getting to the point and conveying simply and strong what you do or offer is essential. That's where I come in.</p>
<p>And if you need help setting up webinars/webcasts, managing them, moderating them, talk to me as well. I've conducted or supported more than 100 in the last few years.</p>
<p>If I can't be of service, I may know others who can meet your needs. After all, creating and fostering relationships - and giving back - is a cornerstone of conducting business today.</p>
<p>Specialties: Writing, editing, synthesizing elaborate materials, team-building and collaboration, high-level relationships, flexibility, and multi-tasking, managing and hosting webinars, startups and online communities.</p>
What I need is;
<p><strong>Background Description:</strong><br>No one is good at everything. As much as you may be in command of your core offering, chances are your messaging doesn't quite make the grade.</p>
<p>I help business people get their messages out clearly, concisely and accurately. My writing, editing and webinar management services help clients who struggle with content reach their target audiences with sharp, meaningful and relevant information.</p>
<p>Whether it's your blog, website, newsletter, book, social media accounts or more, getting to the point and conveying simply and strong what you do or offer is essential. That's where I come in.</p>
<p>And if you need help setting up webinars/webcasts, managing them, moderating them, talk to me as well. I've conducted or supported more than 100 in the last few years.</p>
<p>If I can't be of service, I may know others who can meet your needs. After all, creating and fostering relationships - and giving back - is a cornerstone of conducting business today.</p>
<p>Specialties: Writing, editing, synthesizing elaborate materials, team-building and collaboration, high-level relationships, flexibility, and multi-tasking, managing and hosting webinars, startups and online communities.</p>
I thought the solution might have something to do with wordpress regex or preg-replace but I'm just clutching at straws and out of my depth...
Any further help would be greatly appreciated...
Thanks,
Sean.
Ryan S comments:
Unfortunately that is not possible the reason is we're using WordPress wpautop() function which automatically convert any br to p (or use br instead)
Make sure to remove br tag right after the "Background Description" label like <p>Background Description:<br />
so the result display something like
<p class="background-description-label">Background Description:</p>
<p>our description paragraph</p>
<p>more description paragraph</p>
In that we have valid XHTML, the next thing is we simply add CSS class to control below margin or padding.
In your style.css file, simply add
p.background-description-label{ margin-bottom: 0; padding-bottom: 0; }
Hope that helps
Balanean Corneliu answers:
You can try to use <br> instead of <p>
Sean Gartlan comments:
Balanean,
I tried
<p><strong>Background Description:</strong><br /><?php echo wpautop ( $curauth->brand_desc ); ?>
but it seems to place a </p> at the end in the html output... Possibly something to do with wpautop???
<p><strong>Background Description:</strong><br></p>
Thanks,
Sean.