简体   繁体   English

function.php(wordpress) - 如果它包含 ZA598E4F2AFAD7DF2561FDC4762,则将 class 添加到 P

[英]function.php (wordpress) - Add class to P if it contains iframe

I have this code:我有这个代码:

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

How can I add a class to the P using function.php?如何使用 function.php 将 class 添加到 P? only in a single post?只在一个帖子中?

so the result will be:所以结果将是:

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

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.由于您没有向我们解释您的 HTML 将在哪里出现,我只需要猜测一堆事情。 The code below will output the requested HTML on a single post.下面的代码将 output 请求的 HTML 放在一个帖子上。

if (get_queried_object_id() === 123) {
    echo '<p class="something"><iframe src=""></iframe></p>';
}

Check if your p tag has children using jQuery:检查您的 p 标签是否有使用 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');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM