Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1. Añadir Google Analytics
- <?php
- add_action('wp_footer, 'add_googleanalytics');
- function add_googleanalytics() { ?>
- // Pegar aquí el código de Analytics
- <?php } ?>
- // 2. Eliminar versión de WordPress
- function wpbeginner_remove_version() {
- return '';
- }
- add_filter('the_generator', 'wpbeginner_remove_version');
- // 3. Custom dashboard logo
- add_action('admin_head', 'my_custom_logo');
- function my_custom_logo() {
- echo '
- <style type="text/css">
- #header-logo { background-image: url('.get_bloginfo('template_directory').'/images/custom-logo.gif) !important; }
- </style>
- ';
- }
- // 4. Cambiar Gravatar por defecto
- add_filter( 'avatar_defaults', 'newgravatar' );
- function newgravatar ($avatar_defaults) {
- $myavatar = get_bloginfo('template_directory') . '/images/gravatar.gif';
- $avatar_defaults[$myavatar] = "Gravatar personalizado";
- return $avatar_defaults;
- }
- // 5. Añadir más campos de perfil
- function perfil_social( $contactmethods ) {
- // Añadir Twitter
- $contactmethods['twitter'] = 'Twitter';
- // Añadir Facebook
- $contactmethods['facebook'] = 'Facebook';
- return $contactmethods;
- }
- add_filter('user_contactmethods','perfil_social',10,1);
- // 6. Personalizar longitud de extracto
- function new_excerpt_length($length) {
- return 100;
- }
- add_filter('excerpt_length', 'new_excerpt_length');
- // 7. Mover barra de administración
- function admin_bar_abajo() { ?>
- <style type="text/css">
- body {
- margin-top: -28px;
- padding-bottom: 28px;
- }
- body.admin-bar #wphead {
- padding-top: 0;
- }
- body.admin-bar #footer {
- padding-bottom: 28px;
- }
- #wpadminbar {
- top: auto !important;
- bottom: 0;
- }
- #wpadminbar .quicklinks .menupop ul {
- bottom: 28px;
- }
- </style>
- <?php }
- // En panel de administración (Dashboard)
- add_action( 'admin_head', 'admin_bar_abajo' );
- // En el front-end
- add_action( 'wp_head', 'admin_bar_abajo' );
- // 8. Eliminar barra de administración
- wp_deregister_script('admin-bar');
- wp_deregister_style('admin-bar');
- remove_action('wp_footer','wp_admin_bar_render',1000);
- remove_action('init', 'wp_admin_bar_init');
- // 9. Aviso de actualización solo para dministradores
- global $user_login;
- get_currentuserinfo();
- if ($user_login !== "admin") {
- add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
- add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
- }
- // 10. Redireccionar búsqueda
- add_action('template_redirect', 'single_result');
- function single_result() {
- if (is_search()) {
- global $wp_query;
- if ($wp_query->post_count == 1) {
- wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
- }
- }
- }
- // 11. Número total de palabras escritas
- function post_word_count() {
- $count = 0;
- $posts = get_posts( array(
- 'numberposts' => -1,
- 'post_type' => array( 'post', 'page' )
- ));
- foreach( $posts as $post ) {
- $count += str_word_count( strip_tags( get_post_field( 'post_content', $post->ID )));
- }
- $num = number_format_i18n( $count );
- $text = _n( 'Palabra', 'Palabras', $num );
- echo "<tr><td class='first b'>{$num}</td><td class='t'>{$text}</td></tr>";
- }
- add_action( 'right_now_content_table_end', 'post_word_count');
- // 12. Mensaje personalizado al registrarse
- add_action('register_form', 'trw_mensaje_registro');
- function trw_mensaje_registro() {
- $html = '
- <div style="margin:10px 0;border:1px solid #e5e5e5;padding:10px">
- <p style="margin:5px 0;">
- Ya estoy registrado, ¿y ahora qué?
- </p>
- </div>';
- echo $html;
- }
- // 13. Acortar dirección de búsqueda
- function trw_search_url_rule() {
- if ( is_search() && !empty($_GET['s'])) {
- wp_redirect(home_url("/buscar/") . urlencode(get_query_var('s')));
- exit();
- }
- }
- add_action('template_redirect', 'trw_search_url_rule');
- // 14. Mostrar visitas de un artículo
- add_filter('manage_posts_columns', 'posts_column_views');
- add_action('manage_posts_custom_column', 'posts_custom_column_views',5,2);
- function posts_column_views($defaults){
- $defaults['post_views'] = __('Visitas');
- return $defaults;
- }
- function posts_custom_column_views($column_name, $id){
- if($column_name === 'post_views'){
- echo getPostViews(get_the_ID());
- }
- }
- // FIN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement