Bueno, Este código lo debeis de introducir en el archivo functions.php de vuestra plantilla:
Cita:
Lo que hace es añadir campos personalizados para las páginas y las entradas individuales, (Título, descripción y keyword)
Código PHP:
add_action('admin_init', 'mirror1_add_custom_box', 1);
function mirror1_add_custom_box() {
add_meta_box(
'id_mirror1',
'Titulo',
'wp_box_mirror1',
'post'
);
}
function wp_box_mirror1($post) {
wp_nonce_field(plugin_basename(__FILE__), 'mirror1_noncename');
if($_GET['action']=='edit'){
$mirror1=get_post_meta($post->ID,'mirror1',true);
echo'<input name="mirror1" type="text" value="'.$mirror1.'" style="width:100%" />';
}else{
echo'<input name="mirror1" type="text" value="" style="width:100%" />';
}
}
add_action('save_post', 'guardar_mirror1');
function guardar_mirror1($post_id){
if ( !wp_verify_nonce( $_POST['mirror1_noncename'], plugin_basename(__FILE__) ) )
return $post_id;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return $post_id;
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
delete_post_meta($post_id, 'mirror1');
if(!empty($_POST['mirror1'])){
add_post_meta($post_id, 'mirror1', esc_attr($_POST['mirror1']));
}
}
add_action('admin_init', 'mirror2_add_custom_box', 1);
function mirror2_add_custom_box() {
add_meta_box(
'id_mirror2',
'Descripcion',
'wp_box_mirror2',
'post'
);
}
function wp_box_mirror2($post) {
wp_nonce_field(plugin_basename(__FILE__), 'mirror2_noncename');
if($_GET['action']=='edit'){
$mirror2=get_post_meta($post->ID,'mirror2',true);
echo'<input name="mirror2" type="text" value="'.$mirror2.'" style="width:100%" />';
}else{
echo'<input name="mirror2" type="text" value="" style="width:100%" />';
}
}
add_action('save_post', 'guardar_mirror2');
function guardar_mirror2($post_id){
if ( !wp_verify_nonce( $_POST['mirror2_noncename'], plugin_basename(__FILE__) ) )
return $post_id;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return $post_id;
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
delete_post_meta($post_id, 'mirror2');
if(!empty($_POST['mirror2'])){
add_post_meta($post_id, 'mirror2', esc_attr($_POST['mirror2']));
}
}
add_action('admin_init', 'mirror3_add_custom_box', 1);
function mirror3_add_custom_box() {
add_meta_box(
'id_mirror3',
'Etiquetas',
'wp_box_mirror3',
'post'
);
}
function wp_box_mirror3($post) {
wp_nonce_field(plugin_basename(__FILE__), 'mirror3_noncename');
if($_GET['action']=='edit'){
$mirror3=get_post_meta($post->ID,'mirror3',true);
echo'<input name="mirror3" type="text" value="'.$mirror3.'" style="width:100%" />';
}else{
echo'<input name="mirror3" type="text" value="" style="width:100%" />';
}
}
add_action('save_post', 'guardar_mirror3');
function guardar_mirror3($post_id){
if ( !wp_verify_nonce( $_POST['mirror3_noncename'], plugin_basename(__FILE__) ) )
return $post_id;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return $post_id;
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
delete_post_meta($post_id, 'mirror3');
if(!empty($_POST['mirror3'])){
add_post_meta($post_id, 'mirror3', esc_attr($_POST['mirror3']));
}
}
add_action('admin_init', 'mirror4_add_custom_box', 1);
function mirror4_add_custom_box() {
add_meta_box(
'id_mirror4',
'Titulo',
'wp_box_mirror4',
'page'
);
}
function wp_box_mirror4($post) {
wp_nonce_field(plugin_basename(__FILE__), 'mirror4_noncename');
if($_GET['action']=='edit'){
$mirror4=get_post_meta($post->ID,'mirror4',true);
echo'<input name="mirror4" type="text" value="'.$mirror4.'" style="width:100%" />';
}else{
echo'<input name="mirror4" type="text" value="" style="width:100%" />';
}
}
add_action('save_post', 'guardar_mirror4');
function guardar_mirror4($post_id){
if ( !wp_verify_nonce( $_POST['mirror4_noncename'], plugin_basename(__FILE__) ) )
return $post_id;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return $post_id;
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
delete_post_meta($post_id, 'mirror4');
if(!empty($_POST['mirror4'])){
add_post_meta($post_id, 'mirror4', esc_attr($_POST['mirror4']));
}
}
add_action('admin_init', 'mirror5_add_custom_box', 1);
function mirror5_add_custom_box() {
add_meta_box(
'id_mirror5',
'Descripcion',
'wp_box_mirror5',
'page'
);
}
function wp_box_mirror5($post) {
wp_nonce_field(plugin_basename(__FILE__), 'mirror5_noncename');
if($_GET['action']=='edit'){
$mirror5=get_post_meta($post->ID,'mirror5',true);
echo'<input name="mirror5" type="text" value="'.$mirror5.'" style="width:100%" />';
}else{
echo'<input name="mirror5" type="text" value="" style="width:100%" />';
}
}
add_action('save_post', 'guardar_mirror5');
function guardar_mirror5($post_id){
if ( !wp_verify_nonce( $_POST['mirror5_noncename'], plugin_basename(__FILE__) ) )
return $post_id;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return $post_id;
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
delete_post_meta($post_id, 'mirror5');
if(!empty($_POST['mirror5'])){
add_post_meta($post_id, 'mirror5', esc_attr($_POST['mirror5']));
}
}
add_action('admin_init', 'mirror6_add_custom_box', 1);
function mirror6_add_custom_box() {
add_meta_box(
'id_mirror6',
'Etiquetas',
'wp_box_mirror6',
'page'
);
}
function wp_box_mirror6($post) {
wp_nonce_field(plugin_basename(__FILE__), 'mirror6_noncename');
if($_GET['action']=='edit'){
$mirror6=get_post_meta($post->ID,'mirror6',true);
echo'<input name="mirror6" type="text" value="'.$mirror6.'" style="width:100%" />';
}else{
echo'<input name="mirror6" type="text" value="" style="width:100%" />';
}
}
add_action('save_post', 'guardar_mirror6');
function guardar_mirror6($post_id){
if ( !wp_verify_nonce( $_POST['mirror6_noncename'], plugin_basename(__FILE__) ) )
return $post_id;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return $post_id;
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
delete_post_meta($post_id, 'mirror6');
if(!empty($_POST['mirror6'])){
add_post_meta($post_id, 'mirror6', esc_attr($_POST['mirror6']));
}
}
Cita:
Esto añade nuestros campos personalizados al frontend de la web.
Código PHP:
<?php if ( is_single() ) : ?><?php if ( get_post_meta( get_the_ID(), 'mirror1', true ) ) : ?><title><?php echo get_post_meta( get_the_ID(), 'mirror1', true ) ?></title><?php else : ?><title><?php wp_title( '«', true, 'right' ); ?><?php bloginfo( 'name' ); ?></title><?php endif; ?><?php else : ?><?php if ( get_post_meta( get_the_ID(), 'mirror4', true ) ) : ?><title><?php echo get_post_meta( get_the_ID(), 'mirror4', true ) ?></title><?php else : ?><title><?php wp_title( '«', true, 'right' ); ?><?php bloginfo( 'name' ); ?></title><?php endif; ?><?php endif; ?>
<?php if ( get_post_meta( get_the_ID(), 'mirror2', true ) ) : ?><meta name="description" content="<?php echo get_post_meta( get_the_ID(), 'mirror2', true ) ?>"/><?php else : ?><?php endif; ?><?php if ( get_post_meta( get_the_ID(), 'mirror5', true ) ) : ?><meta name="description" content="<?php echo get_post_meta( get_the_ID(), 'mirror5', true ) ?>"/><?php else : ?><?php endif; ?>
<?php if ( get_post_meta( get_the_ID(), 'mirror3', true ) ) : ?><meta name="keywords" content="<?php echo get_post_meta( get_the_ID(), 'mirror3', true ) ?>"/><?php else : ?><?php endif; ?><?php if ( get_post_meta( get_the_ID(), 'mirror6', true ) ) : ?><meta name="keywords" content="<?php echo get_post_meta( get_the_ID(), 'mirror6', true ) ?>"/><?php else : ?><?php endif; ?>
Por ultimo añadimos esto a header.php de nuestra plantilla para activar gzip:
Cita:
Esto activa la compresión en wordpress.
Código PHP:
<?php ini_set('zlib.output_compression', 'on'); ini_set('zlib.output_compression_level', '6'); ?>
Es un metodo válido para activar la compresión gzip en 1and1 de wordpress.