How do I add h2 to this code?

How do I add h2 to this car-title ?

I have tried various coding methods, yet without success,

All help appreciated.

<div class="car-title">
<?php echo esc_attr(trim(preg_replace( '/\s+/', ' ', substr(stm_generate_title_from_slugs(get_the_id()), 0, 35) ))); ?>
<?php if(strlen(stm_generate_title_from_slugs(get_the_id())) > 35){
                        echo esc_attr('...');
                    } ?>
                </div>

The css code:

.car-listing-row .listing-car-item-meta .car-title {
margin-top: 10px;
min-height: 36px;
white-space: nowrap;
text-overflow: ellipsis; }

What actually gets output by that PHP code?

1 Like

Hello ralpm, thank you for your quick reply,

The Car Tile is the displayed output from the PHP code

creating site here red-wing-shoes.com

Big Blue Car (and all Titles) is the Title I would like to have H2

Looks like you just need to replace the div with an h2:

<h2 class="car-title">
<?php echo esc_attr(trim(preg_replace( '/\s+/', ' ', substr(stm_generate_title_from_slugs(get_the_id()), 0, 35) ))); ?>
<?php if(strlen(stm_generate_title_from_slugs(get_the_id())) > 35){
                        echo esc_attr('...');
                    } ?>
</h2>
2 Likes

Hello ralpm, thank you for that quick code,

I have added the h2 as you suggested, with Inspect Element I can see the new h2 code, yet the car titles are not detected as h2 ?

using: seositecheckup.com/tools/h1-and-h2-tag-test

Hi, RayWilk.

Please show us the HTML after the php has been executed so we can see what would be sent to a browser. PHP by itself is mostly meaningless to a browser. The HTML or content that it inserts is the thing we need to see.

If you can write a “working page” with the HTML and CSS, that would be ideal. A CodePen would be the next option. And if all else fails, a link to the site might help. You just need to tell us where on the page to look for the issue.

1 Like

Hello ralpm, ok retested and now all h2 Title are showing up at H2,

Just needed a moment to update, all H2’s looking great :slight_smile:

Thank you for you quick expert help, much appreciated :slight_smile:

2 Likes

Hello ronpat,

Thank you for your reply,

Just as you replied I re-tested the h2 code and now all Titles are displaying correctly with an h2 tag,

Thank you again :slight_smile:

1 Like

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