Thanks again John – your help has really opened this up for me.
Just a quick follow-up question, so I understand how to use this concept where ever I need to:
How do I best to apply this to other page types, eg. single product page, blog archive, blog page, etc. Is there a list of phrases/descriptors I can swap out for ‘woocommerce_before_shop_loop_item_title’? I apologize, I know very little PHP; if I knew what to call these descriptors I could look it up… Your answers have me interested in learning more about these possibilities.
For example, on a single product page, is there anything wrong coding-wise with the this?:
// Try it on the single product page
add_action('woocommerce_before_shop_loop_item_title', 'custom_single_product_css');
function custom_single_product_css() {
global $product;
?>
<style type="text/css">
.my-custom-block-class {
background: url(<?php the_field('my_image', $product->id); ?>);
}
</style>
<?php
}
@hube2 Perfect. You are an absolute legend and you’ve made my task much easier. Learning this filter really opened my eyes. Much appreciated.
Hi John – thanks, really appreciate your help. I see what you’re doing with that code, and I’m keen to get it working.
When I paste that code into functions, however, I get this syntax error:
Your PHP code changes were rolled back due to an error on line 191 of file wp-content/themes/child/functions.php. Please fix and try saving again.
syntax error, unexpected ':'
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.