Posts Tagged "function"

How to disable posts auto save in WordPress?

WordPress have a very useful function that auto-saves your posts while you’re typing them in the dashboard. Though, if for some reason you’d like to disable this function, it is very easy to do. Just read on! To disable WordPress autosaving function, simply open your functions.php file and paste the following function: function disableAutoSave(){ wp_deregister_script(‘autosave’); } add_action(‘wp_print_scripts’, ‘disableAutoSave’); That’s all. Once you saved the file, WordPress will never autosave a post. To enable autosaving again, simply delete this code. Shashi…

Like to share it
Read More

How to add custom post type in wordpress

Open “function.php” add the following code to add new custom post type : <?php add_action(‘init’, ‘featured_post_register’); function featured_post_register() { $labels = array( ‘name’ => _x(‘Featured Posts’, ‘post type general name’), ‘singular_name’ => _x(‘Featured Posts’, ‘post type singular name’), ‘add_new’ => _x(‘Add New’, ‘featured posts’), ‘add_new_item’ => __(‘Add New Featured Posts’), ‘edit_item’ => __(‘Edit Featured Posts’), ‘new_item’ => __(‘New Featured Posts’), ‘view_item’ => __(‘View Featured Posts’), ‘parent_item_colon’ => ” ); $args = array( ‘labels’ => $labels, ‘public’ => true, ‘publicly_queryable’ =>…

Like to share it
Read More

Get the First Monday of the current Month or Get Last Day of Month or Get First Day of Month

Get the First Monday of the current Month or Get Last Day of Month or Get First Day of Month Get the First Monday of the current Month <?php function getFirstMonday($month,$year) { $num = date(“w”,mktime(0,0,0,$month,1,$year)); if($num==1) return date(“Y-M-ds”,mktime(0,0,0,$month,1,$year)); elseif($num>1) return date(“Y-M-d”,mktime(0,0,0,$month,1,$year)+(86400*(8-$num))); else return date(“Y-M-d”,mktime(0,0,0,$month,1,$year)+(86400*(1-$num))); } $month = date(“m”); $year = date(“Y”); // this will output current month’s First Monday echo getFirstMonday($month,$year); ?> Get the Last Day of current Month <?php echo date(‘d/m/y’,strtotime(“last Friday”,mktime(0,0,0,date(“n”)+1,1))); // you can replace your Day instead…

Like to share it
Read More

Wordwrap your text

Here the function that comes under php i.e wordwrap(). You can use it for wrapping you long string text into multiple lines and easy to read. Following are the code that help you. Copy and paste the code into your editor save the code as php file and run into you browser. <?php // string to be wrapped into multiple lines // change the text according your requirement $text = “Word wrap will split this text up into smaller lines,…

Like to share it
Read More

Substr () PHP Function

The Substr () PHP Function is used to return part of a string. It is written as substr (string, start, optional length);.The string is whatever string you want to return a portion of. The start is how many characters in to skip before starting. Setting this to 3 would skip the first three and start returning at the forth character. Setting this to a negative number will start counting backwards from the end of the string. Length is an optional…

Like to share it
Read More

Difference between isset empty is null

I have come across code that checks for empty or null values, or if a variable is set. Many of these checks fail as the wrong function is being used to assert the correct value. While it is important to be checking values, it is equally important to understand the difference between the different methods of checking and testing values for empty, null, or if they are set. Most common is the incorrect use of isset() and empty(). Many times…

Like to share it
Read More