On this page
- 1 WordPress: Important Functions
- 2 WordPress: Important Functions
- 2.1 1. wp_mail ()
- 2.2 Example
- 2.3 2. bloginfo()
- 2.4 3. get_post_meta()
- 2.4.0.1 Metadata in WordPress
- 2.4.0.2 WP_List_Table tutorial : How to display data from database to the admin block ?
- 2.4.0.3 Shortcode in WordPress
- 2.4.0.4 Add Tracking Code in WordPress
- 2.4.0.5 WordPress: Post Types
- 2.4.0.6 Creating an Administrator Account in WordPress Using Custom PHP Code
- 2.4.0.7 WordPress: Plugins
- 2.4.0.8 WordPress: Hooks
- 2.4.0.9 Cheatsheet: WordPress
- 2.5 Leave A Comment Cancel reply
WordPress: Important Functions
WordPress: Important Functions
April 7, 2019
Many of the core WordPress functions are useful to Plugin and Theme developments.
1. wp_mail ()
Sends an email, similar to PHP’s mail function.
wp_mail( string|array $to, string $subject, string $message, string|array $headers = '', string|array $attachments = array() )
Example
<?php $to= get_option('admin_email_to') ; $subject="Get A Quote"; $message="Name:".$_POST['message_name']."<br>"."Email:".$_POST['message_email']."<br>"."Mobile:".$_POST['message_mobile']; $headers = array('Content-Type: text/html; charset=UTF-8' , 'From: Name of sender <sender@wp.com>' , 'Bcc: sender2@wp.com'); $to_customer = $_POST['message_email']; $subject_customer ="ABC"; $message_customer ="Thanks For Connecting With Us! Our support team will contacts you soon."; $headers_customer = array('Content-Type: text/html; charset=UTF-8' , 'From: ABC <abc@wp.com>'); if($to == get_option('admin_email_to')){ wp_mail( $to, $subject, $message,$headers); } if($to_customer == $_POST['message_email']){ wp_mail( $to_customer, $subject_customer, $message_customer,$headers_customer); } ?>
2. bloginfo()
Displays information about the current site.
3. get_post_meta()
Retrieves a post meta field for the given post ID.
get_post_meta( int $post_id, string $key = ”, bool $single = false )