Skip to content

Instantly share code, notes, and snippets.

Avatar

GaSatrya satrya

View GitHub Profile
@satrya
satrya / comments.php
Created Feb 3, 2015
WordPress recent comments w/ avatar
View comments.php
<?php
$comments = get_comments( array(
'number' => 5,
'status' => 'approve',
'post_status' => 'publish'
) );
?>
<?php if ( $comments ) : ?>
<ul>
<?php foreach( $comments as $comment ) : ?>
@satrya
satrya / excerpt.php
Created Jun 9, 2015
Change the WordPress excerpt more string
View excerpt.php
<?php
/**
* Change the excerpt more string.
*
* @since 1.0.0
* @param string $more
* @return string
*/
function prefix_excerpt_more( $more ) {
return '&hellip;';
@satrya
satrya / category.php
Created Jun 9, 2015
WordPress: If the post has several categories, display the first one only.
View category.php
<?php
$category = get_the_category( get_the_ID() );
if ( $category ) :
?>
<span class="entry-category">
<a href="<?php echo esc_url( get_category_link( $category[0]->term_id ) ); ?>"><?php echo esc_attr( $category[0]->name ); ?></a>
</span>
<?php endif; // End if category ?>
@satrya
satrya / excerpt.php
Created Jun 9, 2015
Control WordPress excerpt length
View excerpt.php
<?php
/**
* Control excerpt length.
*/
function prefix_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'prefix_excerpt_length', 999 );
@satrya
satrya / rel.php
Last active Dec 17, 2015 — forked from corsonr/Add rel attribute to wordpress gallery
Add rel attribute to WordPress gallery
View rel.php
<?php
add_filter('wp_get_attachment_link', 'rc_add_rel_attribute');
function rc_add_rel_attribute($link) {
global $post;
return str_replace('<a href', '<a rel="prettyPhoto[pp_gal]" href', $link);
}
?>
@satrya
satrya / thumbnail-list.php
Created Jul 8, 2013
Display all list thumbnail that already registered in WordPress.
View thumbnail-list.php
<?php
function list_thumbnail_sizes(){
global $_wp_additional_image_sizes;
$sizes = array();
foreach( get_intermediate_image_sizes() as $s ){
$sizes[ $s ] = array( 0, 0 );
if( in_array( $s, array( 'thumbnail', 'medium', 'large' ) ) ){
$sizes[ $s ][0] = get_option( $s . '_size_w' );
$sizes[ $s ][1] = get_option( $s . '_size_h' );
}else{
@satrya
satrya / login-logo.php
Created Jul 16, 2013
Replaces WordPress login header logo
View login-logo.php
<?php
add_action( 'login_head', 'namespace_login_style' );
/**
* Replaces the login header logo
*/
function namespace_login_style() {
echo '<style>.login h1 a { background-image: url( ' . get_template_directory_uri() . '/images/logo.png ) !important; }</style>';
}
?>
@satrya
satrya / header-title.php
Created Jul 16, 2013
Replaces WordPress login header logo title
View header-title.php
<?php
add_filter( 'login_headertitle', 'my_login_headertitle' );
/**
* Replaces the login header logo title
*
*/
function my_login_headertitle( $title ) {
$title = get_bloginfo( 'name' );
return $title;
}
@satrya
satrya / remove-fields.php
Created Jul 16, 2013
Remove default author profile fields
View remove-fields.php
<?php
add_filter( 'user_contactmethods', 'hide_profile_fields', 10, 1 );
/**
* Remove default author profile fields
*
*/
function hide_profile_fields( $contactmethods ) {
unset($contactmethods['aim']);
unset($contactmethods['jabber']);
@satrya
satrya / cpt-search.php
Created Jul 16, 2013
Make Custom Post Type searchable
View cpt-search.php
<?php
add_filter( 'the_search_query', 'add_custom_post_type_to_search' );
/**
* Make Custom Post Type searchable
*
*/
function add_custom_post_type_to_search( $query ) {
if ( $query->is_search ) { $query->set( 'post_type', array( 'site', 'plugin', 'theme', 'person' )); }
return $query;