1. Удаляем вывод версии wordpress.
// remove version info from head and feeds
function complete_version_removal() {
return '';
}
add_filter('the_generator', 'complete_version_removal');
2. Добавить свой логотип в админпанель.
//hook the administrative header output 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> '; }
3. Меняем ссылки в футере админки
function remove_footer_admin () { echo 'Fueled by <a href="http://www.wordpress.org" target="_blank">WordPress</a> | Designed by <a href="http://www.uzzz.net" target="_blank">Uzzz Productions</a> | WordPress Tutorials: <a href="http://www.wpbeginner.com" target="_blank">WPBeginner</a></p>'; } add_filter('admin_footer_text', 'remove_footer_admin');
4. Добавляем произвольный виджет на доску объявлений в админке.
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets'); function my_custom_dashboard_widgets() { global $wp_meta_boxes; wp_add_dashboard_widget('custom_help_widget', 'Theme Support', 'custom_dashboard_help'); } function custom_dashboard_help() { echo '<p>Welcome to Custom Blog Theme! Need help? Contact the developer <a href="mailto:yourusername@gmail.com">here</a>. For WordPress Tutorials visit: <a href="http://www.wpbeginner.com" target="_blank">WPBeginner</a></p>'; }
5. Изменить дефолтные граватарки на сайте.
add_filter( 'avatar_defaults', 'newgravatar' );
function newgravatar ($avatar_defaults) {
$myavatar = get_bloginfo('template_directory') . '/images/gravatar.gif';
$avatar_defaults[$myavatar] = "WPBeginner";
return $avatar_defaults;
}
6. Выводим автора записи через произвольные поля или функция для гостевых постов.
add_filter( 'the_author', 'guest_author_name' );
add_filter( 'get_the_author_display_name', 'guest_author_name' );
function guest_author_name( $name ) {
global $post;
$author = get_post_meta( $post->ID, 'guest-author', true );
if ( $author )
$name = $author;
return $name;
}
7. включить поддержку миниатюр.
add_theme_support( 'post-thumbnails' );
8. включить поддержку функции меню
add_theme_support( 'menus' );
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header' ) ); ?>
9. Удаляем или добавляем необязательные поля при регистрации
add_filter('user_contactmethods','hide_profile_fields',10,1);
function hide_profile_fields( $contactmethods ) {
unset($contactmethods['aim']);
unset($contactmethods['jabber']);
unset($contactmethods['yim']);
return $contactmethods;
}
function my_new_contactmethods( $contactmethods ) {
// Add Twitter
$contactmethods['twitter'] = 'Twitter';
//add Facebook
$contactmethods['facebook'] = 'Facebook';
return $contactmethods;
}
add_filter('user_contactmethods','my_new_contactmethods',10,1);
<?php echo $curauth->twitter; ?>
Понравилась статья? - Подпишись. Или поделись полезным с миром
10. Регистрируем виджеты.
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'MiddleSidebar',
'before_widget' => '<li class="widget">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h3>',
));
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('MiddleSidebar') ) : ?>
<!–Default sidebar info goes here–>
<?php endif; ?>
11. вставляем копирайты в футер
function wpbeginner_postrss($content) {
if(is_feed()){
$content = 'Этот пост написан автором ETNO '.$content.'Посетите сайт http://trend-bag.ru';
}
return $content;
}
add_filter('the_excerpt_rss', 'wpbeginner_postrss');
add_filter('the_content', 'wpbeginner_postrss');
12. вставляем миниатюры в рсс канал
function 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', 'rss_post_thumbnail');
add_filter('the_content_feed', 'rss_post_thumbnail');
13.подключаем вложенные комментарии
// enable threaded comments
function enable_threaded_comments(){
if (!is_admin()) {
if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1))
wp_enqueue_script('comment-reply');
}
}
add_action('get_header', 'enable_threaded_comments');
14. создаем шорткод adsense.
function showads() {
return '<div id="adsense"><script type="text/javascript"><!–
google_ad_client = "pub-XXXXXXXXXXXXXX";
google_ad_slot = "4668915978";
google_ad_width = 468;
google_ad_height = 60;
//–>
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>';
}
add_shortcode('adsense', 'showads');
15. редирект на feedburner без помощи плагинов и .htaccess
function custom_feed_link($output, $feed) {
$feed_url = 'http://feeds.feedburner.com/wpbeginner';
$feed_array = array('rss' => $feed_url, 'rss2' => $feed_url, 'atom' => $feed_url, 'rdf' => $feed_url, 'comments_rss2' => '');
$feed_array[$feed] = $feed_url;
$output = $feed_array[$feed];
return $output;
}
function other_feed_links($link) {
$link = 'http://feeds.feedburner.com/wpbeginner';
return $link;
}
//Add our functions to the specific filters
add_filter('feed_link','custom_feed_link', 1, 2);
add_filter('category_feed_link', 'other_feed_links');
add_filter('author_feed_link', 'other_feed_links');
add_filter('tag_feed_link','other_feed_links');
add_filter('search_feed_link','other_feed_links');
16. отложенное обновление rss ленты.
// delay feed update
function publish_later_on_feed($where) {
global $wpdb;
if (is_feed()) {
// timestamp in WP-format
$now = gmdate('Y-m-d H:i:s');
// value for wait; + device
$wait = '5'; // здесь пишем сколько нужно времени
// http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
$device = 'MINUTE'; // указываем единицу измерения MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
// add SQL-sytax to default $where
$where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
}
return $where;
}
add_filter('posts_where', 'publish_later_on_feed');
17. кастомизируем окончание выдержки.
// custom excerpt ellipses for 2.9
function custom_excerpt_more($more) {
return '…';
}
add_filter('excerpt_more', 'custom_excerpt_more');
/* custom excerpt ellipses for 2.8-
function custom_excerpt_more($excerpt) {
return str_replace('[...]', '…', $excerpt);
}
add_filter('wp_trim_excerpt', 'custom_excerpt_more');
*/
18. кастомизируем длину выдержки
function new_excerpt_length($length) {
return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');
19. отключить рсс фид вообще
function fb_disable_feed() {
wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') );
}
add_action('do_feed', 'fb_disable_feed', 1);
add_action('do_feed_rdf', 'fb_disable_feed', 1);
add_action('do_feed_rss', 'fb_disable_feed', 1);
add_action('do_feed_rss2', 'fb_disable_feed', 1);
add_action('do_feed_atom', 'fb_disable_feed', 1);
20. удаляем ненужные ссылки с wp_head.
// remove junk from head
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);
21. подключаем библиотеку jquery с гугла, а не с нашего сервера
// smart jquery inclusion
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false);
wp_enqueue_script('jquery');
}
22. проверяем нагрузку сайта
function sys_stat() {
printf(('System statistic : %d queries / %s seconds'), get_num_queries(), timer_stop(0, 3));
if ( function_exists('memory_get_usage') ) echo ' / ' . round(memory_get_usage()/1024/1024, 2) . ' mb';
}
<?php sys_stat(); ?>
Спасибо за уйму полезной информации. Как раз пришло время довести тему до ума и эти рекомендации будут весьма кстати.
function remove_menu() {
global $menu;
//remove post top level menu
unset($menu[0]);
unset($menu[75]);
}
add_action('admin_head', 'remove_menu');
print '#footer { display:none; } .form-table fieldset { display:none; }’;
}
add_action (‘admin_head’, ‘sk_admin_css’);
global $screen;
unset($screen[0]);
$text = ‘По всем вопросам обращаться к разработчику сайта’;
return $text;
add_action( ‘contextual_help’, ‘my_admin_help’ );
?>
У меня просто трудность добавления виджета на страницу посредством вставки пхп кода, так как виджет зона в виде многоуровневого слайдера. Отсюда вопрос, как создать, добавить простой виджет без плагина, что бы вывести пхп код «» в слайдер виджет.