Skip to content

Instantly share code, notes, and snippets.

Avatar

GaSatrya satrya

View GitHub Profile
@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
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 / 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 / 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 / gallery.php
Last active Sep 19, 2020
Custom slideshow gallery format
View gallery.php
@satrya
satrya / add-fields.php
Created Jul 16, 2013
Add custom fields to the author profile fields WordPress
View add-fields.php
<?php
add_filter( 'user_contactmethods', 'my_new_contactmethods', 10, 1 );
/**
* Add custom fields to the author profile fields
*
*/
function my_new_contactmethods( $contactmethods ) {
$contactmethods['twitter'] = 'Twitter'; // Add Twitter
@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;
@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;
}