10 Useful WordPress functions to reduce your development time

September 11, 2012

This 10 Useful WordPress functions will certainly reduce your WordPress development time.I found this functions when i do some research for my projects. So i think i better share this with you.

1.Custom Excerpt Length

By default, excerpt length is set to 55 words. To change excerpt length using excerpt_length filter, add the following code to functions.php file in your theme:

[php]
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( ‘excerpt_length’, ‘custom_excerpt_length’, 999 );
[/php]

Find more here.

2. Human Time

[php]
echo human_time_diff( get_the_time(‘U’), current_time(‘timestamp’) ) . ‘ ago’;
// display "2 days ago"
[/php]

Find more here.

3. Validate String

[php]wp_kses($string, $allowed_html, $allowed_protocols);[/php]

This only allow HTML element names, attribute names and attribute values to the inputted string.

Find more here .

4. Use wp mail function to send email

[php] wp_mail( $to, $subject, $message, $headers, $attachments ); [/php]

The benefit of using this function to send email is its super simple.

Find more here.

5. Wp schedule event

[php]
wp_schedule_event($timestamp, $recurrence, $hook, $args);
[/php]

Using this function you can do cron job after specific time interval.

Find more here.

6. Wp redirect function

[php]
wp_redirect( $location, $status );
exit;
[/php]

Using this you can redirect a use to a specific link for a specific event.Lets say if your not logged in then you want to redirect user to login page.

Find more here.

7. Is email function

[php]
is_email( $email );
[/php]

using this function you can verifies that an email is valid or not.

Find more here.

8. Absint function

[php]
absint( $maybeint );
[/php]

This function will converts a value to a non-negative integer.Very useful for integer verification.

Find more here.

9. Wp remote get function

[php]
wp_remote_get( $url, $args );
[/php]

Use this function if you want to retrieve the content of a Webpage.You will get the content in a array.Usin this function you can get feed data also.

Find more here.

10. Wp remote get function

[php]
$feed = fetch_feed( $uri );
[/php]

This function will retrieves an external feed and parses it. Uses the SimplePie and FeedCache functionality for retrieval and parsing and automatic caching.

Find more here.

Related Posts

Let Us Work Together

Let us Plan Your Website or Digital Strategy Together

Start My Proposal Now →