Wednesday, June 6, 2012

Automatically add a Google+ button to your posts

Open your functions.php file and paste the following code in it:


<?php  
add_filter('the_content', 'wpr_google_plusone');
 function wpr_google_plusone($content) {
      $content = $content.'<div class="plusone"><g:plusone size="tall" href="'.get_permalink().'"></g:plusone></div>';  
    return $content; 
 } 
 add_action ('wp_enqueue_scripts','wpr_google_plusone_script'); 
 function wpr_google_plusone_script() {  
    wp_enqueue_script('google-plusone', 'https://apis.google.com/js/plusone.js', array(), null);  }
 ?>

Speed up your blog by caching custom queries

Is your theme using custom queries? If yes, you should definitely use WordPress Transients API to cache the queries and consequently speed up your blog. Today’s recipe will show you how to cache any custom queries.


<?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... 
 ?>


Replace excerpt ellipsis with post permalink

Paste the following code into your functions.php file. Once saved, the tip will be applied to your blog



function replace_excerpt($content) { 
        return str_replace('[...]',  '... <div class="more-link"><a href="'. get_permalink() .'">Continue Reading</a></div>',  $content ); 
 } 
 add_filter('the_excerpt', 'replace_excerpt');

How to automatically create meta description from content

Paste the following code into your functions.php file:


function create_meta_desc() {
    global $post;
if (!is_single()) { return; }
    $meta = strip_tags($post->post_content);
    $meta = strip_shortcodes($post->post_content);
    $meta = str_replace(array("\n", "\r", "\t"), ' ', $meta);
    $meta = substr($meta, 0, 125);
    echo "";
}
add_action('wp_head', 'create_meta_desc');
 
?> 

Customizing wordpress Dashboard Footer


function remove_footer_admin () {
    echo '
Developed By Jibon Bikash Roy
';
    }

    add_filter('admin_footer_text', 'remove_footer_admin');

?>

replac wordpress the dashboard logo



function custom_dashboard_logo() {
   echo '#header-logo 
{ background-image: url('.get_bloginfo('template_directory').'/img/dashboardlogo.gif) !important; }';
}
add_action('admin_head', 'custom_dashboard_logo');
 
?> 

Customize wprdress Login Page

These are things you would put in the active theme's  functions.php file.



function change_wp_login_url() {
    echo bloginfo('url');
}
add_filter('login_headerurl', 'change_wp_login_url');

function change_wp_login_title() {
    echo get_option('blogname');
}
add_filter('login_headertitle', 'change_wp_login_title');

?>