Senin, 01 Mei 2023

RANGKUMAN CHEETSET WORDPRESS

 




<?php

//File Wordpress Terdiri Dari:


File Wajib:

style.css

index.php


single.php

page.php



File Pendukung:

function.php

header.php

footer.php

sidebar.php

menu.php

search_form.php

search.php 


404.php

archive.php 

comments.php 


POSTYPE:

single-namapostype.php





?>



<!--- RECOMENDASI ADMIN TEMPLATE PLUGIN --> 

Aquila Admin Theme



<!--- PEMBERIAN ALAMAT URL MANUAL -->

<?php echo home_url( '/' ); ?>

<?php echo home_url( '/all-paket-tour' ); ?>

<?php echo home_url( '/movie' ); ?>

MISALNYA FORM 

<form action="<?php echo home_url( '/' ); ?>">

........

</form>





CHEET 

<?php 

//Nama Website

site_url();

//Deskripsi Website 

bloginfo('name');


//Menampilkan Judul Post

the_title();

//Menampilkan Isi Desktipsi Sebagian Saja ReadMore

the_excerpt();

//Link Post

the_permalink();


?>



<?php

//CARA INCLUDEKAN FILE CSS ALTERNATIF

//1. Buat file php misalnya cssku.php

//2. copy seluruh file css ke dalam file cssku.php 

//3. includekan file cssku.php di header atau file yang akan disambukan ke css 

//scriptnya :

<style>

<?php include 'cssku.php'; ?>

</style>


?>






<!--------------- MENAMPILKAN MENU ------>

<?php

        // Membuat query untuk menu utama

        $args = array(

            'theme_location' => 'primary-menu', // Nama menu yang ingin ditampilkan

            'menu_class' => 'nav-menu', // Kelas untuk tag ul

            'container' => false, // Tidak menggunakan tag div untuk container

        );

    

        // Menampilkan menu

        wp_nav_menu( $args );

?>




<!--------------- MENAMPILKAN MENU DENGAN DROPDOWN  ------>

<?php

  // Membuat query untuk menu utama

  $args = array(

    'theme_location' => 'primary-menu', // Nama menu yang ingin ditampilkan

    'menu_class' => 'nav-menu', // Kelas untuk tag ul

    'container' => false, // Tidak menggunakan tag div untuk container

    'depth' => 2 // Menampilkan submenu dengan kedalaman maksimum 2 level

  );


  // Menampilkan menu

  wp_nav_menu( $args );

?>





<!---------------LOOP--------------------------->

<?php if ( have_posts() ) : ?>

        <?php while ( have_posts() ) : the_post(); ?>

            <h1><?= the_title(); ?></h1>  

            <?php the_post_thumbnail(); ?>

            <?= the_content(); ?>

        <?php endwhile; ?>

<?php endif; ?>






<!--------------- SINGLE LOOP POST TYPE --------------------------->

<!---------------  single.php        --------------------------->

<!---------------  single-movie.php  --------------------------->

<?php if ( have_posts() ) : ?>

        <?php while ( have_posts() ) : the_post(); ?>

        <?= the_title(); ?>

        <?php the_post_thumbnail(); ?>

        <?= the_content(); ?>

<?php endwhile; ?>

<?php endif; ?>




<!---------------- page.php ------------------------>

<?php if ( have_posts() ) : ?>

    <?php while ( have_posts() ) : the_post(); ?>

        <?= the_title(); ?>

        <?php the_post_thumbnail(); ?><br>

        <?= the_content(); ?>

    <?php endwhile; ?>

<?php endif; ?>



<!-- REGISTRASI  file php kita sebagai custome page ---->

<!---------------------MEMBUAT  CUSTOME PAGE  SENDIRI SEKALIGUS SEBAGAI URL KITA --------------------------->

<!-- Misalnya Kita Akan Membuat custome Page bernama kendaraan agar tampilan

page berbeda dengan bawaan wordpress, maka tinggal buat file misalnya kendaraan.php

kemudian pastekan kode dibawah ini paling atas  sebelum menulis code. Tinggal Perge Ke Page dan Pilih 

Nama Template Kita Maka File kendaraan.php akan terbaca sebagai page dan akan mendapatkan URL Sendiri

hal ini untuk mendaftarkan file php kita ke wordpress agar bisa dibaca : -->

<?php

/*

Template Name: Car-Self-Drive-Page

 */



///kode php dimulai, mislanya untuk menampilkan all post, all kategori, atau ingin membuat form //

?>






<!---------------LOOP POSTYPE--------------------------->

<?php

//Loop Postype Seluruhnya

$args = array( 'post_type' =>  'movies' ); 

$postslist = get_posts( $args );    

foreach ($postslist as $post) :  setup_postdata($post); 

?>  

<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 

<?php the_excerpt(); ?>  

<?php endforeach; ?>


<!---------------LOOP POSTYPE --------------------------->

<?php

//Loop Postype Berdasarkam Postype Dengan Limitasi

$args = array( 'category' => 'Hari Ini','post_type' =>  'movies', 'posts_per_page' => 1 ); 

$postslist = get_posts( $args );    

foreach ($postslist as $post) :  setup_postdata($post); 

?>  

<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 

<?php the_excerpt(); ?>  

<?php endforeach; ?> 



<!---------------LOOP POSTYPE--------------------------->

<?php

//Loop Postype Berdasarkan Kategori

$args = array( 'category' => 'Hari Ini','post_type' =>  'movies' ); 

$postslist = get_posts( $args );    

foreach ($postslist as $post) :  setup_postdata($post); 

?>  

<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 

<?php the_excerpt(); ?>  

<?php endforeach; ?>





<!---------------LOOP + PAGINATORSTYPE--------------------------->

<?php

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    $args = array(

    'post_type'=>'tour', // Your post type name

    'posts_per_page' => 8,

    'paged' => $paged,

    'categories' => '',

    );

    $loop = new WP_Query( $args );

    if ( $loop->have_posts() ) {

    while ( $loop->have_posts() ) : $loop->the_post(); 

?>

    <a href="<?php the_permalink(); ?>">

        <?php the_post_thumbnail('home', array('class' => 'img-fluid')); ?>


        <h6><?php the_title(); ?></h6>

        <p>USD <?php the_field('harga_paket') ?> </p>

    </a>

<?php  endwhile; ?>



<?php 

$total_pages = $loop->max_num_pages;

if ($total_pages > 1){

      $current_page = max(1, get_query_var('paged'));

      echo paginate_links(array(

            'base' => get_pagenum_link(1) . '%_%',

            'format' => '/page/%#%',

            'current' => $current_page,

            'total' => $total_pages,

            'prev_text'    => __('« Prev'),

            'next_text'    => __('Next »'),

      ));

    }    

}

wp_reset_postdata();

?>




<!--- LOOP WORDPRESS MENGGUNAKAN FOREACH --------->

<?php

$args = array(

    'post_type' => 'post',

    'posts_per_page' => 2,

    'orderby' => 'date',

    'order' => 'DESC'

);


$posts = get_posts($args);


foreach ($posts as $post) {

    setup_postdata($post);

?>

    <article>

        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

        <div class="meta"><?php the_date(); ?> by <?php the_author(); ?></div>

        <?php the_excerpt(); ?>

    </article>

<?php

}


wp_reset_postdata();

?>










<!-------------COMMENT FORM WORDPRESS DEFAULT -------->

<?php //comment_form(); ?>


<?php

  if ( comments_open() || get_comments_number() ) {

     comments_template();

  }

?>




<!------ CUSTEM COMMENTAR DENGAN BOOTSTRAP-->

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">


<?php

  // Tampilkan form komentar dengan tampilan Bootstrap

  comment_form( array(

    'class_form'      => 'comment-form',

    'class_submit'    => 'btn btn-primary',

    'submit_button'   => '<button name="%1$s" type="submit" id="%2$s" class="%3$s">%4$s</button>',

    'submit_field'    => '<div class="form-submit">%1$s %2$s</div>',

    'title_reply'     => __( 'Leave a Reply', 'bootstrap' ),

    'title_reply_to'  => __( 'Leave a Reply to %s', 'bootstrap' ),

    'cancel_reply_link' => __( 'Cancel reply', 'bootstrap' ),

    'label_submit'    => __( 'Post Comment', 'bootstrap' ),

    'comment_field'   => '

      <div class="form-group comment-form-comment">

        <label for="comment">' . __( 'Comment', 'bootstrap' ) . '</label>

        <textarea id="comment" name="comment" class="form-control" rows="8" required></textarea>

      </div>

    ',

    'fields'          => array(

      'author' =>

        '<div class="form-group comment-form-author">

          <label for="author">' . __( 'Name', 'bootstrap' ) . '</label> ' .

          ( $req ? '<span class="required">*</span>' : '' ) .

          '<input id="author" name="author" type="text" class="form-control" value="' . esc_attr( $commenter['comment_author'] ) .

          '" required />

        </div>',

      'email' =>

        '<div class="form-group comment-form-email">

          <label for="email">' . __( 'Email', 'bootstrap' ) . '</label> ' .

          ( $req ? '<span class="required">*</span>' : '' ) .

          '<input id="email" name="email" type="email" class="form-control" value="' . esc_attr( $commenter['comment_author_email'] ) .

          '" required />

        </div>',

      'url' =>

        '<div class="form-group comment-form-url">

          <label for="url">' . __( 'Website', 'bootstrap' ) . '</label>

          <input id="url" name="url" type="url" class="form-control" value="' . esc_attr( $commenter['comment_author_url'] ) . '" />

        </div>',

    ),

  ) );

  //Tinggal Mengganti Nama Class Pada DIV dan INPUT

?>











<!-----------------------PENCARIAN DATA ------------>

<!---------------------- search_form.php ------------->

<form action="<?php echo home_url( '/' ); ?>" method="get">

  <input type="search" name="s">

  <input type="submit" value="Search">

  <input type="hidden" name="post_type" value="kb_article">

</form>


<!------------------------  search.php  ------------->

<?php if ( have_posts() ) : ?>

    <?php while ( have_posts() ) : the_post(); ?>

            <?= the_title(); ?>

            <?php the_post_thumbnail(); ?><br>

            <?= the_excerpt(); ?>

            <a href="<?= the_permalink(); ?>" class="btn btn-danger">Selengkapnya</a>

    <?php endwhile; ?>

<?php endif; ?>





<!---------------------- ADVANCE CUSTUME FIELDS ------------------------------------>

<!-----------------Menampilkan Input Dari Plugin Advance Custume Fields------------->

<?php the_field('id_youtube') ?>


<!-----------------Loop Menampilkan Input Dari Plugin Advance Custume Fields------------->

<?php

//Advance Custume Fields

$gambar=get_field('gallery');

if($gambar): ?>

    <?php foreach($gambar as $gambars) : ?>

        <img src="<?= $gambars; ?>" alt="" srcset="">

    <?php endforeach; ?>

<?php endif; ?>




<!-- MENGHILANGKAN MENU CUSTOME POSTYPE ATAU PLUGIN SESUAI ROOL USERNYA  -->

<?php

function wpse28782_remove_menu_items() {

    if(!current_user_can( 'administrator' ) ):

        remove_menu_page( 'edit.php?post_type=acf-field-group' );

    endif;

}

add_action( 'admin_menu', 'wpse28782_remove_menu_items' );

?>





<!------------------------- WIDGET --------------------->

<!-- register sidebar di function.php -->

<?php

/**

 * Register our sidebars and widgetized areas.

 *

 */

function loader1_widgets_init() {

 

  register_sidebar( array(

      'name'          => 'Loader Banner 1',

      'id'            => 'banner-loader1',

      'before_widget' => '<div>',

      'after_widget'  => '</div>',

      'before_title'  => '<h2 class="rounded">',

      'after_title'   => '</h2>',

  ) );


}

add_action( 'widgets_init', 'loader1_widgets_init' );


?>

<!-- buat sidebar.php , sesuaikan nama widget-->

<aside id="sidebar">

  <?php dynamic_sidebar( 'Loader Banner 1' ); ?>

</aside>










<!-------------------------- style.css -------------------->

<style>

/*

Theme Name: Rhistu Thema

Theme URI: https://wordpress.org/themes/twentyseventeen/

Author: Rhistu

Author URI: https://wordpress.org/

Description: Twenty Seventeen brings your site to life with immersive featured 

images and subtle animations. With a focus on business sites, it features multiple 

sections on the front page as well as widgets, navigation and social menus, a logo, 

and more. Personalize its asymmetrical grid with a custom color scheme and showcase 

your multimedia content with post formats. Our default theme for 2017 works great 

in many languages, for any abilities, and on any device.

Version: 1.0

License: GNU General Public License v2 or later

License URI: http://www.gnu.org/licenses/gpl-2.0.html

Text Domain: twentyseventeen

Tags: one-column, two-columns, right-sidebar, flexible-header, accessibility-ready, 

custom-colors, custom-header, custom-menu, custom-logo, editor-style, 

featured-images, footer-widgets, post-formats, rtl-language-support, sticky-post, 

theme-options, threaded-comments, translation-ready

This theme, like WordPress, is licensed under the GPL.

Use it to make something cool, have fun, and share what you've learned with others.

*/

.wp-menu-image:before { color: red !important; }

</style>





<!----------------- FUNCTION.PHP ---------------------->

<?php


////////////////////////////////// MENGAKTIKAN THUMNAILS POST /////////////////////////////////

add_theme_support( 'post-thumbnails' );

set_post_thumbnail_size( 300, 300);





////////////////////////////////// MEMBATASI JUMLAH HURUF /////////////////////////////////

function filter_function_name( $excerpt ) {

    return substr($excerpt,0,55);


}

add_filter( 'get_the_excerpt', 'filter_function_name' );









////////////////////////////////// MEMBUAT CUSTOME KATERORI POST BAWAAN WORDPRESS /////////////////////////////////

function wporg_register_taxonomy_course() {

  $labels = array(

      'name'              => _x( 'Courses', 'taxonomy general name' ),

      'singular_name'     => _x( 'Course', 'taxonomy singular name' ),

      'search_items'      => __( 'Search Courses' ),

      'all_items'         => __( 'All Courses' ),

      'parent_item'       => __( 'Parent Course' ),

      'parent_item_colon' => __( 'Parent Course:' ),

      'edit_item'         => __( 'Edit Course' ),

      'update_item'       => __( 'Update Course' ),

      'add_new_item'      => __( 'Add New Course' ),

      'new_item_name'     => __( 'New Course Name' ),

      'menu_name'         => __( 'Course' ),

  );

  $args   = array(

      'hierarchical'      => true, // make it hierarchical (like categories)

      'labels'            => $labels,

      'show_ui'           => true,

      'show_admin_column' => true,

      'query_var'         => true,

      'rewrite'           => [ 'slug' => 'course' ],

  );

  register_taxonomy( 'course', [ 'post' ], $args );

}

add_action( 'init', 'wporg_register_taxonomy_course' );















////////////////////////////////// MEMBUAT POST TYPE MODEL LAMA /////////////////////////////////

add_action( 'init', 'work_register' );   


function work_register() {   


    $labels = array( 

        'name' => _x('Work', 'post type general name'), 

        'singular_name' => _x('Work Item', 'post type singular name'), 

        'add_new' => _x('Add New', 'work item'), 

        'add_new_item' => __('Add New Work Item'), 

        'edit_item' => __('Edit Work Item'), 

        'new_item' => __('New Work Item'), 


        'view_item' => __('View Work Item'), 

        'search_items' => __('Search Work'), 

        'not_found' => __('Nothing found'), 

        'not_found_in_trash' => __('Nothing found in Trash'), 

        'parent_item_colon' => '' 

    );   


    $args = array( 

        'labels' => $labels, 

        'public' => true, 

        'publicly_queryable' => true, 

        'show_ui' => true, 

        'query_var' => true, 

        'menu_icon' => 'dashicons-video-alt3',

        'rewrite' => array( 'slug' => 'work', 'with_front'=> false ), 

        'capability_type' => 'post', 

        'hierarchical' => true,

        'has_archive' => true,  

        'menu_position' => null, 

        'supports' => array('title','editor','thumbnail') 

    );   


    register_post_type( 'work' , $args ); 


    register_taxonomy( 'categories', array('work'), array(

        'hierarchical' => true, 

        'label' => 'Categories', 

        'singular_label' => 'Category', 

        'rewrite' => array( 'slug' => 'categories', 'with_front'=> false )

        )

    );


    register_taxonomy_for_object_type('init', 'categories', 'work',2 ); // Better be safe than sorry

}












////////////////////////////////// MEMBUAT POSTYPE MODEL BARU  /////////////////////////////////

  

function custom_post_type() {

  

  // Set UI labels for Custom Post Type

      $labels = array(

          'name'                => _x( 'Movies', 'Post Type General Name', 'twentytwentyone' ),

          'singular_name'       => _x( 'Movie', 'Post Type Singular Name', 'twentytwentyone' ),

          'menu_name'           => __( 'Movies', 'twentytwentyone' ),

          'parent_item_colon'   => __( 'Parent Movie', 'twentytwentyone' ),

          'all_items'           => __( 'All Movies', 'twentytwentyone' ),

          'view_item'           => __( 'View Movie', 'twentytwentyone' ),

          'add_new_item'        => __( 'Add New Movie', 'twentytwentyone' ),

          'add_new'             => __( 'Add New', 'twentytwentyone' ),

          'edit_item'           => __( 'Edit Movie', 'twentytwentyone' ),

          'update_item'         => __( 'Update Movie', 'twentytwentyone' ),

          'search_items'        => __( 'Search Movie', 'twentytwentyone' ),

          'not_found'           => __( 'Not Found', 'twentytwentyone' ),

          'not_found_in_trash'  => __( 'Not found in Trash', 'twentytwentyone' ),

      );

        

  // Set other options for Custom Post Type

        

      $args = array(

          'label'               => __( 'movies', 'twentytwentyone' ),

          'description'         => __( 'Movie news and reviews', 'twentytwentyone' ),

          'labels'              => $labels,

          // Features this CPT supports in Post Editor

          'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),

          // You can associate this CPT with a taxonomy or custom taxonomy. 

          'taxonomies'          => array( 'genres' ),

          /* A hierarchical CPT is like Pages and can have

          * Parent and child items. A non-hierarchical CPT

          * is like Posts.

          */

          'hierarchical'        => false,

          'public'              => true,

          'show_ui'             => true,

          'show_in_menu'        => true,

          'show_in_nav_menus'   => true,

          'show_in_admin_bar'   => true,

          'menu_icon'           => 'dashicons-video-alt3',

          'menu_position'       => 5,

          'can_export'          => true,

          'has_archive'         => true,

          'exclude_from_search' => false,

          'publicly_queryable'  => true,

          'capability_type'     => 'post',

          'show_in_rest' => true,

    

      );

        

      // Registering your Custom Post Type

      register_post_type( 'movies', $args );


  }

    

  /* Hook into the 'init' action so that the function

  * Containing our post type registration is not 

  * unnecessarily executed. 

  */

    

  add_action( 'init','custom_post_type', 1 );










//////////////////////////////////////////////Metabox Produk Dengan Metabox///////////////////////////////////////////////////////////////////////

  /**

   * Postype Untuk  Produk

   * @package https://www.onphpid.com/category/membuat-semi-toko-online

   * @see : https://www.onphpid.com/langkah-awal-membuat-semi-toko-online-dengan-wordpress.html

   */

  function onphpid_post_type()

  {

      // add post-type

      register_post_type(

          'onphpid_products',

          array(

              'labels' => array(

                'name' => __('Products', 'semi-toko-online'),

                'singular_name' => __('Product', 'semi-toko-online'),

                'add_new'            => _x( 'Add New', 'product', 'semi-toko-online' ),

                'add_new_item'       => __( 'Add New Product', 'semi-toko-online' ),

                'new_item'           => __( 'New Product', 'semi-toko-online' ),

                'edit_item'          => __( 'Edit Product', 'semi-toko-online' ),

                'view_item'          => __( 'View Product', 'semi-toko-online' ),

                'all_items'          => __( 'All Products', 'semi-toko-online' ),

              ),

              'public' => true,

              'supports' => array('title', 'editor', 'thumbnail'),

              'has_archive' => true,

              'rewrite' => array('slug'=>'product'),

              'menu_position' => 100,

              'menu_icon' => 'dashicons-cart'

          )

    );

  }

  

  add_action('init', 'onphpid_post_type');




/**

* Resgistrasi Metabox Produk.

*/

function onphpid_register_meta_boxes()

{

    add_meta_box( 'metabox-price', __( 'Attribut Products', 'semi-toko-online' ), 'onphpid_render_metabox', 'onphpid_products' );

}

 

add_action('add_meta_boxes', 'onphpid_register_meta_boxes');

 

/**

* Meta box display callback.

*

* @param WP_Post $post Current post object.

*/

function onphpid_render_metabox($post)

{

    wp_nonce_field('onphpid-nonce', "meta-box-nonce");

 

    $sku = get_post_meta($post->ID, "meta-box-sku", true);

    $price = get_post_meta($post->ID, "meta-box-price", true);

    $checked = (get_post_meta($post->ID, "meta-box-best", true)) ? 'checked' : '';

    ?>

    <div>

    <table>

        <tr>

            <td><label for="meta-box-sku">SKU</label></td>

            <td>:</td>

            <td><input name="meta-box-sku" type="text" value="<?php echo $sku; ?>"></td>

        </tr>

        <tr>

            <td><label for="meta-box-price">Price</label></td>

            <td>:</td>

            <td>

                <input name="meta-box-price" type="text" value="<?php echo $price; ?>">

            </td>

        </tr>

        <tr>

            <td><label for="meta-box-best">Best Seller</label></td>

            <td>:</td>

            <td>

                <input name="meta-box-best" type="checkbox" value="best-seller" <?php echo $checked;?>>

            </td>

        </tr>

    </table>

    

    </div>

 

    <?php

 

}




/**

* Simpan Metabox Produk

*

* @param int $post_id Post ID

*/

function onphpid_save_meta_box($post_id)

{

    // Save logic goes here. Don't forget to include nonce checks!

     if (!isset($_POST["meta-box-nonce"]) || !wp_verify_nonce($_POST["meta-box-nonce"], 'onphpid-nonce')) {

          return $post_id;

     }

     if (!current_user_can("edit_post", $post_id)) {

        return $post_id;

     }

 

    if (defined("DOING_AUTOSAVE") && DOING_AUTOSAVE) {

        return $post_id;

    }

 

    $sku = $_POST['meta-box-sku'];

    $price = $_POST['meta-box-price'];

    $checked = $_POST['meta-box-best'];

 

    update_post_meta($post_id, 'meta-box-sku', $sku);

    update_post_meta($post_id, 'meta-box-price', $price);

    update_post_meta($post_id, 'meta-box-best', $checked);

}

add_action('save_post', 'onphpid_save_meta_box');



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////











////////////////////////////////// MEMBUAT POST TYPE dokter /////////////////////////////////

add_action( 'init', 'dokter_register' );   


function dokter_register() {   


    $labels = array( 

        'name' => _x('dokter', 'post type general name'), 

        'singular_name' => _x('dokter Item', 'post type singular name'), 

        'add_new' => _x('Add New', 'dokter item'), 

        'add_new_item' => __('Add New dokter Item'), 

        'edit_item' => __('Edit dokter Item'), 

        'new_item' => __('New dokter Item'), 


        'view_item' => __('View dokter Item'), 

        'search_items' => __('Search dokter'), 

        'not_found' => __('Nothing found'), 

        'not_found_in_trash' => __('Nothing found in Trash'), 

        'parent_item_colon' => '' 

    );   


    $args = array( 

        'labels' => $labels, 

        'public' => true, 

        'publicly_queryable' => true, 

        'show_ui' => true, 

        'query_var' => true, 

        'menu_icon' => 'dashicons-welcome-learn-more',

        'rewrite' => array( 'slug' => 'dokter', 'with_front'=> false ), 

        'capability_type' => 'post', 

        'hierarchical' => true,

        'has_archive' => true,  

        'menu_position' => null, 

        'supports' => array('title','thumbnail') 

    );   


    register_post_type( 'dokter' , $args ); 


    register_taxonomy( 'categories', array('dokter'), array(

        'hierarchical' => true, 

        'label' => 'Categories', 

        'singular_label' => 'Category', 

        'rewrite' => array( 'slug' => 'categories', 'with_front'=> false )

        )

    );


    register_taxonomy_for_object_type('init', 'categories', 'dokter',2 ); // Better be safe than sorry

}







///menghilangkan tulisan powered by worpress

function wpse_edit_footer() {

    add_filter( 'admin_footer_text', 'wpse_edit_text', 11 );

    }

    

    function wpse_edit_text($content) {

    return "Developer By Ristatul Anwar";

    }

    

    add_action( 'admin_init', 'wpse_edit_footer' );





// Menghilangkan Notifikasi Update plugin

function remove_core_updates (){

global $wp_version ; return ( object ) array ( 

        'last_checked' => time (),

        'version_checked' => $wp_version,

    );

}

add_filter ( 'pre_site_transient_update_core' , 'remove_core_updates' );

add_filter ( 'pre_site_transient_update_plugins' , 'remove_core_updates' );

add_filter ( 'pre_site_transient_update_themes' , 'remove_core_updates' );






//Kode Untuk Menyembunyikan dan Menampilkan Menu Yang Diinginkan


add_action( 'admin_menu', 'remove_admin_menus' );

add_action( 'admin_menu', 'remove_admin_submenus' );


//Remove top level admin menus

function remove_admin_menus() {

remove_menu_page( 'edit-comments.php' );

remove_menu_page( 'link-manager.php' );

remove_menu_page( 'tools.php' );

remove_menu_page( 'plugins.php' );

remove_menu_page( 'users.php' );

remove_menu_page( 'options-general.php' );

remove_menu_page( 'upload.php' );

// remove_menu_page( 'edit.php' );

// remove_menu_page( 'edit.php?post_type=page' );

remove_menu_page( 'themes.php' );

}


//Remove sub level admin menus

function remove_admin_submenus() {

remove_submenu_page( 'themes.php', 'theme-editor.php' );

remove_submenu_page( 'themes.php', 'themes.php' );

remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=post_tag' );

remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=category' );

remove_submenu_page( 'edit.php', 'post-new.php' );

// remove_submenu_page( 'themes.php', 'nav-menus.php' );

remove_submenu_page( 'themes.php', 'widgets.php' );

remove_submenu_page( 'themes.php', 'theme-editor.php' );

remove_submenu_page( 'plugins.php', 'plugin-editor.php' );

remove_submenu_page( 'plugins.php', 'plugin-install.php' );

remove_submenu_page( 'users.php', 'users.php' );

remove_submenu_page( 'users.php', 'user-new.php' );

remove_submenu_page( 'users.php', 'profile.php' );

remove_submenu_page( 'upload.php', 'media-new.php' );

remove_submenu_page( 'options-general.php', 'options-writing.php' );

remove_submenu_page( 'options-general.php', 'options-discussion.php' );

remove_submenu_page( 'options-general.php', 'options-reading.php' );

remove_submenu_page( 'options-general.php', 'options-discussion.php' );

remove_submenu_page( 'options-general.php', 'options-media.php' );

remove_submenu_page( 'options-general.php', 'options-privacy.php' );

remove_submenu_page( 'options-general.php', 'options-permalinks.php' );

remove_submenu_page( 'index.php', 'update-core.php' );

}





// Merubah Nama Menu Admin wordpress

function change_admin_menu_labels() {

    global $menu;

  

    $menu[2][0] = 'Beranda';

    $menu[5][0] = 'Konten';

    $menu[10][0] = 'Media';

    $menu[20][0] = 'Halaman';

    $menu[25][0] = 'Komentar';

    $menu[50][0] = 'Tampilan';

    $menu[55][0] = 'Plugin';

    $menu[60][0] = 'Pengguna';

  }

  add_action( 'admin_menu', 'change_admin_menu_labels' );

  




//MENONAKTIFKAN MENU ADVACE CUSTUME FIELD

function wpse28782_remove_menu_items() {

    if(!current_user_can( 'administrator' ) ):

        remove_menu_page( 'edit.php?post_type=acf-field-group' );

    endif;

}

add_action( 'admin_menu', 'wpse28782_remove_menu_items' );



?>






<!----- Script WA MELAYANG ------------>

<a href="https://api.whatsapp.com/send?phone=6285747899098">

<img src="https://hantamo.com/free/whatsapp.svg" class="wabutton" alt="Whatsapp-Button" />

</a>

<style>

.wabutton{

width:50px;

height:50px;

position:fixed;

bottom:20px;

right:20px;

z-index:100;

}

</style>






<?php 

//POST VIEW MANUAL TANPA PLUGIN


//REGISTER DI FUNCTION 

function post_views_counter() {

  $count = get_post_meta(get_the_ID(), 'post_views', true);

  $count = $count ? $count : 0;

  echo '<div class="post-views"><i class="fa fa-eye"></i> '.$count.'</div>';

}


function set_post_views() {

  if (is_single()) {

      $postID = get_the_ID();

      $count = (int)get_post_meta($postID, 'post_views', true);

      $count++;

      update_post_meta($postID, 'post_views', $count);

  }

}


add_action('wp_head', 'set_post_views');


///TARUH DI SINGLE.php, PAGE.php,

post_views_counter(); 



//JIKA INGIN MENGGUNAKAN PLUGIN  BISA MENGGUNAKAN 

WP PostViews

//DAN COPYKAN CODE BERIKUT UNTUK MENAMPILKAN POST VIEW

if(function_exists('the_views')) { the_views(); }


?>







<?php


// NON AKTIFKAN PILIHAN BAHASA LOGIN WORDPRESS

add_filter( 'login_display_language_dropdown', '__return_false' );




// MENGGANTI LOGO LOGIN WORDPRESS

function ppwp_custom_login_logo() { ?>

  <style type="text/css">

      #login h1 a, .login h1 a {

background-image: url(http://localhost/wordpress/wp-content/uploads/2023/04/logo.png);

      height:100px;

      width:300px;

      background-size: 150px 100px;

      background-repeat: no-repeat;

      padding-bottom: 10px;

      }

  </style>

<?php }

add_action( 'login_enqueue_scripts', 'ppwp_custom_login_logo' );



?>

 

Ad Placement