Skip to content

Instantly share code, notes, and snippets.

Avatar

GaSatrya satrya

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / gallery.php
Last active Sep 19, 2020
Custom slideshow gallery format
View gallery.php
@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
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 );