Cách thêm logo vào tiêu đề WordPress PHP

Khi bật hỗ trợ logo tùy chỉnh, bạn có thể định cấu hình năm tham số bằng cách chuyển các đối số cho hàm

function themename_custom_logo_setup() {
	$defaults = array(
		'height'               => 100,
		'width'                => 400,
		'flex-height'          => true,
		'flex-width'           => true,
		'header-text'          => array( 'site-title', 'site-description' ),
		'unlink-homepage-logo' => true, 
	);
	add_theme_support( 'custom-logo', $defaults );
}
add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
5 bằng cách sử dụng một mảng

function themename_custom_logo_setup() {
	$defaults = array(
		'height'               => 100,
		'width'                => 400,
		'flex-height'          => true,
		'flex-width'           => true,
		'header-text'          => array( 'site-title', 'site-description' ),
		'unlink-homepage-logo' => true, 
	);
	add_theme_support( 'custom-logo', $defaults );
}
add_action( 'after_setup_theme', 'themename_custom_logo_setup' );

Móc after_setup_theme được sử dụng để hỗ trợ logo tùy chỉnh được đăng ký sau khi tải xong chủ đề

  • function themename_custom_logo_setup() {
    	$defaults = array(
    		'height'               => 100,
    		'width'                => 400,
    		'flex-height'          => true,
    		'flex-width'           => true,
    		'header-text'          => array( 'site-title', 'site-description' ),
    		'unlink-homepage-logo' => true, 
    	);
    	add_theme_support( 'custom-logo', $defaults );
    }
    add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
    6
    Chiều cao biểu trưng dự kiến ​​tính bằng pixel. Biểu trưng tùy chỉnh cũng có thể sử dụng kích thước hình ảnh tích hợp sẵn, chẳng hạn như
    function themename_custom_logo_setup() {
    	$defaults = array(
    		'height'               => 100,
    		'width'                => 400,
    		'flex-height'          => true,
    		'flex-width'           => true,
    		'header-text'          => array( 'site-title', 'site-description' ),
    		'unlink-homepage-logo' => true, 
    	);
    	add_theme_support( 'custom-logo', $defaults );
    }
    add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
    7 hoặc đăng ký kích thước tùy chỉnh bằng cách sử dụng
    function themename_custom_logo_setup() {
    	$defaults = array(
    		'height'               => 100,
    		'width'                => 400,
    		'flex-height'          => true,
    		'flex-width'           => true,
    		'header-text'          => array( 'site-title', 'site-description' ),
    		'unlink-homepage-logo' => true, 
    	);
    	add_theme_support( 'custom-logo', $defaults );
    }
    add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
    0.
  • function themename_custom_logo_setup() {
    	$defaults = array(
    		'height'               => 100,
    		'width'                => 400,
    		'flex-height'          => true,
    		'flex-width'           => true,
    		'header-text'          => array( 'site-title', 'site-description' ),
    		'unlink-homepage-logo' => true, 
    	);
    	add_theme_support( 'custom-logo', $defaults );
    }
    add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
    1Chiều rộng logo dự kiến ​​tính bằng pixel. Biểu trưng tùy chỉnh cũng có thể sử dụng kích thước hình ảnh tích hợp sẵn, chẳng hạn như
    function themename_custom_logo_setup() {
    	$defaults = array(
    		'height'               => 100,
    		'width'                => 400,
    		'flex-height'          => true,
    		'flex-width'           => true,
    		'header-text'          => array( 'site-title', 'site-description' ),
    		'unlink-homepage-logo' => true, 
    	);
    	add_theme_support( 'custom-logo', $defaults );
    }
    add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
    7 hoặc đăng ký kích thước tùy chỉnh bằng cách sử dụng
    function themename_custom_logo_setup() {
    	$defaults = array(
    		'height'               => 100,
    		'width'                => 400,
    		'flex-height'          => true,
    		'flex-width'           => true,
    		'header-text'          => array( 'site-title', 'site-description' ),
    		'unlink-homepage-logo' => true, 
    	);
    	add_theme_support( 'custom-logo', $defaults );
    }
    add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
    0
  • function themename_custom_logo_setup() {
    	$defaults = array(
    		'height'               => 100,
    		'width'                => 400,
    		'flex-height'          => true,
    		'flex-width'           => true,
    		'header-text'          => array( 'site-title', 'site-description' ),
    		'unlink-homepage-logo' => true, 
    	);
    	add_theme_support( 'custom-logo', $defaults );
    }
    add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
    4
    Có cho phép chiều cao linh hoạt hay không.
  • function themename_custom_logo_setup() {
    	$defaults = array(
    		'height'               => 100,
    		'width'                => 400,
    		'flex-height'          => true,
    		'flex-width'           => true,
    		'header-text'          => array( 'site-title', 'site-description' ),
    		'unlink-homepage-logo' => true, 
    	);
    	add_theme_support( 'custom-logo', $defaults );
    }
    add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
    5Liệu có cho phép chiều rộng linh hoạt hay không
  • function themename_custom_logo_setup() {
    	$defaults = array(
    		'height'               => 100,
    		'width'                => 400,
    		'flex-height'          => true,
    		'flex-width'           => true,
    		'header-text'          => array( 'site-title', 'site-description' ),
    		'unlink-homepage-logo' => true, 
    	);
    	add_theme_support( 'custom-logo', $defaults );
    }
    add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
    6(Các) lớp phần tử cần ẩn. Nó có thể truyền vào đây một mảng tên lớp cho tất cả các phần tử cấu thành văn bản tiêu đề có thể được thay thế bằng logo
  • function themename_custom_logo_setup() {
    	$defaults = array(
    		'height'               => 100,
    		'width'                => 400,
    		'flex-height'          => true,
    		'flex-width'           => true,
    		'header-text'          => array( 'site-title', 'site-description' ),
    		'unlink-homepage-logo' => true, 
    	);
    	add_theme_support( 'custom-logo', $defaults );
    }
    add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
    7
    Nếu thông số 
    function themename_custom_logo_setup() {
    	$defaults = array(
    		'height'               => 100,
    		'width'                => 400,
    		'flex-height'          => true,
    		'flex-width'           => true,
    		'header-text'          => array( 'site-title', 'site-description' ),
    		'unlink-homepage-logo' => true, 
    	);
    	add_theme_support( 'custom-logo', $defaults );
    }
    add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
    8 được đặt thành true, hình ảnh biểu trưng được chèn bằng cách sử dụng 
    function themename_custom_logo_setup() {
    	$defaults = array(
    		'height'               => 100,
    		'width'                => 400,
    		'flex-height'          => true,
    		'flex-width'           => true,
    		'header-text'          => array( 'site-title', 'site-description' ),
    		'unlink-homepage-logo' => true, 
    	);
    	add_theme_support( 'custom-logo', $defaults );
    }
    add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
    9 hoặc 
    function themename_custom_logo_setup() {
    	$defaults = array(
    		'height'               => 100,
    		'width'                => 400,
    		'flex-height'          => true,
    		'flex-width'           => true,
    		'header-text'          => array( 'site-title', 'site-description' ),
    		'unlink-homepage-logo' => true, 
    	);
    	add_theme_support( 'custom-logo', $defaults );
    }
    add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
    9 sẽ không còn liên kết đến trang chủ khi khách truy cập vào trang đó. Nhằm duy trì kiểu dáng cho hình ảnh được liên kết, hình ảnh biểu tượng không được liên kết nằm trong một 
    function themename_custom_logo_setup() {
    	$defaults = array(
    		'height'               => 100,
    		'width'                => 400,
    		'flex-height'          => true,
    		'flex-width'           => true,
    		'header-text'          => array( 'site-title', 'site-description' ),
    		'unlink-homepage-logo' => true, 
    	);
    	add_theme_support( 'custom-logo', $defaults );
    }
    add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
    01 thẻ có cùng lớp "liên kết biểu tượng tùy chỉnh".

Có thể hiển thị biểu trưng tùy chỉnh trong chủ đề bằng cách sử dụng chức năng 

function themename_custom_logo_setup() {
	$defaults = array(
		'height'               => 100,
		'width'                => 400,
		'flex-height'          => true,
		'flex-width'           => true,
		'header-text'          => array( 'site-title', 'site-description' ),
		'unlink-homepage-logo' => true, 
	);
	add_theme_support( 'custom-logo', $defaults );
}
add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
02. Nhưng bạn nên bọc mã trong lệnh gọi
function themename_custom_logo_setup() {
	$defaults = array(
		'height'               => 100,
		'width'                => 400,
		'flex-height'          => true,
		'flex-width'           => true,
		'header-text'          => array( 'site-title', 'site-description' ),
		'unlink-homepage-logo' => true, 
	);
	add_theme_support( 'custom-logo', $defaults );
}
add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
03 để duy trì khả năng tương thích ngược với các phiên bản cũ hơn của WordPress, như thế này

function themename_custom_logo_setup() {
	$defaults = array(
		'height'               => 100,
		'width'                => 400,
		'flex-height'          => true,
		'flex-width'           => true,
		'header-text'          => array( 'site-title', 'site-description' ),
		'unlink-homepage-logo' => true, 
	);
	add_theme_support( 'custom-logo', $defaults );
}
add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
0

Nói chung, các logo được thêm vào tệp

function themename_custom_logo_setup() {
	$defaults = array(
		'height'               => 100,
		'width'                => 400,
		'flex-height'          => true,
		'flex-width'           => true,
		'header-text'          => array( 'site-title', 'site-description' ),
		'unlink-homepage-logo' => true, 
	);
	add_theme_support( 'custom-logo', $defaults );
}
add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
04 của chủ đề, nhưng nó cũng có thể ở nơi khác

Nếu bạn muốn lấy URL logo hiện tại của mình (hoặc sử dụng đánh dấu của riêng bạn) thay vì đánh dấu mặc định, bạn có thể sử dụng mã sau

Tại sao logo của tôi không hiển thị trên WordPress?

Đi tới Trang web của tôi > Tùy chỉnh . Nhấp vào Nhận dạng Trang web . Đánh dấu tùy chọn Tiêu đề trang web hiển thị và Dòng giới thiệu . Nhấp vào Xuất bản .