Skip to content
Om Puter

Om Puter

Berbagi Tutorial Coding dan Pemrograman Komputer

Menu
  • Channel YouTube ThirteeNov
  • Channel YouTube Om Puter
Menu

Cara mengaktifkan sidebar untuk menampilkan widget-widget WordPress pada tema/template yang kita buat

Posted on 10 Oktober 202110 Oktober 2021 by OmPuter

Tentu kita perlu menampilkan widget-widget pada tema WordPress yang kita buat. Oleh karena itu kita perlu memanggil function ini untuk menginclude file sidebar.php:

<?php get_sidebar(); ?>

Karena get_sidebar() itu memanggil file sidebar.php, maka kita perlu membuat file tersendiri bernama sidebar.php yang isinya kode ini:

<?php if(is_active_sidebar('themesaya_sidebar')) : ?>
<?php dynamic_sidebar('themesaya_sidebar'); ?>
<?php endif; ?>

Setelah itu kita perlu menambahkan kode di bawah ini untuk inisialisasi sidebar pada theme kita:

//Sidebar widget
function themesaya_custom_widgetarea(){
	register_sidebar(array(
		'name' 			=> 'Sidebar',
		'id'			=> 'themesaya_sidebar',
		'before_widget'	=> '<div class="widget-right-sidebar">',
		'after_widget'	=> '</div>',
		'before_title' 	=> '<h2>',
		'after_title'	=> '</h2>',
	));
}

add_action('widgets_init', 'themesaya_custom_widgetarea');

Jangan lupa ganti kata “themesaya” dengan textdomain theme kamu ya.

Prakteknya bisa dilihat di video ini:

Post Views: 1,508

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