Last active
August 29, 2015 14:11
-
-
Save isotrope/f567243eda49a66b3c83 to your computer and use it in GitHub Desktop.
One trick to keeping all your site's various re-used values in the same place.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*** | |
* _____ _ _ _ _ _ | |
* / ____| | (_) | | | | (_) | |
* | | ___ _ __ ___ ___ | |_ __| | __ _| |_ _ _ __ __ _ | |
* | | / _ \| '_ \/ __|/ _ \| | |/ _` |/ _` | __| | '_ \ / _` | | |
* | |___| (_) | | | \__ \ (_) | | | (_| | (_| | |_| | | | | (_| | | |
* \_____\___/|_| |_|___/\___/|_|_|\__,_|\__,_|\__|_|_| |_|\__, | | |
* / __ \ | | (_) __/ | | |
* | | | |_ __ | |_ _ ___ _ __ ___ |___/ | |
* | | | | '_ \| __| |/ _ \| '_ \/ __| | |
* | |__| | |_) | |_| | (_) | | | \__ \ | |
* \____/| .__/ \__|_|\___/|_| |_|___/ | |
* | | | |
* |_| | |
*/ | |
/*** | |
* _ _ | |
* /\ | | (_) | |
* / \ _ __ ___ _ __ | |_ _ ___ _ __ ___ | |
* / /\ \ | '_ \ / _ \| '_ \| __| |/ _ \| '_ \/ __| | |
* / ____ \| | | | | (_) | |_) | |_| | (_) | | | \__ \ | |
* /_/ \_\_| |_| \___/| .__/ \__|_|\___/|_| |_|___/ | |
* __ _| |_ | |
* / _| | |_(_) | |
* | |_ _ _ _ __ ___| |_ _ ___ _ __ | |
* | _| | | | '_ \ / __| __| |/ _ \| '_ \ | |
* | | | |_| | | | | (__| |_| | (_) | | | | | |
* |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| | |
* | |
* | |
* Basically a function that serves as a repository for all your re-used values | |
* Stick this at the top of your functions.php | |
* or inside a variables.php (don't forget to include('variables.php') it somewhere like functions.php ) | |
* | |
*/ | |
function allhanesondeck_options( $key ) { | |
// You can add in all sort of values that you re-use a lot | |
$my_options = array( | |
'columns_cat' => 86, | |
'contact_page_id' => 12, | |
'special_category_id' => 17, | |
'cat_pics_ids' => array( 12, 14, 19 ), | |
'text_that_keeps_coming_back' => __( 'Tired of typing this text over and over', 'hanes_text_domain' ), | |
); | |
// Making sure that it's actually set. If not, return false | |
// Note: could get confusing if your $key's value actually IS (bool) false | |
return isset($my_options[$key]) ? $my_options[$key] : false; | |
} | |
/** | |
* Then, anywhere in your code, you can simply use the above. | |
* "But that makes it so much longer! | |
* - Ah! But remember that time you had to go through all your code because your | |
* customer inadvertently deleted a category and then re-created one and assigned | |
* posts to it? | |
* This way, you change it once and everything else is still good to go | |
*/ | |
?> | |
<a href="<?php get_category_link( allhanesondeck_options( 'contact_page_id' ) ); ?>"><?php _e('Contact Us!', 'hanes_text_domain'); ?></a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment