Browser not seeing end </span> in php and html, :(

Browser is putting in a p tag and ignoring my span:
<div class="about-hero"> <h2><span class="accel"><?php echo $excontent[0] . " "; ?></span><?php echo $rebuild; ?> </h2> </div>

in inspect element I get:

please ignore the second h2… Any ideas why its putting in a p tag instead of using the span and h2?

Thanks!

Does $excontent[0] contain the <p> tag as a part of the string in the variable?

1 Like

Just did a var_dump($excontent);

array(27) { [0]=> string(13) "
Accelerate" [1]=> string(2) “is” [2]=> string(1) “a” [3]=> string(9) “marketing” [4]=> string(6) “agency” [5]=> string(7) “located” [6]=> string(2) “in” [7]=> string(3) “the” [8]=> string(5) “heart” [9]=> string(2) “of” [10]=> string(4) “NYC.” [11]=> string(3) " A" [12]=> string(5) “great” [13]=> string(4) “bank” [14]=> string(2) “of” [15]=> string(5) “dust,” [16]=> string(5) “white” [17]=> string(3) “and” [18]=> string(8) “luminous” [19]=> string(2) “in” [20]=> string(3) “the” [21]=> string(5) “blaze” [22]=> string(2) “of” [23]=> string(3) “the” [24]=> string(4) “sun,” [25]=> string(4) “made” [26]=> string(16) "everything.

" } and I don’t see any p tag…

So what is creating the new line before the word Accelerate in the dump if it isn’t a <p> tag?

WP is weird about adding in tags, but what happens if you just remove any returns in the code? (That includes inside the content inserted by PHP.)

<h2><span class="accel"><?php echo $excontent[0] . " "; ?></span><?php echo $rebuild; ?></h2>

head bang… added // $new_string = preg_replace(‘/[^a-zA-Z0-9\s]/’, ‘’, $content); and saw 2 p on either side of content from WP. Did not see it when I echoed the $content since it applied the p tags I guess I am new to this… So, I added $content = strip_tags($content); and it worked… content is teh string from get_the _content() before I explode() it…head bang… I thought $content = apply_filters( ‘the_content’, get_the_content() ); would take care of tags etc. Lots to learn about WP Thanks to @felgall and @ralphm !

It sounds like you might be better off disabling or otherwise avoiding use of wptaup
(OK for WYSIWYG types, for code, not so much)

https://codex.wordpress.org/Function_Reference/wpautop

Changes double line-breaks in the text into HTML paragraphs (<p>…</p>).
WordPress uses it to filter the content and the excerpt.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.