Exclude admin di recent comments widget WordPress

Bagaimana cara supaya administrator atau owner yang komentar di blognya sendiri tidak muncul (exclude) di recent comments widget blog WordPress?. Tanpa harus menggunakan plugin tambahan, Anda bisa memasang function berikut di file functions.php theme WordPress Anda.

add_filter('widget_comments_args', '_jv_filter_recent_comments_widget');
function _jv_filter_recent_comments_widget(){
	// get data from database table wp_options with option_name 'widget_recent-comments'
	$instance = array_shift(get_option('widget_recent-comments'));
	$number = absint($instance['number']);
	$args = array(
		'number' => $number,
		'status'  => 'approve',
		'post_status' => 'publish',
		'author__not_in' => 1, // '1' is user id of administrator/owner
        );
	return $args;
}

Save pekerjaan Anda and see the result.

Jadi, kecuali owner blog, para pengunjung lain yang komentar di blog Anda tetap ada di recent comments (komentar terbaru) widget.


 Share

Cara mendapatkan gambar pertama dalam konten WordPress

Function berikut adalah cara untuk mendapatkan gambar pertama dalam konten di blog WordPress. Jika konten Anda tidak terdapat gambar maka akan diambil gambar default yang telah Anda sisipkan url gambarnya dalam kode berikut.

function get_first_image() {
  if ($first_img = wp_get_attachment_thumb_url(get_post_thumbnail_id($post->ID))){
  return $first_img;
  }
  else {
 global $post, $posts;  
$first_img = '';
 ob_start();  
 ob_end_clean();  
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches) ;
$first_img = $matches [1] [0];
}
	if(empty($first_img)){
		$first_img = "http://www.namadomainanda.com/wp-content/uploads/2012/default.jpg";
		}
	return $first_img;
}

Ganti http://www.namadomainanda.com/wp-content/uploads/2012/default.jpg dengan url gambar default Anda. Untuk memanggil function ini terapkan kode berikut:

<?php if (function_exists('get_first_image')) {echo get_first_image(); }?>

Kode remove_filter & add_filter di Functions WordPress

Fungsi remove_filter dan add_filter berikut akan menghapus fungsi standar yang ada pada filter core WordPress. Misalnya untuk menghilangkan kode <p> yang otomatis membentuk paragraf di single post, terapkan kode remove_filter('the_content', 'wpautop'); di functions.php. Baca juga fungsi remove_action di Functions WordPress

Pada Halaman Full Content

remove_filter('the_content', 'wpautop'); //menghilangkan kode <p> di konten single post
remove_filter('the_content', 'wptexturize'); //This returns given text with transformations of quotes to smart quotes, apostrophes, dashes, ellipses, the trademark symbol, and the multiplication symbol. Text enclosed in the tags <pre>, <code>, <kbd>, <style>, <script>, <tt>, and 1 will be skipped.
remove_filter('the_content', 'convert_chars'); //Metadata tags <title> and <category> are removed, <br> and <hr> are converted into correct XHTML and Unicode characters are converted to the valid range. 
remove_filter('the_content', 'convert_smilies'); //Will only convert smilies if the option 'use_smilies' is true and the globals used in the function aren't empty.

Pada Halaman Excerpt

remove_filter('the_excerpt', 'wpautop');
remove_filter('the_excerpt', 'wptexturize');
remove_filter('the_excerpt', 'convert_chars');
remove_filter('the_excerpt', 'convert_smilies');

Pada Halaman Comment
Fungsi berikut misalnya untuk menghilangkan link pada kolom komentar

remove_filter('comment_text', 'make_clickable', 9); //Disable link di kolom komentar WP
add_filter('comment_text', 'wp_filter_nohtml_kses'); //Disable html tags in comment
add_filter('comment_text_rss', 'wp_filter_nohtml_kses'); //Disable html tags in comment RSS
add_filter('comment_excerpt', 'wp_filter_nohtml_kses'); //Disable html tags in comment excerpt

Kode remove_action di Functions WordPress

Secara default blog WordPress menampilkan beberapa fungsi di theme WordPress seperti menampilkan rss feed, wp generator, rel canonical atau yang lainnya. Cara menghilangkan fungsi-fungsi tersebut, terapkan kode-kode berikut di functions.php theme WP Anda:

remove_action( 'wp_head', 'feed_links_extra', 3 ); //menghilangkan feed
remove_action( 'wp_head', 'feed_links', 2 ); //menghilangkan feed
remove_action( 'wp_head', 'rsd_link' ); //menghilangkan feed
remove_action( 'wp_head', 'wlwmanifest_link' ); //menghilangkan wlwmanifest link
remove_action( 'wp_head', 'index_rel_link' );  //menghilangkan link rel index
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); //menghilangkan parent post rel link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );  //menghilangkan start post rel link
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); //menghilangkan adjacent posts rel link
remove_action( 'wp_head', 'wp_generator' ); //menghilangkan generator wp
remove_action( 'do_feed_rdf', 'do_feed_rdf', 10, 1 ); //menghilangkan feed rdf
remove_action( 'do_feed_rss', 'do_feed_rss', 10, 1 ); //menghilangkan feed rss
remove_action( 'do_feed_rss2', 'do_feed_rss2', 10, 1 ); //menghilangkan feed rss2
remove_action( 'do_feed_atom', 'do_feed_atom', 10, 1 ); //menghilangkan feed atom
remove_action( 'wp_head', 'rel_canonical' ); //menghilangkan rel canonical