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

Hello Friends!

If you want to remove the wordpress and plugin “Update” notification from admin section using hooks then just use my code given below:

Screenshot-1 Screenshot-2

add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );
add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );

Add these code in your themes function.php file! That’s it :)

Enjoy Code! | Raghunath Blog

Hello Friends!

If you are using jQuery hover effect in your site and want to remove the hover loop then use jQuery stop() function. you can remove the loop by adding the stop() function.

We can create a nice fade effect without the common problem of multiple queued animations by adding .stop(true, true) to the chain:

$( "#hoverme-stop-2" ).hover(function() {
$( this ).find( "img" ).stop( true, true ).fadeOut();
}, function() {
$( this ).find( "img" ).stop( true, true ).fadeIn();
});

For more please go here

Enjoy Code! | Raghunath Blog

Hello Friends!

If you do not want to load the any plugins JS file in front-end then don’t worry,you can do it using hooks without any changes in plugin files.

For Example:

If you are using “Contact Form 7” plugins in your site and don’t want to load the form7 js files on any specific page then then just add given code in your theme function file:

add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );   
function my_deregister_javascript() 
{    
    if ( !is_page('Contact') ) 
    {     
        wp_deregister_script( 'contact-form-7' );      
    } 
}

Follow same process for all plugins :)

Enjoy Code! | Raghunath Blog

Hello Friends!

Hope you are doing well :)

If you are using the WP e-Commerce plugin in your wordpress site and want to create a custom sorting option on product list page OR want to show the product on basis of variations in different-2 tabs  then don’t worry , just update the attached files in your theme folder

Screenshot-1

Download Source Code

Enjoy Code! | Raghunath Blog

Hello Friends!

If you want to get the post content anywhere in your templates files using post id, then use my code, hope this will be help full to all my friends :)

<?php
$post_7 = get_post(7); 
$title = $post_7->post_title; //get the post title
$content = $post_7->post_content; //get post content
?> 

Enjoy Raghunath Code!