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?

link|improve this question
Are you looking to do this on a per-post basis? – 5t3ph Feb 2 at 17:37
@5t3ph: more on a per-template basis. – dalbaeb Feb 2 at 18:09
feedback

2 Answers

up vote 0 down vote accepted

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
}
link|improve this answer
Perfect! Thank you. – dalbaeb Feb 2 at 18:08
feedback

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.

link|improve this answer
Never done it before but would be willing to try. Any nice tutorials come to mind? – dalbaeb Feb 3 at 15:37
This one is pretty solid. – m0r7if3r Feb 4 at 3:38
feedback

Your Answer

 
or
required, but never shown

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