How remove custom post type slug from post url : wordpress

Hello Friends,

I you are using your own custom post type on wordpress site and want to remove the custom post type slug from post url then you can do it easily using hooks. You will no need to edit any wordpress core file, just copy and paste given blow code into your theme function.php file.

/** Start Removed custom post_type slug from posts url**/
function custom_parse_request_tricksy( $query ) {

    // Only noop the main query
    if ( ! $query->is_main_query() )
        return;

    // Only noop our very specific rewrite rule match
    if ( 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
        return;
    }

    // 'name' will be set if post permalinks are just post_name, otherwise the page rule will match
    if ( ! empty( $query->query['name'] ) ) {
        $query->set( 'post_type', array( 'project','post','page') );
    }
}
add_action( 'pre_get_posts', 'custom_parse_request_tricksy' );
 function custom_remove_cpt_slug( $post_link, $post, $leavename ) {

    if ( 'project' != $post->post_type  || 'publish' != $post->post_status ) {
        return $post_link;
    }

    $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );

    return $post_link;
}
add_filter( 'post_type_link', 'custom_remove_cpt_slug', 10, 3 );

We have given above example for “project” custom post type , you will need to update post type value as per your custom post type name.

 

Enjoy Code!!

Tagged with: , ,
Posted in Wordpress

How perform action during add/edit/delete category using hooks : wordpress

Hello Friends!!

If you want perform any action during add/edit/delete category/taxonomy without changing in wordpress core files then you can do it using wordpress hooks . You will only need to add given blow function in your theme function file, no need to edit

/** Call function during create new category/taxonomy */
add_action('create_term','wp_custom_save_taxonomy');
function wp_custom_save_taxonomy($term_id) {
print_r($_POST); // add action here
}
/** Call function during edit category/taxonomy */
add_action('edit_term','wp_custom_edit_taxonomy');
function wp_custom_edit_taxonomy($term_id) {
print_r($_POST); // add action here
}
/** Call function during delete category/taxonomy */
add_action('delete_term_taxonomy','wp_custom_delete_taxonomy');
function wp_custom_delete_taxonomy($term_taxonomy_id) {
       global $wpdb; // add action here
}

I hope you will enjoy wordpress hooks magic!!

Tagged with: , , ,
Posted in Wordpress

How add IP restriction for access to wp-admin login page through htaccess file : WordPress

Hello Friends.

Hope you are doing well!!

As you know there days hacker can easily hack wordpress site admin because generally we used common username/password of access to admin (i.e admin/admin123, admin/123456). I am here going to describe you how you can restrict wp-admin login page only for few IP address using htaccess file. I am sure IP restriction will make more secure your wordpress admin, after add IP restrict code no other user can access your site login page.

You will need to add given below code into your root htaccess file and update your IP address

# IP restriction code
<Files wp-login.php>
Order Deny,Allow
Deny from all
Allow from 000.000.00.00
Allow from 000.00.0.000
</Files>

Now create a new htaccess file under wp-admin folder and paste given below code and update your IP address

# IP restriction code
Order Deny,Allow
Deny from all
Allow from 000.000.00.00
Allow from 000.00.0.000

I have already created a wordpress plugin “Protect WP-Admin” for make admin more secure, You can use my plugin on your wordpress site.

Tagged with: , , ,
Posted in Wordpress

How Add New Custom Filed ON Media Image Pages : WordPress

Hello Friends!!

Hope you all are doing well :)

In admin if you want to add new custom field on media details page then you can do it in a easy way. You will not need to edit in wordpress core files , using wordpress hooks you can do it by add the code in your theme function file.

I am given to a example for add to new field “External URL”, You will need to add the code in your theme function file.

 

/** Add new Custom Field On Media detail page */
function add_custom_media_fields($form_fields, $post) {
    $form_fields["externalUrl"] = array(
        "label" => __("External URL"),
        "input" => "text", // this is default if "input" is omitted
        "value" => get_post_meta($post->ID, "externalUrl", true)
    );
     
    return $form_fields;
}
add_filter("attachment_fields_to_edit", "add_custom_media_fields", null, 2); 

/** Save the new custom field value into database*/
function save_custom_media_fields($post, $attachment) {
    $my_data = sanitize_text_field( $attachment['externalUrl'] );
    update_post_meta( $post['ID'], 'externalUrl', $my_data );
return $post;
}

add_filter('attachment_fields_to_save', 'save_custom_media_fields', 10, 2);

 
 
Firefox_Screenshot_2015-06-17T14-16-53.285Z
 
 
Hope you will all enjoy my code.

Posted in Wordpress

How change order information on success order: Magento

Hello Friends!

Hope you all are doing well!

I am here going to describe you a important Magento script for change the order information on success order.

Using my script, you can easily update recent order information like “customer group”, “payment status”, “order confirmation” etc.

/** Change Custom Payment Status */
                $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
                $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
                $order->setData('state', 'complete');
                $order->setStatus('complete');   
                $history = $order->addStatusHistoryComment('Order was set to Complete by our automation tool.', false);
                $history->setIsCustomerNotified(true);
                $order->save();
           /* End payment status */

 

Enjoy script! :)

Tagged with: , , , ,
Posted in Magento

Lunched new version 1.3 of protect-wp-admin plugin : WordPress

Hello Friends,

Hope you all doing well :)

Last time i was released version 1.2 https://raghunathgurjar.wordpress.com/2014/12/01/lunched-new-version-1-2-of-protect-wp-admin-plugin-wordpress/ and now launching new version 1.3 of “Protect WP-Admin” wordpress plugin with some new features.

In current version 1.3 admin can able to change the wp-login page logo by configure the plugin settings and also admin can define the wp-login page body background color also.
Firefox_Screenshot_2015-01-06T12-23-01.135Z

Version 1.3

  • Added an option for define to admin login page logo
  • Added an option for define to wp-login page background-color
  • Fixed some minor css issues

Click here to view all change log
Click here to download plugin

Enjoy!

Tagged with: , , ,
Posted in Wordpress
Follow

Get every new post delivered to your Inbox.

Join 139 other followers

%d bloggers like this: