如何使用正确的“FILTER HOOK”

时间:2018-04-20 08:43:06

标签: wordpress filter hook-woocommerce

我想在下面的代码中替换图像源:

$placeholder = apply_filters( 'rocket_lazyload_placeholder', 'data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=' );

$html = sprintf( '<img%1$s src="%4$s" data-lazy-src=%2$s%3$s>', $matches[1], $matches[2], $matches[3], $placeholder );

$html_noscript = sprintf( '<noscript><img%1$s src=%2$s%3$s></noscript>', $matches[1], $matches[2], $matches[3] );

我已经编写了这段代码来改变它,但它没有用。怎么了?

function add_change_image_lazyload ( $output ) {
    $output = 'http://example.com/image.svg';
    return $output;
}
add_filter( 'rocket_lazyload_placeholder', 'add_change_image_lazyload' );

1 个答案:

答案 0 :(得分:0)

更改微调器/加载图像的方法是:

<?php 
$status = $row[‘Status’] == ‘ONLINE’ ? ‘Online’ : ‘Offline’; 
$css = $row[‘Status’] == ‘ONLINE’ ? ‘success’ : ‘danger’;
?>
<span class="label label-<?= $css ?> label-rounded"><?= $status?></span>

代码进入您的活动主题/子功能。php