Wednesday, June 27, 2012

load the video on wp theme

<?php $embed_code = wp_oembed_get('http://www.youtube.com/watch?v=AbcDeFg123'); ?>

<?php $embed_code = wp_oembed_get('http://www.youtube.com/watch?v=AbcDeFg123', array('width'=>400)); ?>

Sunday, June 24, 2012

wordpress query post orderby meta_value number

query_posts('cat=5&showposts=9&meta_key=views&orderby=meta_value'.'&paged='.$paged);

Wednesday, June 6, 2012

WordPress plugin: Protect your blog from malicious URL Requests

Due to its popularity, WordPress is often the target of hackers. Today, let’s see how we can build a plugin that will check for malicious URL requests (Long request strings, presence of either “eval” and “base64″ php functions, etc.) and use it to protect our blog.

Paste the following code into a text file, and save it as blockbadqueries.php

<?php 
 /*  Plugin Name: Block Bad Queries
  Plugin URI: http://h20bikash.blogspot.com/
  Description: Protect WordPress Against Malicious URL Requests  
Author URI: http://h20bikash.blogspot.com  
Author: Jibon Bikash Roy  Version: 1.0  
*/  
global $user_ID; if($user_ID)
 {  
  if(!current_user_can('level_10'))
 {  
    if (strlen($_SERVER['REQUEST_URI']) > 255 || strpos($_SERVER['REQUEST_URI'], "eval(") || strpos($_SERVER['REQUEST_URI'], "CONCAT") || strpos($_SERVER['REQUEST_URI'], "UNION+SELECT") || strpos($_SERVER['REQUEST_URI'], "base64")) 
{   
       @header("HTTP/1.1 414 Request-URI Too Long");
   @header("Status: 414 Request-URI Too Long");
   @header("Connection: Close"); 
  @exit; 
     } 
   } 
 }


?>

How to increase WordPress memory limit, the easy way

Simply open your wp-config file, located at the root of your WordPress install, and paste the following code in it. Once saved, WordPress will be able to use as much memory as specified.

define('WP_MEMORY_LIMIT', '96M');

How to easily disable theme changing

paste the following piece of code in your functions.php file:


add_action('admin_init', 'slt_lock_theme'); 
 function slt_lock_theme() { 
     global $submenu, $userdata;  
get_currentuserinfo();  
    if ($userdata->ID != 1) {  
        unset($submenu['themes.php'][5]); 
     set($submenu['themes.php'][15]);  
    } 
 }

Post Pic Reduce spam on your WordPress blog by using .htaccess


RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*yourdomainname.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

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');

?>