0

I have many custom templates for different post types, and I am manually inserting a social share bar inside the 'entry-meta' footer in each of those templates. I need a simple centralized way to disable the social share bar without hacking into the plugin.

Basically I have this setup so far:

In functions.php:

update_option( 'show_social_bar', 'true' );

In my templates I have this check:

if( get_option( 'show_social_bar' ) === 'true' ) {
  // show my social share links 
}

If I need to turn the bar off, I just set the option to 'false' in functions.php. This somehow seems inefficient. Is there a more sensible way?

2
  • Are you looking to do this on a per-post basis?
    – 5t3ph
    Feb 2, 2012 at 17:37
  • @5t3ph: more on a per-template basis. Feb 2, 2012 at 18:09

2 Answers 2

0

It's a bad practice to update an option on every page load. You should use a constant instead.

define('SHOW_SOCIAL_BAR', true); //functions.php

if(SHOW_SOCIAL_BAR){
    //Do Something
}
0
1

I think I would make it a checkbox on a settings page, that way you're not setting something every load (because MySQL writes are slow) and you have a user-friendly way to make the change.

2
  • Never done it before but would be willing to try. Any nice tutorials come to mind? Feb 3, 2012 at 15:37
  • This one is pretty solid.
    – mor7ifer
    Feb 4, 2012 at 3:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.