Home › Forums › General Issues › Use ACF image field from specific post ID as CSS Background › Reply To: Use ACF image field from specific post ID as CSS Background
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
}
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.