Jump to content
hbv

where to place code function.php or custom.css

Recommended Posts

Woocommerce took out the option for enabling a lightbox feature for your image gallery earlier this year.  They have in their documentation to add code if you want to enable the gallery features but don’t actually say where.

https://woocommerce.wordpress.com/2017/02/28/adding-support-for-woocommerce-2-7s-new-gallery-feature-to-your-theme/

This is a significant frontend change that can be broken down in to three separate new features;

  • Image zoom / magnification

  • Lightbox

  • Slider

To enable each of these features in your theme you must declare support using add_theme_support() like so;

1

2

3

4

5

6

7

add_action( 'after_setup_theme', 'yourtheme_setup' );

 

function yourtheme_setup() {

    add_theme_support( 'wc-product-gallery-zoom' );

    add_theme_support( 'wc-product-gallery-lightbox' );

    add_theme_support( 'wc-product-gallery-slider' );

}

This allows you the flexibility to pick and choose exactly which features you want to include/exclude in your theme or at your store.

I am not a developer, I don’t have a developer (and shame on WC for not making this an option that end users can opt for or not without having to add code!)  I need to know where to put this code.  I am using a child theme called mystile1.  I have files called “Theme Functions (function.php)” and one called “custom.css” that’s says it is specifically for adding code to modify my child theme styles.

I don’t know which file I should put the above coding in and where.  Nowhere does each of these files have a line called “after_setup_theme” So would I be safe in just adding the code as follows in one of those files (which one?) replacing “yourtheme” with the name of my theme:

add_action( 'after_setup_theme', 'mystile1_setup' );

 

function mystile1_setup() {

    add_theme_support( 'wc-product-gallery-zoom' );

    add_theme_support( 'wc-product-gallery-lightbox' );

    add_theme_support( 'wc-product-gallery-slider' );

}

 

Or any other suggestions are greatly appreciated.

Thank you.

Share this post


Link to post
Share on other sites

' after_setup_theme' is wordpress hook, that will run specific function after current theme setup is finished.

So yes! you add what you currently have at bottom of previous post  in function.php or is it functions.php?

But! make backup first! just in case.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...