Making a section optional (e.g. adsense or not)

There has been an astounding silence to my previous query regarding divergent themes (several themes which are mostly similar, but which have some differences.) so I’m considering another direction.

Is it possible to make certain parts of a theme (say, a whole section) optional? I’m thinking customizer control, In my specific instance, I want to have Google ads shown on some sites, and not on others, but the same concept could be extended to a slider or no slider, jumbotron or no, and so on.

However, I can’t see a way of doing this with customizer. Is there a way to leave the option to the site admin?

Alternatively, I’m thinking:

  1. Clone the entire project and have two versions (make it hard to maintain)
  2. Have single_with_ ad.html and single_no_ad.html and rename one php file to single.php (yuk, messy)
  3. Add PHP code from the WP/Misc in Pinegrow and check for something like the site url before outputting the ad (makes it very specific, works for my situation, but not generally useful)

Any input would be very much appreciated! Thanks

(Incidentally, Forum feedback:I couldn’t get the list to work to create this entry, and am I right in thinking I can only use pre-existing tags?)

Hi @greyguru. I meant to comment on your previous question but I genuinely forgot. What I would suggest is the possibility of using the option to not export the parts of the theme you do not want to use. For example if you create one theme with all options included, this might be used on Site A (including ads), then for site B (not including ads) click the option to not export the part/section of the theme. This way you can have one overall theme but output only the required parts for each site. I know “Don’t Export” wasn’t intended for this but I think it could work quite well.

The one issue I see with this is that each time you export you will overwrite the last export which would mean you would have to back up the export of Site A to losing a copy of it when exporting Site B. I don’t think that’s to much of a hassle and once you make it part of your process I think it could work quite well.

Thanks, I hadn’t thought of “Do not export”.I’m using a local test bed, so the theme on the actual sites won’t be overridden. But I will have to be careful.

I take it there isn’t an option you can think of using Customise.

I believe there is a larger issue for people who don’t want to start from the Pinegrow starter each time, and yet would like to incorporate any new features from future starter versions. But that’s a separate topic. Thanks again.

Woops, maybe “spoke” too soon.Added “Don’t export” to the containing section, saved, exported the theme, refreshed the page and yet the ad is still there.

No forget that, it was working, but I had a single-xxxx.html as well, which I didn’t change. Do not export IS working when there’s no filter to divert to the other template. Gosh, this stuff is confusing sometimes!

1 Like

@greyguru so is this a possible solution for your situation? Can you tell us what was the scenario where it still exported, i.e. why it exported and how to prevent it from happening… just in case somebody else is doing something similar and meet the same issue.

Yes, I wasn’t too clear - a long day of debugging… ending up with my hosting company running out of disk space after I had just deleted the theme so I couldn’t upload again, AND this forum being down!

I have single.php and single-random.php. The latter is used when a post has a tag of “random” because random posts are meant to show as small text items in the side bar, so single-random doesn’t show the featured image. When I was trying “Don’t export” I changed single.php and tested. But because the post that was currently showing had the “random” tag, my test appeared to fail (the ads still showed) because I wasn’t using the single.php to display the post. Once I added “don’t export” in both I had no ads.

It’s not a GREAT solution - already I need to remember to change TWO things for the non-ad version, I’d prefer to have a master project with all the code and be able to turn things on and off through a separate mechanism. I could certainly do this with a straight PHP MySQL set of sites, the challenge is to be able to do this within the PineGrow framework.

unabashedgeek.com is my work in progress (with ads!)