Skip to content
Om Puter

Om Puter

Berbagi Tutorial Coding dan Pemrograman Komputer

Menu
  • Channel YouTube ThirteeNov
  • Channel YouTube Om Puter
Menu

Pengembangan Theme WordPress – Cara menampilkan logo situs, jika ada, atau teks judul jika tidak

Posted on 10 Oktober 202110 Oktober 2021 by OmPuter

Dalam membuat tema/template WordPress, tentunya di bagian atas atau header website kita, kita ingin menampilkan logo situs jika ada, jika tidak maka kita ingin menampilkan teks judul situs.

Untuk itu, kita perlu script php seperti ini:

$custom_logo_id = get_theme_mod( 'custom_logo' );
					$logo = wp_get_attachment_image_src( $custom_logo_id , 'full' );
					if ( has_custom_logo() ) {
							echo '<a href="' .get_site_url(). '"><img src="' . $logo[0] . '" alt="' . get_bloginfo( 'name' ) . '" height="60px" style="margin-top: 10px;"></a>';
					} else {
							echo '<h1><a href="' .get_site_url(). '">'. get_bloginfo( 'name' ) .'</a></h1>';
					}

Script ini hendaknya diletakkan di file kepala/header tema WordPress kita.

Oh ya, jangan lupa, pada fungtions.php theme kita perlu ada setingan custom logo seperti ini ya:

//Custom 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' );

Pastikan themename di script terakhir ini diganti dengan teks domain theme atau plugin yang kamu buat.

Post Views: 755

Kategori

  • 3D Max
  • Adobe Animate
  • Android
  • c#
  • Cordova
  • HTML5, CSS & JavaScript
  • iOS
  • Lain-lain
  • Photoshop
  • PHP
  • Python
  • Roblox
  • Tak Berkategori
  • Unity
  • WordPress
ciihuy2020
© 2026 Om Puter | Powered by Superbs Personal Blog theme