Skip to content

Instantly share code, notes, and snippets.

View gasatrya's full-sized avatar
🏠
Working from home

Ga Satrya gasatrya

🏠
Working from home
View GitHub Profile
@gasatrya
gasatrya / rel.php
Last active December 17, 2015 03:58 — forked from corsonr/Add rel attribute to wordpress gallery
Add rel attribute to WordPress gallery
<?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);
}
?>
@gasatrya
gasatrya / thumbnail-list.php
Created July 8, 2013 07:35
Display all list thumbnail that already registered in WordPress.
<?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{
@gasatrya
gasatrya / header-title.php
Created July 16, 2013 03:42
Replaces WordPress login header logo title
<?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;
}
@gasatrya
gasatrya / login-logo.php
Created July 16, 2013 03:44
Replaces WordPress login header logo
<?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>';
}
?>
@gasatrya
gasatrya / cpt-search.php
Created July 16, 2013 03:50
Make Custom Post Type searchable
<?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;
@gasatrya
gasatrya / remove-fields.php
Created July 16, 2013 03:56
Remove default author profile fields
<?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']);
@gasatrya
gasatrya / add-fields.php
Created July 16, 2013 04:07
Add custom fields to the author profile fields WordPress
<?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
@gasatrya
gasatrya / gallery.php
Last active September 19, 2020 15:34
Custom slideshow gallery format
@gasatrya
gasatrya / comments.php
Created February 3, 2015 17:53
WordPress recent comments w/ avatar
<?php
$comments = get_comments( array(
'number' => 5,
'status' => 'approve',
'post_status' => 'publish'
) );
?>
<?php if ( $comments ) : ?>
<ul>
<?php foreach( $comments as $comment ) : ?>
@gasatrya
gasatrya / excerpt.php
Created June 9, 2015 14:43
Control WordPress excerpt length
<?php
/**
* Control excerpt length.
*/
function prefix_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'prefix_excerpt_length', 999 );