How To Execute Shortcode From Custom Field
The snippet will let you add shortcode to a WordPress custom field.
1 |
<?php echo apply_filters('the_content', get_post_meta($post->ID, 'your_custom_field_here', true)); ?> |
Snippet Source/Credit: Leeboyce.co.uk
How To Have Login Form For Your Themes In WordPress
The following snippet will let you have login form for your themes in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/** * Usage: add user_login_form(); to your theme somewhere. * * */ function user_login_form(){ ?> <form id="loginform" action="<? echo site_url('wp-login.php', 'login_post') ?>" method="post"> <ul id="login_list"> <li> <label for="user_login">Username / Email Address <input type="text" name="log" id="user_login" class="input round" value="<?php echo esc_attr($user_login); ?>" /> </label> </li> <li> <label for="user_pass">Password <input type="password" name="pwd" id="user_pass" class="input round" value="" /> </label> </li> <? do_action('login_form'); ?> <li class="rememberme-check-box"> <input name="rememberme" type="checkbox" id="rememberme" value="forever" /> Remember you? <input type="hidden" name="redirect_to" value="<?php echo esc_attr(get_option('home')); ?>/?action=user" /> </li> <li class="submit"> <a href="<? echo get_option('home'); ?>/?action=user" title="Lost your password? Reset it here..." class="button" id="password-reset"> Forgot Your Password? </a> <input class="button" type="submit" id="signin" value="Sign In" /> </li> </ul> </form> <? } |
How To Disable Post Revision In WordPress
Add the following snippet to your theme’s wp-config.php file and you will be able to disable WordPress post revision.
1 |
define('WP_POST_REVISIONS', false); |
Snippet source/Credit: lesterchan.net
How To Have WordPress Domain Check
Using the following snippet will let you have your WordPress domain check.
1 2 3 4 5 6 7 8 9 10 |
<?php $loc = $_SERVER['REQUEST_URI']; $locDomain = $_SERVER['HTTP_HOST']; $posDomain = strpos($locDomain, 'travismathew.ca'); ?> <?php if ($posDomain !== false) { ?> <!-- CANADIAN --> <?php } else { ?> <!-- UNITED STATES --> <?php } ?> |
Snippet Source/Credit: Snipplr
How To Speed Up Your Blog By Adding Caching Custom Queries
Using the following snippet, you will be able to speed up your blog by adding caching custom queries.
1 2 3 4 5 6 7 8 9 |
<?php // Get any existing copy of our transient data if ( false === ( $special_query_results = get_transient( 'special_query_results' ) ) ) { // It wasn't there, so regenerate the data and save the transient $special_query_results = new WP_Query( 'cat=5&order=random&tag=tech&post_meta_key=thumbnail' ); set_transient( 'special_query_results', $special_query_results ); } // Use the data like you would have normally... ?> |
Snippet Source/Credit: WordPress Codex