Support

Account

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 
    }