Prevent WordPress to compress your jpg images
Adding the following code to your functions.php file will let WordPress prevent to compress your jpg images.
1 |
add_filter('jpeg_quality', function($arg){return 100;}); |
Source: WP-Snippets
Embed a page into another page
Paste the code below within the loop. And you will be able to embed a page into another page.
1 2 3 4 5 6 7 |
<?php $recent = new WP_Query("page_id=**ID**"); while($recent->have_posts()) : $recent->the_post();?> <h3><?php the_title(); ?></h3> <?php the_content(); ?> <?php endwhile; ?> |
Source: CSS Tricks
Add extra contact methods to user profiles
Just paste the following code into your function.php file and you will be able to add extra contact methods for your user profiles.
1 2 3 4 5 6 7 8 9 10 11 |
add_filter('user_contactmethods', 'my_user_contactmethods'); function my_user_contactmethods($user_contactmethods){ $user_contactmethods['twitter'] = 'Twitter Username'; $user_contactmethods['facebook'] = 'Facebook Username'; return $user_contactmethods; } |
Source: TutsPlus
Use shortcodes in theme files
The following snippet will allow you to use shortcodes in theme files.
1 |
<?php echo do_shortcode("[my_shortcode]"); ?> |
Source: WP Snippets
Speed up your blog by caching custom queries
Simply paste the following code where you need to execute a custom query to the database and you will be able to speed up your blog by caching custom queries.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?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... ?> |
Source: WordPress Codex
Show admin bar only for admins
Simply paste the following code into your functions.php file and you will be able to show admin bar only for admins.
1 2 3 4 5 |
if (!current_user_can('manage_options')) { add_filter('show_admin_bar', '__return_false'); } |
Source: Jeff Starr
Display number of Facebook fans in full text
Simply paste the following code, where you want your Facebook fan count to be displayed.
1 2 3 4 5 6 7 8 9 10 11 |
<?php $page_id = "YOUR PAGE-ID"; $xml = @simplexml_load_file("http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=".$page_id."") or die ("a lot"); $fans = $xml->page->fan_count; echo $fans; ?> |
Source: WP Snippets
Restrict user access to specific templates
Simply create a new page template and paste the following code and you will be able to restrict user access to specific templates.
1 2 3 4 5 6 7 8 9 10 11 |
<?php /* Template Name: Restricted to Authors only */ if ( !current_user_can('author')) { wp_die('You don’t have access to this page.') } ?> |
Source: Kevin Chard
Photo Credit: Flickr/Jeff Dlouhy