Here is a list of some useful WordPress functions.This may reduce your development time.
wp_mail()
Some time we need to send email to the user.We can use this wordpress function wp_mail() to send email.It works just like the php email function but have better functionality.
wp_loginout()
Displays a login link, or if a user is logged in, displays a logout link.You can even give the redirect url here.SO user will redirect to that url.
esc_url()
This function ejects URLs that do not have one of the provided whitelisted protocols (defaulting to http, https, ftp, ftps, mailto, news, irc, gopher, nntp, feed, and telnet), eliminates invalid characters, and removes dangerous characters.
is_page()
With this function you can check if that particular page is being load.Very handy if you want to load a script only a specific page
Disable Commenting on Posts Older Than 1 Month:
<?php
function close_comments( $posts ) {
if ( !is_single() ) { return $posts; }
if ( time() – strtotime( $posts[0]->post_date_gmt ) > ( 30 * 24 * 60 * 60 ) ) {
$posts[0]->comment_status = ‘closed’;
$posts[0]->ping_status = ‘closed’;
}
return $posts;
}
add_filter( ‘the_posts’, ‘close_comments’ );
?>
[/php]
Custom Excerpt Length:
[php]
function new_excerpt_length($length) {
return 100;
}
add_filter(‘excerpt_length’, ‘new_excerpt_length’);
[/php]
Writer
Dynamic Web Lab Editorial
We share how we design, engineer, and scale digital products across the GCC, Europe, and the US.
Tags
Need help implementing this?
We turn these playbooks into shipped features. Let us scope your roadmap and support your team.
Start a project conversation

