Más hacks de WordPress que te haran volar la cabeza!!
Categories: Tips de wordpress, Tutoriales, WordpressAyer publique 12 hacks de WordPress impresionantes que no fueron más porque no tenía tiempo y tampoco quería hacer un post muy largo, así que hoy les traigo la segunda parte con más trucos de WordPress.
Tienen sus propios trucos de WordPress? Quieren promocionar su blog con un dofollow link? Entonces envíen sus trucos o hacks de WordPress
Añadir thumbnails a la lista de posts y páginas de WordPress
Con este código añaden una nueva columna en el listado de entradas y páginas para mostrar el thumbnail.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
if ( !function_exists('AddThumbColumn') && function_exists('add_theme_support') ) {
// Agregamos el soporte para páginas y posts
add_theme_support('post-thumbnails', array( 'post', 'page' ) );
function AddThumbColumn($cols) {
$cols['thumbnail'] = __('Thumbnail');
return $cols;
}
function AddThumbValue($column_name, $post_id) {
$width = (int) 35;
$height = (int) 35;
if ( 'thumbnail' == $column_name ) {
// thumbnail
$thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
// o una foto de la galería
$attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
if ($thumbnail_id)
$thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
elseif ($attachments) {
foreach ( $attachments as $attachment_id => $attachment ) {
$thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
}
}
if ( isset($thumb) && $thumb ) {
echo $thumb;
} else {
echo __('None');
}
}
}
// Para los post
add_filter( 'manage_posts_columns', 'AddThumbColumn' );
add_action( 'manage_posts_custom_column', 'AddThumbValue', 10, 2 );
// Para la páginas
add_filter( 'manage_pages_columns', 'AddThumbColumn' );
add_action( 'manage_pages_custom_column', 'AddThumbValue', 10, 2 );
Extender el tiempo de Sesión en WordPress
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | if ( !function_exists('AddThumbColumn') && function_exists('add_theme_support') ) { // Agregamos el soporte para páginas y posts add_theme_support('post-thumbnails', array( 'post', 'page' ) ); function AddThumbColumn($cols) { $cols['thumbnail'] = __('Thumbnail'); return $cols; } function AddThumbValue($column_name, $post_id) { $width = (int) 35; $height = (int) 35; if ( 'thumbnail' == $column_name ) { // thumbnail $thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true ); // o una foto de la galería $attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') ); if ($thumbnail_id) $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true ); elseif ($attachments) { foreach ( $attachments as $attachment_id => $attachment ) { $thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true ); } } if ( isset($thumb) && $thumb ) { echo $thumb; } else { echo __('None'); } } } // Para los post add_filter( 'manage_posts_columns', 'AddThumbColumn' ); add_action( 'manage_posts_custom_column', 'AddThumbValue', 10, 2 ); // Para la páginas add_filter( 'manage_pages_columns', 'AddThumbColumn' ); add_action( 'manage_pages_custom_column', 'AddThumbValue', 10, 2 ); |
Extender el tiempo de Sesión en WordPress
Por defecto cuando haces login en WordPress este graba la sesión por 2 días, si marcas el checkbox de recordar sesión este tiempo se alarga a 15 dias. Con esta pequeña función pueden alargar el tiempo que quieran.
1 2 3 4 | function mqw_extender_tiempo( $expirein ) { return 31556926; // 1 año en segundos } add_filter( 'auth_cookie_expiration', 'mqw_extender_tiempo' ); |
Cambiar el editor de WordPress a HTML por defecto
//Si cambias html por tinymce, este será el editor por defecto
1 | add_filter('wp_default_editor', create_function('', 'return "html";')); |
Mostrar las constantes de WordPress
Muestra todas las variables definidas por WordPress. Bastante útil para aprender que variables absolutas podemos usar.
1 2 3 4 5 | if ( current_user_can('update_plugins') ) { print('<pre>'); print_r( @get_defined_constants() ); print('</pre>'); } |
Saludos!!!



