Change the email sender header
PHP
// 修改發信電子郵件 function wpb_sender_email( $original_email_address ) { return '[email protected]'; } // 修改寄件人名稱 function wpb_sender_name( $original_email_from ) { return '寄件人名稱'; } add_filter( 'wp_mail_from', 'wpb_sender_email' ); add_filter( 'wp_mail_from_name', 'wpb_sender_name' );
Register widget
PHP
function custom_sidebar() { $args = array( 'id' => 'widget-weather', 'name' => __( '天氣', 'innews' ), 'description' => __( '天氣小工具', 'innews' ), 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', 'before_widget' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', ); register_sidebar( $args ); } add_action( 'widgets_init', 'custom_sidebar' );
Tags:
- widget
- /
ACF Options Page
PHP
function my_acf_op_init() { if( function_exists('acf_add_options_page') ) { acf_add_options_page(array( 'page_title' => __('設定'), 'menu_title' => __('設定'), 'menu_slug' => 'setting-my', 'icon_url' => 'dashicons-code-standards', 'redirect' => false )); } } add_action('acf/init', 'my_acf_op_init');
Tags:
Register Nav
PHP
function setNavigation(){ if (function_exists('add_theme_support')) { add_theme_support('menus'); } function header_menu(){ wp_nav_menu( array( 'theme_location' => 'header-menu', 'menu' => '', 'container' => 'div', 'container_class' => 'menu-{menu slug}-container', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '', 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul>%3$s</ul>', 'depth' => 0, 'walker' => '' ) ); } function footer_menu(){ wp_nav_menu( array( 'theme_location' => 'footer-menu', 'menu' => '', 'container' => 'div', 'container_class' => 'menu-{menu slug}-container', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '', 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul>%3$s</ul>', 'depth' => 0, 'walker' => '' ) ); } function register_nav(){ register_nav_menus(array( 'header-menu' => '頁首', 'footer-menu' => '頁尾', )); } add_action('init', 'register_nav'); }
Tags:
- nav
- /
Register custom taxonomy in array
PHP
function add_post_taxonomy() { $taxArray = array( array( "taxName" => 'tax中文名', "taxNameEn" =>'taxSlu' ), ); foreach ($taxArray as $tax) { $labels = array( "name" => __( "", "" ), "singular_name" => __( $tax['taxName'], "" ), "menu_name" => __( $tax['taxName'], "" ), "all_items" => __( "所有", "" ), "edit_item" => __( "編輯", "" ), "view_item" => __( "檢視", "" ), "update_item" => __( "更新", "" ), "add_new_item" => __( "新增", "" ), "new_item_name" => __( "新增", "" ), "search_items" => __( "搜尋", "" ), ); $args = array( "label" => __( $tax['taxName'], "" ), "labels" => $labels, "public" => true, "hierarchical" => true, "label" => $tax['taxName'], "show_ui" => true, "show_in_menu" => true, "show_in_nav_menus" => true, "show_admin_column" => true, "query_var" => true, "rewrite" => array( 'slug' => $tax['taxNameEn'], 'with_front' => true, ), "show_admin_column" => true, "show_in_rest" => false, "rest_base" => $tax['taxNameEn'], "show_in_quick_edit" => true, ); register_taxonomy( $tax['taxNameEn'], 'post', $args ); } } add_action( 'init', 'add_post_taxonomy' );
WordPress plugin header
The essential information of plugin.
PHP
<?php /** * @package Hello_Dolly * @version 1.7.2 */ /* Plugin Name: Hello Dolly Plugin URI: http://wordpress.org/plugins/hello-dolly/ Description: This is a plugin of creating Custom Post Type, Taxonomy, and other models which is existed when switch anther theme. Author: Matt Mullenweg Version: 1.7.2 Author URI: http://ma.tt/ */
Tags:
- template
- /
Add custom post type and taxonomy
The WordPress API of adding a custom post type and taxonomy. Naming the post type in the variables: $cptName and $cptNameEn. Modifying the variable $hasTax to true if there is taxonomy in the post type.
PHP
<?php function cpt_support() { $cptName = 'CPT中文名字'; $cptNameEn = 'CPT English Name'; $cptTax = $cptNameEn . '_tax'; $cptTaxLabel = 'Taxonomy中文名字' $hasTax = true; $labels = array( "name" => __( $cptName, "" ), "singular_name" => __( $cptName, "" ), "menu_name" => __( $cptName, "" ), "all_items" => __( "所有", "" ), "add_new" => __( "新增", "" ), "add_new_item" => __( "新增", "" ), "edit_item" => __( "編輯", "" ), "new_item" => __( "新項目", "" ), "view_item" => __( "檢視", "" ), "view_items" => __( "檢視", "" ), "search_items" => __( "搜尋", "" ), "not_found" => __( "無結果", "" ), "not_found_in_trash" => __( "無結果", "" ), ); $args = array( "label" => __( $cptName, "" ), "labels" => $labels, "description" => "", "public" => true, "publicly_queryable" => true, "show_ui" => true, "show_in_rest" => false, "rest_base" => "", "has_archive" => true, "show_in_menu" => true, "show_in_nav_menus" => true, "exclude_from_search" => false, "capability_type" => "post", "map_meta_cap" => true, "hierarchical" => false, "rewrite" => array( "slug" => $cptNameEn, "with_front" => true ), "query_var" => true, "menu_icon" => "dashicons-groups", // https://developer.wordpress.org/resource/dashicons/#arrow-left "supports" => array( "title","revisions","editor" ), ); register_post_type( $cptNameEn, $args ); $labels = array( "name" => __( $cptTaxLabel, "" ), "singular_name" => __( $cptTaxLabel, "" ), "menu_name" => __( $cptTaxLabel, "" ), "all_items" => __( "所有", "" ), "edit_item" => __( "編輯", "" ), "view_item" => __( "檢視", "" ), "update_item" => __( "更新", "" ), "add_new_item" => __( "新增", "" ), "new_item_name" => __( "新增", "" ), "search_items" => __( "搜尋", "" ), ); $args = array( "label" => __( $cptTaxLabel, "" ), "labels" => $labels, "public" => true, "hierarchical" => true, "label" => $cptTaxLabel, "show_ui" => true, "show_in_menu" => true, "show_in_nav_menus" => true, "query_var" => true, "rewrite" => array( 'slug' => $cptTax, 'with_front' => true, ), "show_admin_column" => true, "show_in_rest" => false, "rest_base" => $cptTax, "show_in_quick_edit" => true, ); if( $hasTax ){ register_taxonomy( $cptTax, array( $cptNameEn ), $args ); } } add_action( 'init', 'cpt_support' );