Установка WordPress Мультисайт
Рубрика: WordPress
Свой шорткод
|
1 2 3 4 5 6 |
<? add_action('my_action', 'action_function'); function action_function() { echo 'asdasd'; } ?> |
Выводим хук в код
|
1 |
<? do_action('my_action');?> |
|
1 2 3 4 5 6 |
<? add_shortcode('my_short', 'short_function'); function short_function() { return 'Вывели ширткод'; } ?> |
Выводим шорткод
|
1 |
[my_short] |
Как изменить дизайн страницы авторизации в WordPress
https://meliorem.ru/cms/wordpress/kak-izmenit-dizajn-stranicy-avtorizacii-v-wordpress/
Получить домены в режиме мультисайт
|
1 2 3 4 5 6 7 8 |
<? if ( function_exists( 'get_sites' ) & class_exists( 'WP_Site_Query' ) ): $sites = get_sites(); foreach ( $sites as $site ): $arr[] = $site->domain; endforeach; ?> <?endif;?> |
Contact form 7 защита от спама без капчи
1. Создаем в Contact Form 7 чекбокс
|
1 |
[acceptance agree class:agree default:on invert] |
2. Убираем чекбоксу видимость через CSS
|
1 |
.agree {display:none} |
3. Снимаем галочку через JS
|
1 2 3 |
<script language="javascript"> jQuery('.agree').prop('checked', false); </script> |
Добавить кнопку выбрать все в админке WP
|
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
## Фильтр элементо втаксономии для метабокса таксономий в админке. add_action( 'admin_print_scripts', 'my_admin_term_filter', 99 ); function my_admin_term_filter() { $screen = get_current_screen(); if( 'post' !== $screen->base ) return; // только для страницы редактирвоания любой записи ?> <script> jQuery(document).ready(function($){ var $categoryDivs = $('#taxonomy-areas'); var $categoryDivs2 = $('#taxonomy-themes'); $categoryDivs.prepend('<label><input type="checkbox" id="check_all" />Выбрать все<label >'); $categoryDivs2.prepend('<label><input type="checkbox" id="check_all_2" />Выбрать все<label >'); $("#check_all").click(function () { var t = $('#areaschecklist'); t.find('input[type=checkbox]').each(function() { this.checked = true; }); if($("#check_all").attr("checked") != 'checked') { $("#check_all").click(function () { t.find('input[type=checkbox]').each(function() { this.checked = true; }); }); }else{ $("#check_all").click(function () { t.find('input[type=checkbox]').each(function() { this.checked = false; }); }); }; }); /**/ $("#check_all_2").click(function () { var t = $('#themeschecklist'); t.find('input[type=checkbox]').each(function() { this.checked = true; }); if($("#check_all_2").attr("checked") != 'checked') { $("#check_all_2").click(function () { t.find('input[type=checkbox]').each(function() { this.checked = true; }); }); }else{ $("#check_all_2").click(function () { t.find('input[type=checkbox]').each(function() { this.checked = false; }); }); }; }); }); </script> <?php } |
добавляем код в файл functions.php
WP подключение файлов с CDN
|
1 2 3 4 5 6 7 |
//CSS wp_register_style( 'Font_Awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css' ); wp_enqueue_style('Font_Awesome'); //JS wp_register_script( 'jQuery', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js', null, null, true ); wp_enqueue_script('jQuery'); |
Рандомный бэкграунд
|
1 2 3 4 5 6 |
function wpb_bg() { $rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'); $color ='#'.$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)]. $rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)]; echo $color; } |
В теме можно подключить к тегу body
|
1 |
<body <?php body_class(); ?> style="background-color:<?php wpb_bg();?>">> |
Добавляем свои виджеты в консоль WP
|
1 2 3 4 5 6 7 8 |
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 '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>'; } |
Меняем подвал админки WP
|
1 2 3 4 |
function remove_footer_admin () { echo 'Fueled by <a href="http://www.wordpress.org" target="_blank">WordPress</a> | WordPress Tutorials: <a href="http://www.wpbeginner.com" target="_blank">WPBeginner</a>'; } add_filter('admin_footer_text', 'remove_footer_admin'); |
Свой логотип в админке Вордпресс
|
1 2 3 4 5 |
function wpb_custom_logo() { echo '<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cstyle%20type%3D%22text%2Fcss%22%3E%0A%23wpadminbar%20%23wp-admin-bar-wp-logo%20%3E%20.ab-item%20.ab-icon%3Abefore%20%7B%0Abackground-image%3A%20url('%20.%20get_bloginfo('stylesheet_directory')%20.%20'%2Fimages%2Fcustom-logo.png)%20!important%3B%0Abackground-position%3A%200%200%3B%0Acolor%3Argba(0%2C%200%2C%200%2C%200)%3B%0A%7D%0A%23wpadminbar%20%23wp-admin-bar-wp-logo.hover%20%3E%20.ab-item%20.ab-icon%20%7B%0Abackground-position%3A%200%200%3B%0A%7D%0A%3C%2Fstyle%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<style>" title="<style>" />'; } //hook into the administrative header output add_action('wp_before_admin_bar_render', 'wpb_custom_logo'); |
Удаляем версию WP
|
1 2 3 4 |
function wpb_remove_version() { return ''; } add_filter('the_generator', 'wpb_remove_version'); |