Wednesday, November 28, 2012

use the get_bookmarks() method

<?php $links = get_bookmarks( array(
'orderby' => 'link_id',
'order' => 'ASC',
));
//print_r($links);
// Loop through each bookmark and display the formatted output
foreach ( $links as $link ) {
echo '<li>';
echo '<strong>'.$link->link_name.'</strong>';
echo '<br />';
echo '<a href="'.$link->link_url.'" target="_blank">';
echo $link->link_url.'</a>';
echo '<br />';
echo $link->link_description;
echo '</li>';
} ?>

Wednesday, November 21, 2012

display all Authors in an unordered list

$args = array(
 'blog_id' => $GLOBALS['blog_id'],
 'role' => 'Author',
 'orderby' => 'nicename'
 ); 

  $blogusers = get_users($args);
//  print_r($blogusers);
    foreach ($blogusers as $user) {
    echo '' . $user->user_email . '';
    }
    


Sunday, November 18, 2012

meta_query with comparison

Display posts of type 'my_custom_post_type', ordered by 'training_date', and filtered
  <?php
$todaysDate = date( 'd-m-Y' );
$args = array(
'post_type' => 'training',
'meta_key' => 'training_date',
'orderby' => 'training_date',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'training_date',
'value' => $todaysDate,
'compare' => '>=',
))

);
$query = new WP_Query($args);

Tuesday, November 13, 2012

How to hide Personal Options in WordPress’ User Profile


Adding this code to the functions.php of your wordpress theme
function hide_personal_options() {
?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#your-profile .form-table:first, #your-profile h3:first").remove();
});
</script>
<?php
}
add_action( 'personal_options', 'hide_personal_options');

Thursday, October 18, 2012

Add select menu to filter by custom field in admin

Adding this code to the functions.php of your wordpress theme will add a select menu with a list of all custom fields, just select the field you want to filter by and click the filter button.

add_filter( 'parse_query', 'ba_admin_posts_filter' );
add_action( 'restrict_manage_posts', 'ba_admin_posts_filter_restrict_manage_posts' );
function ba_admin_posts_filter( $query )
{
    global $pagenow;
    if ( is_admin() && $pagenow=='edit.php' && isset($_GET['ADMIN_FILTER_FIELD_NAME']) && $_GET['ADMIN_FILTER_FIELD_NAME'] != '') {
        $query->query_vars['meta_key'] = $_GET['ADMIN_FILTER_FIELD_NAME'];
    if (isset($_GET['ADMIN_FILTER_FIELD_VALUE']) && $_GET['ADMIN_FILTER_FIELD_VALUE'] != '')
        $query->query_vars['meta_value'] = $_GET['ADMIN_FILTER_FIELD_VALUE'];
    }
}
function ba_admin_posts_filter_restrict_manage_posts()
{
    global $wpdb;
    $sql = 'SELECT DISTINCT meta_key FROM '.$wpdb->postmeta.' ORDER BY 1';
    $fields = $wpdb->get_results($sql, ARRAY_N);
?>
<select name="ADMIN_FILTER_FIELD_NAME">
<option value=""><?php _e('Filter By Custom Fields', 'baapf'); ?></option>
<?php
    $current = isset($_GET['ADMIN_FILTER_FIELD_NAME'])? $_GET['ADMIN_FILTER_FIELD_NAME']:'';
    $current_v = isset($_GET['ADMIN_FILTER_FIELD_VALUE'])? $_GET['ADMIN_FILTER_FIELD_VALUE']:'';
    foreach ($fields as $field) {
        if (substr($field[0],0,1) != "_"){
        printf
            (
                '<option value="%s"%s>%s</option>',
                $field[0],
                $field[0] == $current? ' selected="selected"':'',
                $field[0]
            );
        }
    }
?>
</select> <?php _e('Value:', 'baapf'); ?><input type="TEXT" name="ADMIN_FILTER_FIELD_VALUE" value="<?php echo $current_v; ?>" />
<?php
}

Enable TinyMCE editor for post the_excerpt

Adding this code to the functions.php of your wordpress theme will add the TinyMCE editor to the post excerpt textarea.

function tinymce_excerpt_js(){ ?>
<script type="text/javascript">
        jQuery(document).ready( tinymce_excerpt );
            function tinymce_excerpt() {
                jQuery("#excerpt").addClass("mceEditor");
                tinyMCE.execCommand("mceAddControl", false, "excerpt");
            }
</script>
<?php }
add_action( 'admin_head-post.php', 'tinymce_excerpt_js');
add_action( 'admin_head-post-new.php', 'tinymce_excerpt_js');
function tinymce_css(){ ?>
<style type='text/css'>
            #postexcerpt .inside{margin:0;padding:0;background:#fff;}
            #postexcerpt .inside p{padding:0px 0px 5px 10px;}
            #postexcerpt #excerpteditorcontainer { border-style: solid; padding: 0; }
</style>
<?php }
add_action( 'admin_head-post.php', 'tinymce_css');
add_action( 'admin_head-post-new.php', 'tinymce_css');

Create most recent posts dashboard widget

Adding this code to the functions.php of your wordpress theme will create a new dashboard widget showing the five most recent posts.
function wps_recent_posts_dw() {
?>
   <ol>
     <?php
          global $post;
          $args = array( 'numberposts' => 5 );
          $myposts = get_posts( $args );
                foreach( $myposts as $post ) :  setup_postdata($post); ?>
                    <li> (<? the_date('Y / n / d'); ?>) <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
          <?php endforeach; ?>
   </ol>
<?php
}
function add_wps_recent_posts_dw() {
       wp_add_dashboard_widget( 'wps_recent_posts_dw', __( 'Recent Posts' ), 'wps_recent_posts_dw' );
}
add_action('wp_dashboard_setup', 'add_wps_recent_posts_dw' );

Remove admin color scheme options from user profile

Adding this codeto the functions.php of your wordpress theme will remove the admin color scheme from the user profile.

function admin_color_scheme() {
   global $_wp_admin_css_colors;
   $_wp_admin_css_colors = 0;
}
add_action('admin_head', 'admin_color_scheme');

Display EXIF metadata in media library admin column

Adding this snippet to the functions.php of your wordpress theme will create a new column within the media library that will display EXIF metadata. Including, (credit, camera, focal length, aperture, iso, shutter speed, timestamp, copyright).

add_filter('manage_media_columns', 'posts_columns_attachment_exif', 1);
add_action('manage_media_custom_column', 'posts_custom_columns_attachment_exif', 1, 2);
function posts_columns_attachment_exif($defaults){
    $defaults['wps_post_attachments_exif'] = __('EXIF');
    return $defaults;
}
function posts_custom_columns_attachment_exif($column_name, $id){
        if($column_name === 'wps_post_attachments_exif'){
           $meta = wp_get_attachment_metadata($id);
           if($meta[image_meta][camera] != ''){
           echo "CR:  ".$meta[image_meta][credit]."<hr />";
           echo "CAM:  ".$meta[image_meta][camera]."<hr />";
           echo "FL:  ".$meta[image_meta][focal_length]."<hr />";
           echo "AP:  ".$meta[image_meta][aperture]."<hr />";
           echo "ISO:  ".$meta[image_meta][iso]."<hr />";
           echo "SS:  ".$meta[image_meta][shutter_speed]."<hr />";
           echo "TS:  ".$meta[image_meta][created_timestamp]."<hr />";
           echo "C:  ".$meta[image_meta][copyright];
           }
    }
}

Remove menu items from 3.3 admin bar

Adding this codeto the functions.php of your wordpress theme will remove menu items from the wordpress 3.3 admin bar.
function wps_admin_bar() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_node('wp-logo');
    $wp_admin_bar->remove_node('about');
    $wp_admin_bar->remove_node('wporg');
    $wp_admin_bar->remove_node('documentation');
    $wp_admin_bar->remove_node('support-forums');
    $wp_admin_bar->remove_node('feedback');
    $wp_admin_bar->remove_node('view-site');
}
add_action( 'wp_before_admin_bar_render', 'wps_admin_bar' )

Monday, October 1, 2012

Prevent direct file access to functions.php

if (!empty($_SERVER['SCRIPT_FILENAME']) && 'functions.php' == basename($_SERVER['SCRIPT_FILENAME']))
{
die ('No access!');
}

Add rel=”lightbox” to all images embedded in a post

Adding this snippet to the functions.php of your wordpress theme will add a rel=”lightbox” attribute to all images embedded in your post. Also note that on line 05 you can change the rel=”lightbox” to whatever you need as some image viewer scripts will use rel=”thumbnail” for example. This snippet will also add the post title as the title attribute of the images anchor tag.
add_filter('the_content', 'my_addlightboxrel');
function my_addlightboxrel($content) {
       global $post;
       $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
       $replacement = '<a$1href=$2$3.$4$5 rel="lightbox" title="'.$post->post_title.'"$6>';
       $content = preg_replace($pattern, $replacement, $content);
       return $content;
}

Attach PDF files to post with custom metabox file selection

Adding this snippet to the functions.php of your wordpress theme will create a new metabox within your post editing screen with a select menu listing all PDF files. Adding the second snippet in your wordpress template in the location you wish to display the files URL.

add_action("admin_init", "pdf_init");
add_action('save_post', 'save_pdf_link');
function pdf_init(){
        add_meta_box("my-pdf", "PDF Document", "pdf_link", "post", "normal", "low");
        }
function pdf_link(){
        global $post;
        $custom  = get_post_custom($post->ID);
        $link    = $custom["link"][0];
        $count   = 0;
        echo '<div class="link_header">';
        $query_pdf_args = array(
                'post_type' => 'attachment',
                'post_mime_type' =>'application/pdf',
                'post_status' => 'inherit',
                'posts_per_page' => -1,
                );
        $query_pdf = new WP_Query( $query_pdf_args );
        $pdf = array();
        echo '<select name="link">';
        echo '<option class="pdf_select">SELECT pdf FILE</option>';
        foreach ( $query_pdf->posts as $file) {
           if($link == $pdf[]= $file->guid){
              echo '<option value="'.$pdf[]= $file->guid.'" selected="true">'.$pdf[]= $file->guid.'</option>';
                 }else{
              echo '<option value="'.$pdf[]= $file->guid.'">'.$pdf[]= $file->guid.'</option>';
                 }
                $count++;
        }
        echo '</select><br /></div>';
        echo '<p>Selecting a pdf file from the above list to attach to this post.</p>';
        echo '<div class="pdf_count"><span>Files:</span> <b>'.$count.'</b></div>';
}
function save_pdf_link(){
        global $post;
        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ return $post->ID; }
        update_post_meta($post->ID, "link", $_POST["link"]);
}
add_action( 'admin_head', 'pdf_css' );
function pdf_css() {
        echo '<style type="text/css">
        .pdf_select{
                font-weight:bold;
                background:#e5e5e5;
                }
        .pdf_count{
                font-size:9px;
                color:#0066ff;
                text-transform:uppercase;
                background:#f3f3f3;
                border-top:solid 1px #e5e5e5;
                padding:6px 6px 6px 12px;
                margin:0px -6px -8px -6px;
                -moz-border-radius:0px 0px 6px 6px;
                -webkit-border-radius:0px 0px 6px 6px;
                border-radius:0px 0px 6px 6px;
                }
        .pdf_count span{color:#666;}
                </style>';
}
function pdf_file_url(){
        global $wp_query;
        $custom = get_post_custom($wp_query->post->ID);
        echo $custom['link'][0];
}

 echo pdf_file_url();
My PDF File

Remove current theme from “Right Now” dashboard widget

add_filter( 'ngettext', 'wps_remove_theme_name' );
if(!function_exists('wps_remove_theme_name')) {
function wps_remove_theme_name($translated) {
     $translated = str_ireplace('Theme %1$s with',  '',  $translated );
     return $translated;
  }
}

Insert calendar into wp_nav_menu

Needed this for a recent project as a client wanted to display the wordpress calendar as a dropdown item within the menu. Add this snippet to the functions.php of your wordpress theme will add a new menu item to your wp_nav_menu that has a submenu calendar.
add_filter('wp_nav_menu_items','add_calendar', 10, 2);
function add_calendar($items, $args) {
    if( $args->theme_location == 'header-navigation' )
        return $items . '<li><a href="#">Calendar</a><ul class="sub-menu"><li>' . get_calendar(true,false) . '</li></ul></li>';
}

Shortcode for HTML5 audio in posts and pages

Adding this snippet to the functions.php of your wordpress theme will create a new shortcode for HTML5 audio. Just add the second snippet of shortcode to a post or page to add HTML5 audio.


function html5_audio($atts, $content = null) {
        extract(shortcode_atts(array(
                "src" => '',
                "autoplay" => '',
                "preload"=> 'true',
                "loop" => '',
                "controls"=> ''
        ), $atts));
        return '<audio src="'.$src.'" autoplay="'.$autoplay.'" preload="'.$preload.'" loop="'.$loop.'" controls="'.$controls.'" autobuffer />';
}
add_shortcode('audio5', 'html5_audio');

[audio5 src="http://your-site/videos/your-video.mp4" loop="true" autoplay="autoplay" preload="auto" loop="loop" controls=""]

Send email notification when user role changes

function user_role_update( $user_id, $new_role ) {
        $site_url = get_bloginfo('wpurl');
        $user_info = get_userdata( $user_id );
        $to = $user_info->user_email;
        $subject = "Role changed: ".$site_url."";
        $message = "Hello " .$user_info->display_name . " your role has changed on ".$site_url.", congratulations you are now an " . $new_role;
        wp_mail($to, $subject, $message);
}
add_action( 'set_user_role', 'user_role_update', 10, 2);

Send email notification when profile updates

function user_profile_update( $user_id ) {
        $site_url = get_bloginfo('wpurl');
        $user_info = get_userdata( $user_id );
        $to = $user_info->user_email;
        $subject = "Profile Updated: ".$site_url."";
        $message = "Hello " .$user_info->display_name . "\nYour profile has been updated!\n\nThank you for visiting\n ".$site_url."";
        wp_mail( $to, $subject, $message);
}
add_action( 'profile_update', 'user_profile_update', 10, 2);

Add class to next and previous post_link

I recently needed to use this for a theme I was building figured I would post the results up here for everyone. Adding this snippet to the functions.php of your wordpress theme will add a custom class to next and previous post_link.
function add_class_next_post_link($html){
    $html = str_replace('<a','<a class="next"',$html);
    return $html;
}
add_filter('next_post_link','add_class_next_post_link',10,1);
function add_class_previous_post_link($html){
    $html = str_replace('<a','<a class="prev"',$html);
    return $html;
}
add_filter('previous_post_link','add_class_previous_post_link',10,1);

Increase the excerpt field height

Adding this snippet to the functions.php of your wordpress theme will increase height of the excerpt field within your post editing screen.
add_action('admin_head', 'excerpt_textarea_height');
function excerpt_textarea_height() {
        echo'
        <style type="text/css">
                #excerpt{ height:500px; }
        </style>
        ';
}

Increase the excerpt field height

Adding this snippet to the functions.php of your wordpress theme will increase height of the excerpt field within your post editing screen.
add_action('admin_head', 'excerpt_textarea_height');
function excerpt_textarea_height() {
        echo'
        <style type="text/css">
                #excerpt{ height:500px; }
        </style>
        ';
}

Automatically wrap images in the_content with custom html

Adding this snippet to the functions.php of your wordpress theme will automatically wrap images in the_content with any custom HTML that you wish.
function filter_images($content){
    return preg_replace('/<img (.*) \/>\s*/iU', '<span class="className"><b><img \1 /></b></span>', $content);
}
add_filter('the_content', 'filter_images');

Remove admin color scheme options from user profile

Adding this snippet to the functions.php of your wordpress theme will remove the admin color scheme from the user profile.

function admin_color_scheme() {
   global $_wp_admin_css_colors;
   $_wp_admin_css_colors = 0;
}
add_action('admin_head', 'admin_color_scheme');

Disable the help menu for admin only

Adding this snippet to the functions.php of your wordpress theme will display the help menu for the admin only.

function hide_help() {
    if(!is_admin()){
    echo '<style type="text/css">
            #contextual-help-link-wrap { display: none !important; }
          </style>';
    }
}
add_action('admin_head', 'hide_help');

Display EXIF metadata in media library admin column

For anyone that uses wordpress for photography you should find this snippet useful. Adding this snippet to the functions.php of your wordpress theme will create a new column within the media library that will display EXIF metadata. Including, (credit, camera, focal length, aperture, iso, shutter speed, timestamp, copyright).

add_filter('manage_media_columns', 'posts_columns_attachment_exif', 1);
add_action('manage_media_custom_column', 'posts_custom_columns_attachment_exif', 1, 2);
function posts_columns_attachment_exif($defaults){
    $defaults['wps_post_attachments_exif'] = __('EXIF');
    return $defaults;
}
function posts_custom_columns_attachment_exif($column_name, $id){
        if($column_name === 'wps_post_attachments_exif'){
           $meta = wp_get_attachment_metadata($id);
           if($meta[image_meta][camera] != ''){
           echo "CR:  ".$meta[image_meta][credit]."<hr />";
           echo "CAM:  ".$meta[image_meta][camera]."<hr />";
           echo "FL:  ".$meta[image_meta][focal_length]."<hr />";
           echo "AP:  ".$meta[image_meta][aperture]."<hr />";
           echo "ISO:  ".$meta[image_meta][iso]."<hr />";
           echo "SS:  ".$meta[image_meta][shutter_speed]."<hr />";
           echo "TS:  ".$meta[image_meta][created_timestamp]."<hr />";
           echo "C:  ".$meta[image_meta][copyright];
           }
    }
}

Disable dragging of metaboxes within admin

Adding this snippet to the functions.php of your wordpress theme will disable all dragging of metaboxes within the admin. Please note that this includes dashboard widgets as well.

function disable_drag_metabox() {
    wp_deregister_script('postbox');
}
add_action( 'admin_init', 'disable_drag_metabox' );

Include external file shortcode

function show_file_func( $atts ) {
  extract( shortcode_atts( array(
    'file' => ''
  ), $atts ) );
  if ($file!='')
    return @file_get_contents($file);
}
add_shortcode( 'show_file', 'show_file_func' );

[show_file file="http://www.mysite.com/somefile.html"]

Remove inline style from gallery shortcode

The WordPress gallery shortcode will add some inline CSS to your document however if I’m like many of you, I would rather use my own. Adding the above snippet to the functions.php of your wordpress theme will disable the default gallery styles from being inserted into the page.
add_filter( 'use_default_gallery_style', '__return_false' );

Highlight keywords in search results within the_excerpt and the_title

You can add to the functions.php of your wordpress theme to highlight keywords in search results for the_excerpt and the_title
function wps_highlight_results($text){
     if(is_search()){
     $sr = get_query_var('s');
     $keys = explode(" ",$sr);
     $text = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="search-excerpt">'.$sr.'</strong>', $text);
     }
     return $text;
}
add_filter('the_excerpt', 'wps_highlight_results');
add_filter('the_title', 'wps_highlight_results');

Remove unneeded images / thumbnail sizes

Adding some or all of these lines of code to the functions.php of your wordpress theme will effectively remove some of the default images sizes that may be unneeded. Make sure to include both the _w _h for width and height,

   update_option( 'thumbnail_size_h', 0 );
    update_option( 'thumbnail_size_w', 0 );
    update_option( 'medium_size_h', 0 );
    update_option( 'medium_size_w', 0 );
    update_option( 'large_size_h', 0 );
    update_option( 'large_size_w', 0 );

Allow more HTML tags in the editor

By default the wordpress editor does not allow some tags and will strip them out. Adding this snippet to the functions.php of your wordpress theme will enable you to use HTML tags like iframe, name, class etc…

function jb_change_mce_options($initArray) {
        $ext = 'pre[id|name|class|style],iframe[align|longdesc| name|width|height|frameborder|scrolling|marginheight| marginwidth|src]';
        if ( isset( $initArray['extended_valid_elements'] ) ) {
                $initArray['extended_valid_elements'] .= ',' . $ext;
        } else {
                $initArray['extended_valid_elements'] = $ext;
        }
        return $initArray;
}
add_filter('tiny_mce_before_init', 'jb_change_mce_options');

Adjust default sizes for embedded content

Adding this snippet to the functions.php of your wordpress theme will let you update the default embed sizes
function wps_embed_size($embed_size){
    if(is_single()){
        $embed_size['height'] = 240;
        $embed_size['width']  = 380;
    }
    return $embed_size;
}
add_filter('embed_defaults', 'wps_embed_size');

Hide update nag within the admin

Adding this snippet to the functions.php of your wordpress theme will hide the update nag within the wordpress admin.

function remove_upgrade_nag() {
   echo '<style type="text/css">
           .update-nag {display: none}
         </style>';
}
add_action('admin_head', 'remove_upgrade_nag');

Check if post / page has a gallery

Adding this snippet to your wordpress theme will let you check to see if a post contains the gallery shortcode. Add this code to the single.php template of your wordpress theme inside the loop.
if (strpos($post->post_content,'[gallery') === false){
  echo 'no gallery';
}else{
  echo 'has gallery';
}

Add custom field automatically when post or page is publish

Adding this snippet to the functions.php of your wordpress theme will add a custom field to a post or page when published. Don’t forget to update the FIELD_NAME and the CUSTOM VALUE.
add_action('publish_page', 'add_custom_field_automatically');
add_action('publish_post'. 'add_custom_field_automatically');
function add_custom_field_automatically($post_ID) {
    global $wpdb;
    if(!wp_is_post_revision($post_ID)) {
        add_post_meta($post_ID, 'FIELD_NAME', 'CUSTOM VALUE', true);
    }
}

Facebook open graph snippet to set default image

Adding this snippet to the functions.php of your wordpress theme will allow you to specify Facebook Open Graph information on your WordPress posts. Allowing you to specify which image should be displayed when sharing your article on Facebook among other things.
function diww_facebook_image() {
                echo '<meta property="fb:admins" content="ADMIN_ID" />';
                echo '<meta property="og:title" content="' . get_the_title() . '" />';
                echo '<meta property="og:site_name" content="' . get_bloginfo('name') . '" />';
        global $post;
        if ( is_singular() ) { // only if a single post or page
                echo '<meta property="og:type" content="article" />';
                echo '<meta property="og:url" content="' . get_permalink() . '" />';
        if (has_post_thumbnail( $post->ID )) { // use featured image if there is one
                $feat_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
                echo '<meta property="og:image" content="' . esc_attr( $feat_image[0] ) . '" />';
         }else{ // use site logo in case no featured image
                echo '<meta property="og:image" content="http://yourdomain.com/logo.png" />';
         }
        }
        if ( is_home() ) { // for homepage only
                echo '<meta property="og:type" content="website" />';
                echo '<meta property="og:url" content="' . get_bloginfo('url') . '" />';
                echo '<meta property="og:image" content="http://yourdomain.com/logo.png" />';
        }
}
add_action( 'wp_head', 'diww_facebook_image' );

Hide post view and post preview admin buttons

Ever wanted to remove “preview & view” options from the new post and post edit admin screens. Add this code functions.php of your wordpress theme and don’t forget to update the post type array. Enter any post type you would like to remove the "view and preview" buttons from "custom post type, post, page".
function posttype_admin_css() {
    global $post_type;
    $post_types = array(
                        /* set post types */
                        'post_type_name',
                        'post',
                        'page',
                  );
    if(in_array($post_type, $post_types))
    echo '';
}
add_action( 'admin_head-post-new.php', 'posttype_admin_css' );
add_action( 'admin_head-post.php', 'posttype_admin_css' );

    echo
'<style type="text/css">#post-preview, #view-post-btn{display: none;}</style>'

Change default "Enter title here" text within post title input field

paste the code into your functions.php file.
function title_text_input( $title ){
     return $title = 'Enter new title';
}
add_filter( 'enter_title_here', 'title_text_input' );

Disable theme switching

Paste the following code into functions.php
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]);
  unset($submenu['themes.php'][15]);
 }
}

Remove menu items from WordPress admin bar

Paste this code into your theme functions.php file to remove menus from the admin bar.
function wps_admin_bar() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('wp-logo');
    $wp_admin_bar->remove_menu('about');
    $wp_admin_bar->remove_menu('wporg');
    $wp_admin_bar->remove_menu('documentation');
    $wp_admin_bar->remove_menu('support-forums');
    $wp_admin_bar->remove_menu('feedback');
    $wp_admin_bar->remove_menu('view-site');
}
add_action( 'wp_before_admin_bar_render', 'wps_admin_bar' );

How to execute shortcodes inside custom fields

By default, WordPress do not allows shortcodes to be executed inside custom fields. If for some reason you need to be able to execute a shortcode inside a specific custom field, here is an easy way to do it.

Just put this code into whatever page you are displaying the results of the shortcode, and change the your_custom_field_here to the name of your custom field.

<?php echo apply_filters('the_content', get_post_meta($post->ID, 'your_custom_field_here', true)); ?>

Monday, September 24, 2012

How to Disable Plugin and Theme Update and Installation on WordPress

Add this constant to your wp-config.php file to disable plugin and theme updates/installation:

define('DISALLOW_FILE_MODS',true);

Monday, September 3, 2012

Get the page ID by the page name

function get_id_by_post_name($post_name)
{
global $wpdb;
$id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$post_name."' AND post_status='publish'");
return $id;


 

Saturday, September 1, 2012

How To Create A Custom Page Template In WordPress

To create a WordPress Page Template, you’ll need to use your text editor. Go to the directory on your server where you installed WordPress, and then navigate to the directory of your theme. Usually that looks something like this: “/wp-content/themes/default” where “default” is your theme name.

That’s where you will create your custom page template file. Create a file called “cover_page.php” and add the following code to it:
<?php /* Template Name: Cover Page */ ?>
<?php get_header(); ?>
Here's my cover page!
<?php get_footer(); ?>


<?php if (is_page_template('cover_page.php') ) 
{ ?>    <p>Apples</p>    <?php } 
else { ?>    <p>Oranges</p>    <?php } ?>

Tuesday, August 28, 2012

How to automatically add rel=”lightbox” to all images embedded in a post

The well known jQuery plugin Lightbox is a very simple way to open images in fancy full-screen boxes. It is very easy to use, but you have to add a rel=”lightbox” attribute to each image you want to open in a lightbox. Here’s a cool code snippet to automatically add the rel=”lightbox” attribute to all images embedded in your posts.
 
Paste the following code snippet in your functions.php file. 
Once done, a rel="lightbox" attribute will be automatically 
added to all images embedded in a post.
 
 function my_addlightboxrel($content) {   
      global $post;
      $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";         
  $replacement = '<a$1href=$2$3.$4$5 rel="lightbox" 
                title="'.$post->post_title.'"$6>';        
  $content = preg_replace($pattern, $replacement, $content);       
  return $content;
  }
add_filter('the_content', 'my_addlightboxrel');

How to easily add shortcuts to WordPress toolbar

As with many things, WordPress makes it easy to customize the Toolbar, using the add_node() functions. In this recipe, I’m going to show you how to add a shortcut to WordPress toolbar.

function custom_toolbar_link($wp_admin_bar) {
$args = array( 'id' => Help,
'title' => 'Help',
'href' => 'http://h20bikash.blogspot.com/',
'meta' => array( 'class' =>Help,
'title' => 'Help' ) );
$wp_admin_bar->add_node($args);
}
add_action('admin_bar_menu', 'custom_toolbar_link', 999);

How to add .pdf support to the WordPress media manager

By default, the built-in WordPress media manager allows you to filter media by three types: images, audio and video. But if you work a lot with .pdf files, you may need to add an option to filter .pdf files from the media manager. Here is a simple code snippet to do it.

Paste this code into your functions.php file. Save the file, and you're done.
 
function modify_post_mime_types( $post_mime_types ) {
// select the mime type, here: 'application/pdf'
// then we define an array with the label values
$post_mime_types['application/pdf'] = array( __( 'PDFs' ), __( 'Manage PDFs' ), _n_noop( 'PDF (%s)', 'PDFs (%s)' ) );
// then we return the $post_mime_types variable
return $post_mime_types;
} // Add Filter Hook
add_filter( 'post_mime_types', 'modify_post_mime_types' );

How to automatically empty trash on a daily basis

Simply open your wp-config.php file (Located at the root of your WordPress install) and add the following line of code:

define('EMPTY_TRASH_DAYS', 1);

How to remove the url field from WordPress comment form

In some cases, you may not need or want that people who comment your posts can leave their website url. Here is a simple code snippet to remove the url field from WordPress comment form.

Paste the code below into your functions.php file. Once saved, the url field will be removed from your comment form.
 
function remove_comment_fields($fields) {  
    unset($fields['url']); 
     return $fields;  
}
  add_filter('comment_form_default_fields','remove_comment_fields');

Monday, August 13, 2012

Complete flexible Project Task Management System


This WordPress plugin is a complete flexible Project Task Management System. It's a very easy to use, but yet a powerful plugin. 

Using jQuery UI datepicker with WordPress custom post meta

if(is_admin()) {
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_script('custom-js', get_template_directory_uri().'/js/custom-js.js');
wp_enqueue_style('jquery-ui-custom', get_template_directory_uri().'/css/jquery-ui-custom.css');
}
function my_admin_footer() {
?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#registration_lastdate').datepicker({
dateFormat : 'd M yy'
});

jQuery('#training_date').datepicker({
dateFormat : 'd M yy'
});
});
</script>
<?php
}
add_action('admin_footer', 'my_admin_footer');

Monday, August 6, 2012

Custom page links without or with a list


$args = array(
'orderby' => 'post_title',
'order' => 'ASC',
'post_type' => 'page',
//'post_parent'=> '35',
'caller_get_posts' => 1
);

$pages = get_posts($args);
foreach($pages as $page) {
$out .= '<div class="bluecategory_wrapper">';
$out .= '<a href="'.get_permalink($page->ID).'" title="'.wptexturize($page->post_title).'">
<div class="bluecategory_left"></div><div class="bluecategory_bg">'.wptexturize($page->post_title).'</div>
<div class="bluecategory_right"></div></a></div>';
}
$out = $out;
echo $out;

Thursday, August 2, 2012

Change WordPress “from” email header

By default, the default WordPress email adress looks like WordPress@yoursitename.com. Want to use your real email and username instead?

function res_fromemail($email) {
$wpfrom = get_option('admin_email');
return $wpfrom;
}
function res_fromname($email){
$wpfrom = get_option('blogname');
return $wpfrom;
}
add_filter('wp_mail_from', 'res_fromemail');
add_filter('wp_mail_from_name', 'res_fromname');

Sending users email on post publish

function send_email_publish_post($post_ID) 
{ global $wpdb; $permalink = get_permalink( $post_ID ); 
 $query = "SELECT * FROM {$wpdb->users}"; 
 $users = $wpdb->get_results( $query);
 foreach($users as $user) 

$permalink = get_permalink( $post_ID ); 
$message="A New Post published. You can view the post details from the link ".$permalink." This is an auto generated notification. Please do not reply to it."; 
wp_mail( $user->user_email, "A New Post published", $message); 
 } 
return $post_ID; 

add_action('wp_publish_post','send_email_publish_post');

Wednesday, August 1, 2012

add theme support

add_theme_support( $feature );
$feature
  • 'post-formats'
  • 'post-thumbnails'
  • 'custom-background'
  • custom-header'
  • 'automatic-feed-links'
  • 'menus' 

Enabling Support for Post Thumbnails

add_theme_support( 'post-thumbnails' ); 

Default Usage 

if ( has_post_thumbnail() ) { the_post_thumbnail(); } 

Thumbnail Sizes 

the_post_thumbnail(); // without parameter -> Thumbnail the_post_thumbnail('thumbnail'); // Thumbnail (default 150px x 150px max) the_post_thumbnail('medium'); // Medium resolution (default 300px x 300px max) the_post_thumbnail('large'); // Large resolution (default 640px x 640px max) the_post_thumbnail( array(100,100) ); // Other resolutions 

Example of a new Post Thumbnail size named "category-thumb". 

add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height)
Here is an example of how to use this new Post Thumbnail size in theme template files. the_post_thumbnail( 'category-thumb' );

Custom Backgrounds

add_theme_support( 'custom-background' ); 

Note that you can add default arguments using:
$defaults = array( 'default-color' => '', 
'default-image' => '', 
'wp-head-callback' => '_custom_background_cb', 
'admin-head-callback' => '', 'admin-preview-callback' => '' ); 

add_theme_support( 'custom-background', $defaults ); 

Example  
An example using default '#000000' background color with 'background.jpg' background image:

$args = array( 'default-color' => '000000',
 'default-image' => get_template_directory_uri() . '/images/background.jpg', ); 
add_theme_support( 'custom-background', $args );

Sunday, July 22, 2012

Customising the HTML of the WordPress search form

Changing the markup used for the global search form (which is normally displayed in the header or at the top of the sidebar) is pretty straightforward .

Using a custom function

Yet another option is to create a custom function in your functions.php file:


function custom_search_form( $form ) { 
     $form = '<form method="get" id="quick-search" action="/" >';
     $form .= '<div><label for="s">Search this site for:</label>';
     $form .= '<input type="text" value="' . get_search_query() . '" name="s" id="s" />';
     $form .= '<input type="submit" value="Search" />';     
     $form .= '</div>';      $form .= '</form>';    
return $form;
  }
  add_filter( 'get_search_form', 'custom_search_form' );
 
 
In the file that contains your global search form
 (typically header.php or sidebar.php), replace <?php get_search_form(); ?> 

Wednesday, July 18, 2012

Protect your WordPress site with .htacces

The typical WordPress .htaccess file looks similar:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Protect wp-config.php

In your .htaccess add the following to prevent any access to the wp-config.php file:

<Files wp-config.php>
order allow,deny
deny from all
</Files>

Admin access from your IP only

You can limit who can access your admin folder by IP address, to do this you would need to create a new .htaccess file in your text editor and upload to your wp-admin folder.
order deny,allow
allow from 202.090.21.1 (replace with your IP address)
deny from all
 

Protect .htaccess

This snippet basically stops anyone viewing any file on your site that begins with "hta", this will protect it and make it somewhat safer.


<Files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</Files>
 

Stop Spammers

Like hotlinking, spammers are notorious to use up your site’s resources. There are a number of ways to identify a potential spammer. One of them is to detect requests with ‘no referrer’. Spammers use bots to post comments on blogs and they come from ‘nowhere’. Add these lines to stop the spammers.

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

If you want a list of bad bots / User Agents to block then scroll to the end of this file.

RewriteCond %{HTTP_USER_AGENT} (libwww-perl|wget|python|nikto|curl|scan|java|winhttp|clshttp|loader) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} (%0A|%0D|%27|%3C|%3E|) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} (;|<|>|'|"|\)|\(|%0A|%0D|%22|%27|%28|%3C|%3E|).*(libwww-perl|wget|python|nikto|curl|scan|java|winhttp|HTTrack|clshttp|archiver|loader|email|harvest|extract|grab|miner) [NC,OR]
RewriteCond %{THE_REQUEST} \?\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} \/\*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} etc/passwd [NC,OR]
RewriteCond %{THE_REQUEST} cgi-bin [NC,OR]
RewriteCond %{THE_REQUEST} (%0A|%0D|\\r|\\n) [NC,OR]
RewriteCond %{REQUEST_URI} owssvr\.dll [NC,OR]
RewriteCond %{HTTP_REFERER} (%0A|%0D|%27|%3C|%3E|) [NC,OR]
RewriteCond %{HTTP_REFERER} \.opendirviewer\. [NC,OR]
RewriteCond %{HTTP_REFERER} users\.skynet\.be.* [NC,OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=http:// [OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=(\.\.//?)+ [OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=/([a-z0-9_.]//?)+ [NC,OR]
RewriteCond %{QUERY_STRING} \=PHP[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} [NC,OR]
RewriteCond %{QUERY_STRING} (\.\./|\.\.) [OR]
RewriteCond %{QUERY_STRING} ftp\: [NC,OR]
RewriteCond %{QUERY_STRING} http\: [NC,OR]
RewriteCond %{QUERY_STRING} https\: [NC,OR]
RewriteCond %{QUERY_STRING} \=\|w\| [NC,OR]
RewriteCond %{QUERY_STRING} ^(.*)/self/(.*)$ [NC,OR]
RewriteCond %{QUERY_STRING} ^(.*)cPath=http://(.*)$ [NC,OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*embed.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^e]*e)+mbed.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*object.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^o]*o)+bject.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*iframe.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^i]*i)+frame.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [NC,OR]
RewriteCond %{QUERY_STRING} base64_(en|de)code[^(]*\([^)]*\) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} ^.*(\[|\]|\(|\)|<|>|%3c|%3e|%5b|%5d).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(\x00|\x04|\x08|\x0d|\x1b|\x20|\x3c|\x3e|\x5b|\x5d|\x7f).* [NC,OR]
RewriteCond %{QUERY_STRING} (NULL|OUTFILE|LOAD_FILE) [OR]
RewriteCond %{QUERY_STRING} (\./|\../|\.../)+(motd|etc|bin) [NC,OR]
RewriteCond %{QUERY_STRING} (localhost|loopback|127\.0\.0\.1) [NC,OR]
RewriteCond %{QUERY_STRING} (<|>|'|%0A|%0D|%27|%3C|%3E|) [NC,OR]
RewriteCond %{QUERY_STRING} concat[^\(]*\( [NC,OR]
RewriteCond %{QUERY_STRING} union([^s]*s)+elect [NC,OR]
RewriteCond %{QUERY_STRING} union([^a]*a)+ll([^s]*s)+elect [NC,OR]
RewriteCond %{QUERY_STRING} (;|<|>|'|"|\)|%0A|%0D|%22|%27|%3C|%3E|).*(/\*|union|select|insert|drop|delete|update|cast|create|char|convert|alter|declare|order|script|set|md5|benchmark|encode) [NC,OR]
RewriteCond %{QUERY_STRING} (sp_executesql) [NC]
RewriteRule ^(.*)$ - [F,L]

You can install BulletProof security protection against: XSS, RFI, CRLF, CSRF, Base64, Code Injection and SQL Injection hacking

Tuesday, July 17, 2012

Adding your own News Feed to the Wordpress Admin Dashboard


<?php
  function wp_admin_dashboard_add_news_feed_widget() {
  global $wp_meta_boxes;

// Our new dashboard widget

  wp_add_dashboard_widget( 'dashboard_gravfx_feed', 'News from h20bikash.blogspot.com', 'dashboard_gravfx_feed_output' );

  }

  add_action('wp_dashboard_setup', 'wp_admin_dashboard_add_news_feed_widget');

function dashboard_gravfx_feed_output() {
  echo '<div>';
  wp_widget_rss_output(array(
  'url' => 'http://h20bikash.blogspot.com/atom.xml',
  'title' => 'Latest news from drikict.net',
  'items' => 2,
  'show_summary' => 1,
  'show_author' => 0,
  'show_date' => 1

  ));
  echo "</div>";

  }
  ?>

Removing Meta Generator WordPress

<meta name="generator" content="WordPress 3.4.1" />
 
<?php

  function remove_generator() {

  return '';

  }
add_filter('the_generator', 'remove_generator'); ?>

Sunday, July 8, 2012

Create a word count limit PHP function

<?php

function limit_words($description, $count) {

$words = explode(" ", $description); // explode our string by spaces and add to our $words variable as an array

$chunk = array_chunk($words, $count); // split our $words array into a multi-dimensional array, by our count

$description = implode(" ", $chunk[0]); // convert the $chunk array into a string, seperating words by spaces

return $description; // return our $description string with correct word count

}
$wordcount=$this->limit_words($home_news->intro,15);
?>

Sunday, July 1, 2012

Show Children Categories from Parent Category

$category = get_the_category();
$args = array(
'type'                     => 'post',
'child_of'                 => $category[1]->term_id,
'parent'                   => '',
'orderby'                  => 'name',
'order'                    => 'ASC',
'hide_empty'               => 1,
'hierarchical'             => 1,
'exclude'                  => '',
'include'                  =>'' ,
'number'                   =>'',
'taxonomy'                 => 'category',
'pad_counts'               => false );




        $categories = get_categories($args);
        echo "<pre>";
        print_r($categories);
        echo "<pre>";

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

?>

Monday, May 21, 2012

wordpress Custom Post Types

By default, WordPress offers two different types of posts for content. First, you 
have the traditional “post”, used most often for what WordPress is known best for
 – blogging. Second, you have “pages”. Each of these, as far as WordPress is 
concerned, is a type of “post”. A custom post type is a type of post that you 
define. 

add_action('init', 'register_news, 1); // Set priority to avoid plugin conflicts
 
    function register_news() { // A unique name for our function
        $labels = array( // Used in the WordPress admin
                'name' => _x('News & Event', 'post type general name'),
                'singular_name' => _x('event', 'post type singular name'),
                'add_new' => _x('Add New', 'Event'),
                'add_new_item' => __('Add New Event'),
                'edit_item' => __('Edit Event'),
                'new_item' => __('New Event'),
                'view_item' => __('View Event '),
                'search_items' => __('Search Event'),
                'not_found' =>  __('Nothing found'),
                'not_found_in_trash' => __('Nothing found in Trash')
        );
        $file_dir=get_bloginfo('template_directory');
        $args = array(
                'labels' => $labels, // Set above
                'public' => true, // Make it publicly accessible
                'hierarchical' => false, // No parents and children here
                'menu_position' => 5, // Appear right below "Posts"
                'has_archive' => 'event', // Activate the archive
                'menu_icon' => $file_dir.'/images/faq.png',
                'supports' => array('title','author','editor','comments','thumbnail','custom-fields'),
        );
        
        register_taxonomy("catalog", array("event"), array("hierarchical" => true, "label" => "Categories", "singular_label" => "event", "rewrite" => true));
        register_post_type( 'event', $args ); // Create the post type, use options above
 }
?> 

Remove wordpress admin dashboard widgets






function pathshala_remove_dashboard_widgets() {

    // Globalize the metaboxes array, this holds all the widgets for wp-admin
     global $wp_meta_boxes;

    // Remove the incomming links widget
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);   
//$wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']
    // Remove right now
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
    //unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
}

// Hoook into the 'wp_dashboard_setup' action to register our function
add_action('wp_dashboard_setup', 'pathshala_remove_dashboard_widgets' );

?>

Header Image Nivo Slider wp plugin


You can easily build a slider of your header images. This plugin also adds an option to remove your uploaded header images right from the Header options page.
As of now it only supports Nivo Slider.

Download: 
Header Image Slider

Thursday, May 10, 2012

Update data in wordpress table

$wpdb->update('wp_profile_visitor', array('count' => $countvisit, 'visitor_name' => $final_current_user->display_name), array('profile_id' =>$final_curauth->ID, 'visitor_id' =>$final_current_user->ID ));

wp_profile_visitor is table name.
array('count' => $countvisit, 'visitor_name' => $final_current_user->display_name) is updated data and
array('profile_id' =>$final_curauth->ID, 'visitor_id' =>$final_current_user->ID ) where condition.
 



Insert data in wordpress table

$wpdb->insert('wp_profile_visitor', array(
            'profile_id' => $final_curauth->ID,
            'visitor_id' => $final_current_user->ID,
            'visitor_name' => $final_current_user->display_name,
            'visitor_nicename' => $final_current_user->user_nicename,           
            ) );
"wp_profile_visitor" is table name
"profile_id" is table field name and $final_curauth->ID is dynamic data..

You can also insert in  another format. I have given a example please see  http://h20bikash.blogspot.com/2012/05/inserting-into-data-in-wordpress.html


Sunday, May 6, 2012

Inserting Into Data in WordPress database

To perform an insert, we can use the insert method: 
 $wpdb->$wpdb->insert( $table, $data, $format ); ?> 
 Insert a row into a table.
$wpdb->insert(
'rz_tblsubmit',
array(
'id' => '',
'titleofevent' => $_POST["title"],
'typeofevent' => $_POST["type"],
'organisation' => $_POST["organisation"],
'website' => $_POST["website"],
'description' => $_POST["description"],
'startdate' => $_POST["start_date"]."-".$_POST["start_time"],
'enddate' => $_POST["end_date"],
'entryprice' => $_POST["entry_price"],
'venueaddress' => $_POST["venue_address"],
'venuecountry' => $_POST["venue_country"],
'postcode' => $_POST["venue_postcode"],
'venuewebsite' => $_POST["venue_website"],
'contact' => $_POST["contact"],
'contactemail' => $_POST["contact_email"],
'contactphone' => $_POST["contact_phone"],
'wessage' => $_POST["message"],

),
array(
'',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%d',
'%s',
'%s',
'%s',
'%d',
'%s'

)
); ?>

Saturday, May 5, 2012

wordpress upload http error...!!!

function push_the_max(){
@ini_set( 'upload_max_size' , '100M' );
@ini_set( 'post_max_size', '105M');
@ini_set( 'max_execution_time', '300' );
}
add_action('init','push_the_max');

Wednesday, February 22, 2012

How to Exclude Pages from WordPress Search Results

function SearchFilter($query) { 
 if ($query->is_search) { 
 $query->set('post_type', 'post'); 
 }  return $query; 
 }  
  add_filter('pre_get_posts','SearchFilter');

Thursday, January 26, 2012

wp mail content type

<?php

add_filter('wp_mail_content_type','set_content_type');

function set_content_type($content_type){

return 'text/html';

}

?>