8个最新的好用的WordPress hacks

8 New and amazing WordPress hacks

翻译自编程的猫~首段不翻译了,直接进入代码段。

修改WordPress编辑器的字体

不喜欢WordPress编辑器的默认字体?没问题,下面的代码可以帮助你修改它。只需要把这段代码粘贴到你的主题的functions.php文件就可以了。你可以修改第五行中的字体来获得你要的效果。

add_action( 'admin_head-post.php', 'cwc_fix_html_editor_font' );
add_action( 'admin_head-post-new.php', 'cwc_fix_html_editor_font' );

function cwc_fix_html_editor_font() { ?>

<style type="text/css">#editorcontainer #content, #wp_mce_fullscreen { font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif; }</style>
<?php }

来源:http://devpress.com/blog/fixing-wordpress-3-2s-html-editor-font/

快速简单的维护模式

有些时候,当你维护的时候你需要暂时关闭你的博客。许多插件可以让你做到这一点,但是这里有个更简单的方法:只要将下面的代码粘贴到你的主题中的functions.php文件中并保存,你的博客现在对除管理员外的人是不开放的。当然,别忘了在维护后去掉这段代码哦!

function cwc_maintenance_mode() {
    
if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
        
wp_die('Maintenance, please come back soon.');
    
}
}
add_action('get_header', 'cwc_maintenance_mode');

来源: http://skyje.com/2011/05/wordpress-code-snippets/

更简单的登录URL链接

你想用这样一个简单的链接来登录后台吗:http://ineyes.org/login。如果是的话,阅读这个方法并使用吧!

打开你的.htaccess文件(在你的WordPress安装目录下),加入以下的代码。别忘了编辑前先备份!

RewriteRule ^login$ http://yoursite.com/wp-login.php [NC,L]

来源: http://www.wprecipes.com/simpler-wordpress-login-url

屏蔽风格改变

当你为客户维护时,最好能控制好,避免可能的问题发生。例如,屏蔽改变风格是一个好主意,特别是你建立的站很依赖风格的话。要屏蔽的话,把下面的代码粘贴到风格的functions.php文件中。这样一做,客户就不能去改变风格了。

add_action('admin_init', 'cwc_lock_theme');
function cwc_lock_theme() {
    
global $submenu, $userdata;
    
get_currentuserinfo();
    
if ($userdata->ID != 1) {
        
unset($submenu['themes.php'][5]);
        
unset($submenu['themes.php'][15]);
    
}
}

来源: http://sltaylor.co.uk/blog/disabling-wordpress-plugin-deactivation-theme-changing/

屏蔽RSS feed

默认情况下,WordPress包括了流行的RSS功能,这个功能对Blog来说挺有用的。但是如果你建立一个静态的WordPress站点的话,用RSS订阅功能也许会让访客们感到很迷惑。

这段代码会在你的站点完全屏蔽RSS feed(还有其他类似的格式)。将下面的代码加入functions.php即可。

function cwc_disable_feed() {
    
wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') );
}
add_action('do_feed', 'cwc_disable_feed', 1);
add_action('do_feed_rdf', 'cwc_disable_feed', 1);
add_action('do_feed_rss', 'cwc_disable_feed', 1);
add_action('do_feed_rss2', 'cwc_disable_feed', 1);
add_action('do_feed_atom', 'cwc_disable_feed', 1);

来源: http://wpengineer.com/287/disable-wordpress-feed/

自定义文章类型过滤器

这个函数可以为用户在已存在的过滤器旁边(默认是日期)增加一个下拉菜单。它也可以和作者过滤器一起使用,也就是当你在管理页面点击一个作者的时候会显示的(默认是文章和页面)。

和上面一样,添加以下代码到functions.php文件就可以了。

function cwc_restrict_manage_authors() {
        
if (isset($_GET['post_type']) && post_type_exists($_GET['post_type']) && in_array(strtolower($_GET['post_type']), array('your_custom_post_types', 'here'))) {
                
wp_dropdown_users(array(
                        
'show_option_all'       => 'Show all Authors',
                        
'show_option_none'      => false,
                        
'name'                  => 'author',
                        
'selected'              => !empty($_GET['author']) ? $_GET['author'] : 0,
                        
'include_selected'      => false
                
));
        
}
}
add_action('restrict_manage_posts', 'cwc_restrict_manage_authors');

来源: http://forrst.com/posts/WordPress_Custom_Post_Types_Filter_by_Author_in-s9p

在RSS订阅中加入文章缩略图

这是一段非常酷的代码,它会自动在RSS feeds中加入文章的缩略图。在functions.php中加入以下代码。不要忘记你的风格需要支持文章缩略图。

function cwc_rss_post_thumbnail($content) {
    
global $post;
    
if(has_post_thumbnail($post->ID)) {
        
$content = '<p>' . get_the_post_thumbnail($post->ID) .
        
'</p>' . get_the_content();
    
}
 
    
return $content;
}
add_filter('the_excerpt_rss', 'cwc_rss_post_thumbnail');
add_filter('the_content_feed', 'cwc_rss_post_thumbnail');

来源: http://snipplr.com/view.php?codeview&id=56180

移除WordPress管理工具栏

WordPress 3.x版本中引入的管理工具栏是一个很好用的特性,但是如果你不喜欢它,可以移除它。添加以下代码到functions.php文件中。

add_filter('show_admin_bar', '__return_false');

来源: http://speckyboy.com/2011/03/01/how-to-remove-the-admin-bar-from-wordpress-3-1/

原文链接:http://www.catswhocode.com/blog/8-new-and-amazing-wordpress-hacks

,

还没有评论~

发表评论

QR Code Business Card