Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

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

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
}
share|improve this answer
    
Perfect! Thank you. –  dalbaeb Feb 2 '12 at 18:08
add comment

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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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