skip to Main Content

I have this code:

<p>
<iframe src=""></iframe>
</p>

How can I add a class to the P using function.php? only in a single post?

so the result will be:

<p class="something">
 <iframe src=""></iframe>
</p>

2

Answers


  1. Since you haven’t given us much of an explanation of where your HTML is coming, I’ll just have to guess at a bunch of things. The code below will output the requested HTML on a single post.

    if (get_queried_object_id() === 123) {
        echo '<p class="something"><iframe src=""></iframe></p>';
    }
    
    Login or Signup to reply.
  2. Check if your p tag has children using jQuery:

    // Add some class that is unique or someting
    if ( $('p.unique-class').children().length > 0 ) {
         // do something
         $(this).addClass('your-class');
    }
    
    // or
    
    if ( $('p.unique-class').find('iframe').length > 0 ) {
        // do something
         $('p.unique-class').addClass('your-class');
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search