Hello Friends!

Hope you all are doing well.

If you want to disable the theme and plugin file editor from admin then don’t worry, i am here only for you :)

add the give code below  in wp-config file.

Basically this is very important for make your site more secure because generally most of people have used their UN-secure admin password , they have used password like “admin123″, “admin”,”admin@123″ and site hacker can easily your hack your admin password.

After hack the admin access he can changes anything in theme files  as well plugin files also and after done anything by hacker in files your site will be down. So don’t waste your time just add this code in your wp-config.php files

define( 'DISALLOW_FILE_EDIT', true );

Enjoy Code!

Hello Friends!

Hope you are doing well :)

I am here going to tell you some useful script for manage .htaccess file of your website.

  1. First of all you have need to check the  RewriteEngine is “on” or not in your htaccess file. if not then add the given code in top of the file
    RewriteEngine on
  2. How redirect site form NON-WWW to WWW url using htaccess?
    ##non-www to www
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
  3. How redirect site from WWW to NON-WWW url using htaccess?
    pre>## www to non-www
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule ^(.*)$ %{HTTP_HOST}$1 [C]
    RewriteRule ^www\.(.*)$ http://$1 [L,R=301]
  4. How create a single line code for read “.php” files as “.html using htaccess”?
    ## Add rewrite rule for call ".php" pages as ".html" pages
    # Example about-us.php file will be read as about-us.html
    Options +Indexes
    Options +FollowSymlinks
    RewriteRule ^([^.]+)\.html$ $1.php [L]
  5. How remove the index.php OR index.html from the site url using htaccess
    RewriteRule ^(.*)index\.(htm|html|php)$ http://%{HTTP_HOST}/$1 [R=301,L]
  6. How redirect Old Site to new New Site?
      RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
      RewriteCond %{HTTP_HOST} ^www.olddomain.com$
      RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]

Enjoy Code!

Hello Friends!

Hope you all are doing well :)

In my last post i have explain to you  all my friends a way for  “add a new “Custom Fields” on taxonomy/category page

http://raghunathgurjar.wordpress.com/2014/04/14/how-add-new-custom-fields-on-taxonomycategory-page-using-hooks-wordpress/

Now i am going to explain you for show the newly added custom field and its value on “Category List” page

custom-filed

For do that you have need only to use my code and follow steps give below:

Steps.1 – First of all you have need to add given code in your theme function file

//For add the new fields 
function my_column_header($columns)
{
    $columns['customval'] = __('Custom Field');
    return $columns;
}
add_filter('manage_edit-category_columns', 'my_column_header', 10, 2);

After add this code in your theme function file you will be see the custom fields title

title

Step.2 – Now you have need to add the given code in your theme function for get the custom field value

//Get the custom field value
function my_column_value($empty = '', $custom_column, $term_id)
{
    //Category custom field
   $term_meta = get_option( "taxonomy_term_$term_id" ); 
   $CustomValue=$term_meta['wpsc_product_category_catsortby'] ? $term_meta['category_customval'] : '0';
       
 return $CustomValue;
}
add_filter('manage_category_custom_column', 'my_column_value', 10, 3);

 

That’s All :)

Enjoy Code! | Raghunath Blog

 

Hello Friends!

Facebook has done some changes in his API so that’s why we are unable to define the “Share Image” in facebook share window in a way that was given on my last post http://raghunathgurjar.wordpress.com/2013/08/21/how-add-thumb-image-in-custom-facebook-share-link-window/ but don’t worry i am here only for you :)

Using “OG Meta Tags” we can define facebook share window content, for more details about “OG Meta Tags” you can visit facebook official page https://developers.facebook.com/docs/plugins/checklist/

you have need to add the og meta tags in head section (between <head></head> tags) in given format :

<meta property="og:title" content="Your Title">

<meta property="og:image" content="Your image path">

<meta property="og:description" content="Your description">

After add the OG meta tag , you have need to add your share url (url that you want share) like this https://www.facebook.com/sharer/sharer.php?u=your-site-url

For Example :Share My Blog

That’s All :)
Enjoy Code! | Raghunath Blog

Hello Friends!

In admin if you want to add a new “Custom Fields” on taxonomy/category page without any changes in wordpress core files then don’t worry :) , you can add your new custom field using hooks.

Screenshot

Just add given code in your theme function file.

// A callback function to add a custom field to our "custom" taxonomy  
function custom_taxonomy_custom_fields($tag) {  
   // Check for existing taxonomy meta for the term you're editing  
    $t_id = $tag->term_id; // Get the ID of the term you're editing  
    $term_meta = get_option( "taxonomy_term_$t_id" ); // Do the check  


echo '<tr class="form-field">  
    <th scope="row" valign="top">  
        <label for="custom_id"><?php _e('Custom Field');?></label>  
    </th>  
    <td>  
        <input type="text" name="term_meta[custom_catsortby]" id="term_meta[custom_catsortby]" size="25" style="width:60%;" value="<?php echo $term_meta['custom_catsortby'] ? $term_meta['custom_catsortby'] : '';?>"><br />  
        <span class="description"><?php _e('The new Custom Field'); ?></span>  
    </td>  
</tr>';   
}
// Add the fields to the "custom" taxonomy, using our callback function  
add_action( 'custom_edit_form_fields', 'custom_taxonomy_custom_fields', 10, 2 );  

/*  Save the custom field value into database */

// A callback function to save our extra taxonomy field(s)  
function save_taxonomy_custom_fields( $term_id ) {  
    if ( isset( $_POST['term_meta'] ) ) {  
        $t_id = $term_id;  
        $term_meta = get_option( "taxonomy_term_$t_id" );  
        $cat_keys = array_keys( $_POST['term_meta'] );  
            foreach ( $cat_keys as $key ){  
            if ( isset( $_POST['term_meta'][$key] ) ){  
                $term_meta[$key] = $_POST['term_meta'][$key];  
            }  
        }  
        //save the option array  
        update_option( "taxonomy_term_$t_id", $term_meta );  
    }  
}  
// Save the changes made on the "custom" taxonomy, using our callback function  
add_action( 'edited_custom', 'save_taxonomy_custom_fields', 10, 2 );  

//For retrieve the value in front-end
$newterm_id='put here term id';
$term_meta = get_option( "taxonomy_term_$newterm_id" ); // Do the check  
echo "<b>Custom Field Value:</b> ".$term_meta['custom_catsortby'];

That’s All :)

Enjoy Code! || Raghunath Blog

Hello Friends!

Hope you are doing well :)

If you want to edit the html of default search form in your wordpress website, then don’t warry :) just add my code in your theme function file.

raghu-blog

/********************************************
 * Start search form hookes part here
*********************************************/
function my_search_form( $form ) {
    $form = '<form role="search" method="get" id="searchform" class="searchform" action="' . home_url( '/' ) . '" >
    <div>
    <input type="text" value="' . get_search_query() . '" name="s" onblur="if (this.value == \'\') {this.value = \'Search\';}" onfocus="if (this.value == \'Search\') {this.value = \'\';}" id="setop"/>
    <input type="submit" id="searchsubmit" value="'. esc_attr__( 'Search' ) .'" />
    </div>
    </form>';

    return $form;
}

add_filter( 'get_search_form', 'my_search_form' );
/********************************************
 * End hookes part here
*********************************************/

Enjoy Code! | Raghunath Blog

Hello Friends!,

If you want to set delay time for publish/hide to any specific block in your site then you can use the setTimeout() function.

setTimeout function can be used for reloading page, show/hide jQuery UI Datepicker and for making a div disappear or appear after few seconds.

For example, if I want to make div element fade out then you can use below code. It will fade out the div with id “dvData” after 2 seconds.

$(document).ready(function(){
//Fade out the div after 2 seconds automatically when page is loaded.
setTimeout(function(){
 $('#dvData').fadeOut();}, 2000);
//Fade in the div after 2 seconds automatically when page is loaded.
setTimeout(function(){
 $('#dvData').fadeIn();}, 2000);
});

Enjoy Code | Raghunath Blog

Hello Friends!

Hope you are doing well :)

If you want to add a new custom field to customer address during checkout process then just follow my step:

  1. Adding New Field in Database Tables
    First of all you have need to create the all require fields in your database through the phpMyadmin,so lets start the process.
    Here we are taking “govt_id” as new fileds name
    eav_attribute table
    insert a row in this table with values entity_type_id = 2, attribute_code = govt_id, backend_type = varchar, fontend_input = text, fontend_label = Govt ID No#, is_user_defined = 1, is_required = 1, default = NULL.
    eav_entity_attribute table
    insert a row in this table with values entity_type_id = 2,attribute_set_id =2, attribute_group_id = 2, attribute_id = (The attribute_id or the primary key of the row inserted in the eav_attribute table)
    customer_eav_attribute table
    insert a row in this table with values attribute_id = (The attribute_id or the primary key of the row inserted in the eav_attribute table), is_visible = 1 rest all column will take default values
    customer_form_attribute table
    1. insert row in this table with values form_code = adminhtml_customer_address and attribute_id = (The attribute_id or the primary key of the row inserted in the eav_attribute table). This required for the attribute to show up in the admin
    2. insert row in this table with values form_code = customer_address_edit and attribute_id = (The attribute_id or the primary key of the row inserted in the eav_attribute table). This required for the attribute to get saved in edit address form and checkout page
    3. insert row in this table with values form_code = customer_register_address and attribute_id = (The attribute_id or the primary key of the row inserted in the eav_attribute table). This is required to save the attribute in the create account page
    After doing this step, you should be able to do see your new address attribute in the admin. -
    addressattribute1In Last Step we need to add govt_id column in the tables sales_flat_order_address, sales_flat_quote_address
  2. Now we have need to add the new field in both shipping.phtml and billing.phtml files, you can find both files in your theme folder app/design/frontend/yourtheme/default/template/checkout/onepage
    billing.phtml :

    <li class="fields">
                        <div class="field">
                            <label for="govt_id" class="required"><em>*</em><?php echo $this->__('Govt ID#') ?></label>
                            <div class="input-box">
                                <input type="text" name="billing[govt_id]" value="<?php echo $this->htmlEscape($this->getAddress()->getGovtId()) ?>" title="<?php echo $this->__('Govt ID#') ?>" id="billing:govt_id" class="input-text required-entry" />
                            </div>
                        </div>
                    </li>
    
    

    shipping.phtml :

    <li class="fields">
                            <div class="field">
                                <label for="govt_id" class="required"><em>*</em><?php echo $this->__('Govt ID#') ?></label>
                                <div class="input-box">
                                    <input type="text" name="shipping[govt_id]" value="<?php echo $this->htmlEscape($this->getAddress()->getGovtId()) ?>" title="<?php echo $this->__('Govt ID#') ?>" id="shipping:govt_id" class="input-text required-entry" />
                                </div>
                            </div>
                        </li>
  3. In Next Step you have need to add new fields in config.xml file
    Add this one under <sales_convert_quote_address></sales_convert_quote_address> tag
                    <govt_id>
                        <to_order_address>*</to_order_address>
                        <to_customer_address>*</to_customer_address>
                    </govt_id>
    Add this one under <customer_address></customer_address> tag
                    <govt_id>
                        <to_quote_address>*</to_quote_address>
                    </govt_id>
    

     

  4. Finally you have need to add the new field in templates in same format as given other fields
    To change the format, go to System -> Configuration -> Customer Configuration -> Address Template
    There you will see 5 options, we need to change all.
    Text
    Add {{depend govt_id}}ID# {{var govt_id}}{{/depend}} where ever you want it. {{depend}} basically checks, if govt_id is not empty.
    Text One line
    Add {{depend govt_id}}ID# {{var govt_id}}{{/depend}} where ever you want it. This format shows up in the checkout page shipping,billing address dropdowns.
    HTML
    Add {{depend govt_id}}<br/>ID# {{var govt_id}}{{/depend}}. This format is used in many places like Order View, Address Display etc.
    PDF
    Add {{depend govt_id}}<br/>ID# {{var govt_id}}{{/depend}}|. This format is used in PDF invoices, shipments etc.
    Javascript Template
    Add <br/>ID#{govt_id}. This is used in admin add/edit address area.
    After saving these in the configuration, the new address format should be visible. You can view this here
    addressattribute2

That’s All! :)

Enjoy Code! | Raghunath Blog