Xin lưu ý tài liệu này chỉ dành cho anh em phát triển theme và plugin (các anh chị tìm hiểu wordpress dưới dạng sử dụng không nên thử)
1.Code tích hợp acf vào theme:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // 1. customize ACF path add_filter('acf/settings/path', 'my_acf_settings_path'); function my_acf_settings_path( $path ) { // update path $path = get_stylesheet_directory() . '/includes/advanced-custom-fields-pro/'; // return return $path; } // 2. customize ACF dir add_filter('acf/settings/dir', 'my_acf_settings_dir'); function my_acf_settings_dir( $dir ) { // update path $dir = get_stylesheet_directory_uri() . '/includes/advanced-custom-fields-pro/'; // return return $dir; } // 3. Hide ACF field group menu item add_filter('acf/settings/show_admin', '__return_true'); // 4. Include ACF include_once( get_stylesheet_directory(). '/includes/advanced-custom-fields-pro/acf.php' ); |
2. Vào plugin
Xài trong class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | public function __construct(){ $this->integrate_acf(); } function integrate_acf(){ // 1. customize ACF path add_filter('acf/settings/path', array($this,'my_acf_settings_path')); // 2. customize ACF dir add_filter('acf/settings/dir', array($this,'my_acf_settings_dir')); // 3. Hide ACF field group menu item add_filter('acf/settings/show_admin', '__return_true'); // 4. Include ACF include_once( EUPROSEO_PLUGIN_DIR.'libs/advanced-custom-fields-pro/acf.php' ); } function my_acf_settings_path( $path ) { // update path $path = EUPROSEO_PLUGIN_DIR . 'libs/advanced-custom-fields-pro/'; // return return $path; } function my_acf_settings_dir( $dir ) { // update path $dir = EUPROSEO_URL. 'libs/advanced-custom-fields-pro/'; // return return $dir; } |
Mọi sự sao chép xin ghi rõ nguồn là fcwordpress.net
Chuyên trang về wordpress: hướng dẫn thiết kế theme, plugin, thủ thuật wordpress