if ( is_front_page() && is_home() ){
// Default homepage
} elseif ( is_front_page()){
//Static homepage
} elseif ( is_home()){
//Blog page
} else {
//everything else
}
Logging Variables https://querymonitor.com/docs/logging-variables/
qm/emergency qm/alert qm/critical qm/error qm/warning qm/notice qm/info qm/debug
do_action( 'qm/warning', 'Warning );
do_action( 'qm/info', 'Title' );
do_action( 'qm/debug', $variable );
if ( is_wp_error( $response ) ) {
do_action( 'qm/error', $response );
}
try {
// your code
} catch ( Exception $e ) {
do_action( 'qm/error', $e );
}
// Start the 'foo' timer:
do_action( 'qm/start', 'foo' );
// Run some code
my_potentially_slow_function();
// Stop the 'foo' timer:
do_action( 'qm/stop', 'foo' );
<?php include(TEMPLATEPATH.'/pagenavi.php'); ?>
<?php include_once('advanced-custom-fields/acf.php'); ?>
echo json_encode(array('loggedin' => true, 'message' => $phone, 'user_id' => $user_signon->ID));
add_action('init', 'gutschlafen_enqueue_theme_scripts_170921');
function gutschlafen_enqueue_theme_scripts_170921()
{
//core
wp_enqueue_script( 'jquery' );
// Better to use local jquery
//wp_register_script('jquery', '//cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js', array(), '3.4.1');
//wp_enqueue_script('jquery');
// wp_deregister_script('jquery');
// wp_deregister_script('jquery-migrate');
//wp_deregister_script('modernizr');
wp_deregister_script('jquery-form');
wp_enqueue_script('select2', THEME_URL . '/assets/js/libs/select2.min.js', array('jquery'), '1.0.0', true);
wp_enqueue_script('fancybox', THEME_URL . '/assets/js/libs/fancybox.umd.min.js', array('jquery'), '1.0.0', true);
wp_enqueue_script('swiper', THEME_URL . '/assets/js/libs/swiper-bundle.min.js', array('jquery'), '1.0.0', true);
wp_enqueue_script('wishlist', THEME_URL . '/assets/js/wishlist.js', array('jquery'), filemtime( get_stylesheet_directory() . '/assets/js/wishlist.js'), true);
// Theme main scripts file
wp_enqueue_script('wpeScripts', THEME_URL . '/assets/js/main.js', array('jquery', 'select2', 'fancybox', 'swiper', 'wishlist'), filemtime( get_stylesheet_directory() . '/assets/js/main.js'), true);
wp_localize_script('wpeScripts', 'adminAjax', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'templatePath' => THEME_URL,
'posts_per_page' => get_option('posts_per_page')
));
}
debug($data);
function debug($data){
echo '<pre>'. print_r($data, 1) .'</pre>';
}
// http://saitobaza.ru/specialnyj-shablon-zapisej-dlya-opredelennyx-kategorij-wordpress.htm
add_filter('single_template', 'check_for_category_single_template');
function check_for_category_single_template( $t )
{
foreach( (array) get_the_category() as $cat )
{
if ( file_exists(TEMPLATEPATH . "/single-category-{$cat->slug}.php") ) return TEMPLATEPATH . "/single-category-{$cat->slug}.php";
if($cat->parent)
{
$cat = get_the_category_by_ID( $cat->parent );
if ( file_exists(TEMPLATEPATH . "/single-category-{$cat->slug}.php") ) return TEMPLATEPATH . "/single-category-{$cat->slug}.php";
}
}
return $t;
}
function replace_text_wps($text){
$replace = array(
// 'WORD TO REPLACE' => 'REPLACE WORD WITH THIS'
'wordpress' => '<a href="#">wordpress</a>',
'excerpt' => '<a href="#">excerpt</a>',
'function' => '<a href="#">function</a>'
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}
add_filter('the_content', 'replace_text_wps');
add_filter('the_excerpt', 'replace_text_wps');
<?php
$attachment_id = get_field('dl-fb2');
$url = wp_get_attachment_url( $attachment_id );
$title = get_the_title( $attachment_id );
$myfile = filesize( get_attached_file( $attachment_id ) );
$bytes = size_format($myfile, 2);
if(get_field('dl-fb2')) { ?>
<tr>
<td><a href="<?php echo $url; ?>" title="<?php echo $title; ?>">Скачать в формате fb2</a></td>
<td>Размер файла: <?php echo $bytes; ?></td>
</tr>
<?php } ?>
$ids = get_posts(
array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_status' => 'inherit',
'posts_per_page' => -1,
'fields' => 'ids',
)
);
$media_libriary_images = array();
foreach ($ids as $id) {
$media_libriary_images[]= $id;
}
query_posts("showposts=20&post_type=product");
if (have_posts()) : while (have_posts()) : the_post();
shuffle($media_libriary_images);
$post_gallery_images = $media_libriary_images;
$random_number = random_int(0, 10);
$post_gallery_images = array_slice($post_gallery_images, $random_number);
$post_id = get_the_ID();
$gallery_array = get_field('gallery', $post_id, false);
echo '<pre>';
print_r($gallery_array);
echo '</pre>';
if (!is_array($gallery_array)) {
$gallery_array = array();
}
update_field('gallery', $gallery_array, $post_id);
update_post_meta($post_id, '_thumbnail_id', $post_gallery_images[0]);
endwhile;
endif;
wp_reset_query();
$terms_filter = get_terms(array(
'taxonomy' => array( 'dclass' ), // название таксономии с WP 4.5
'orderby' => 'id',
'order' => 'ASC',
'hide_empty' => false,
'object_ids' => null,
'include' => array(),
'exclude' => array(),
'exclude_tree' => array(),
'number' => '',
'fields' => 'all',
'count' => false,
'slug' => '',
'parent' => '',
'hierarchical' => true,
'child_of' => 0,
'get' => '', // ставим all чтобы получить все термины
'name__like' => '',
'pad_counts' => false,
'offset' => '',
'search' => '',
'cache_domain' => 'core',
'name' => '', // str/arr поле name для получения термина по нему. C 4.2.
'childless' => false, // true не получит (пропустит) термины у которых есть дочерние термины. C 4.2.
'update_term_meta_cache' => true, // подгружать метаданные в кэш
'meta_query' => '',
));
foreach ($terms_filter as $term) {
echo $term->name; wp_set_object_terms( 410, $term->name, 'product_drug_class' );
}
/*
* Обрабатываем AJAX-запрос типа ncAction
*/
add_action( 'wp_ajax_ncAction', 'ncAction_callback' );
add_action( 'wp_ajax_nopriv_ncAction', 'ncAction_callback' );
function ncAction_callback() {
$args = wp_parse_args( $_POST, array(
'test' => false,
) );
$result = array(
'test' => $args['test'],
);
if ( $result['test'] ) {
wp_send_json_success( $result );
} else {
wp_send_json_error( $result );
}
}
/*
* Отправляем AJAX-запрос типа ncAction
*/
$.ajax({
type: 'POST',
url: ncVar.ajaxurl,
data: {
'test': 'Hello, world!',
'action': 'ncAction',
},
dataType: 'json',
success: function(result) {
console.log('success: ' + result.success);
console.log(result.data);
}
});
<?php
add_action('wp_ajax_get_new', 'get_new');
add_action('wp_ajax_nopriv_get_new', 'get_new'); // not really needed
function get_new() {
// args
$args = array(
'post_type' => 'product',
'showposts' => 100,
'meta_query' => array(
array(
'key' => 'new',
'value' => '1',
'compare' => '=='
)
)
);
// query
$the_query = new WP_Query( $args );
if( $the_query->have_posts() ):
while( $the_query->have_posts() ) : $the_query->the_post();
if ( has_post_thumbnail()) {
$post_thumbnail_id = get_post_thumbnail_id( $post );
$image = '<img src="'. wp_get_attachment_image_url( $post_thumbnail_id, "medium" ) .'" title="'. get_the_title() .'" alt="'. get_the_title() .'" />';
} else {
$image = '<img src="'. catchFirstImage() .'" title="'. the_title() .'" alt="'. the_title() .'" />';
}
if( get_field('sale') ) {
$action = '<span class="action upper fira-bold">НА АКЦИИ</span>';
} else {
$action = '';
}
$output = $output .'<div id="post-'. get_the_ID() .'" class="col-xs-6 col-md-4 nopadding card-product__img card-product__img--cat">
<a href="'. get_the_permalink() .'">'. $image .'
'. $action .'
<span class="num upper fira-bold">'. get_the_title() .'</span>
<i class="ic ic-loop"></i>
</a>
<a href="#" class="like" like-id="'. get_the_ID() .'"><i class="ic ic-like"></i></a>
</div><!-- end card-product__img -->';
endwhile;
endif;
// Reset Query
wp_reset_query();
die($output);
}
$(document).ready(function() {
$(".sidebar-links--new").click(function(e) {
e.preventDefault();
var category = '<?php echo strtolower($category); ?>';
// var id = '<?php echo $blogger_id; ?>';
// var firstname = '<?php echo $firstname; ?>';
// var surname = '<?php echo $surname; ?>';
// alert(posts + category + id + firstname + surname);
$.ajax({
type: "GET",
url: "http://curtains.dev/wp-admin/admin-ajax.php",
dataType: 'html',
data: ({
action: 'get_new',
id: 46
// firstname: firstname,
// surname: surname,
// posts: posts,
// category: category
}),
success: function(data) {
$('.card-product__img--cat').hide('fast');
$('.card-products-cat-wrap').hide().fadeIn('slow').html(data);
$('.card-products-cat-wrap').append('<div className="clearfix"></div>');
}
});
});
});
$default_args = array('status' => null, 'customer_id' => null, 'customer_note' => null, 'parent' => null, 'created_via' => null, 'cart_hash' => null, 'order_id' => 0);
$args = wp_parse_args($args, $default_args);
$order = new WC_Order($args['order_id']);
if (!$customer_id) {
return new WP_Error('simplify_error', __('Customer not found', 'woocommerce'));
}
// Even more smart jQuery inclusion :)
add_action( 'init', 'jquery_register' );
// Register from Google and for footer
function jquery_register() {
if ( !is_admin() ) {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', ( '//cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js' ), false, '3.6.0', true );
wp_enqueue_script( 'jquery' );
}
}
if ( !function_exists('add_thumb_column') && function_exists('add_theme_support') ) {
// for post and page
add_theme_support('post-thumbnails', array( 'post', 'page' ) );
function add_thumb_column($cols) {
$cols['thumbnail'] = __('Thumbnail');
return $cols;
}
function add_thumb_value($column_name, $post_id) {
$width = (int) 35;
$height = (int) 35;
if ( 'thumbnail' == $column_name ) {
// thumbnail of WP 2.9
$thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
// image from gallery
$attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
if ($thumbnail_id)
$thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
elseif ($attachments) {
foreach ( $attachments as $attachment_id => $attachment ) {
$thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
}
}
if ( isset($thumb) && $thumb ) {
echo $thumb;
} else {
echo __('None');
}
}
}
// for posts
add_filter( 'manage_posts_columns', 'add_thumb_value' );
add_action( 'manage_posts_custom_column', 'add_thumb_value', 10, 2 );
// for pages
add_filter( 'manage_pages_columns', 'add_thumb_value' );
add_action( 'manage_pages_custom_column', 'add_thumb_value', 10, 2 );
}
// Remove pings to self
function no_self_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) )
unset($links[$l]);
}
add_action( 'pre_ping', 'no_self_ping' );
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
function my_custom_dashboard_widgets() {
global $wp_meta_boxes;
// Right Now - Comments, Posts, Pages at a glance
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
// Recent Comments
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
// Incoming Links
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
// Plugins - Popular, New and Recently updated Wordpress Plugins
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
// WordPress Development Blog Feed
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
// Other WordPress News Feed
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
// Quick Press Form
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
// Recent Drafts List
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
}
add_action( 'init', 'remove_header_info' );
function remove_header_info() {
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'start_post_rel_link' );
remove_action( 'wp_head', 'index_rel_link' );
remove_action( 'wp_head', 'adjacent_posts_rel_link' ); // for WordPress < 3.0
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' ); // for WordPress >= 3.0
}
function set_custom_generated_favicons() {
echo '<link rel="apple-touch-icon" sizes="180x180" href="' . BNM_THEME_DIRECTORY . '/img/favicon/apple-touch-icon.png">';
echo '<link rel="icon" type="image/png" sizes="32x32" href="' . BNM_THEME_DIRECTORY . '/img/favicon/favicon-32x32.png">';
echo '<link rel="icon" type="image/png" sizes="16x16" href="' . BNM_THEME_DIRECTORY . '/img/favicon/favicon-16x16.png">';
echo '<link rel="manifest" href="' . BNM_THEME_DIRECTORY . '/img/favicon/site.webmanifest">';
echo '<link rel="mask-icon" href="' . BNM_THEME_DIRECTORY . '/img/favicon/safari-pinned-tab.svg" color="#5bbad5">';
echo '<meta name="apple-mobile-web-app-title" content="Brands & Madrid">';
echo '<meta name="application-name" content="Brands & Madrid">';
echo '<meta name="msapplication-TileColor" content="#da532c">';
echo '<meta name="theme-color" content="#ffffff">';
}
add_filter( 'wp_head' , 'set_custom_generated_favicons' );
// remove default favicon ability
//function remove_sections_favicon($wp_customize) {
// $wp_customize->remove_control('site_icon');
//}
//add_action( 'customize_register', 'remove_sections_favicon', 20, 1 );
// add preconect and prefetch to head
function add_preconect_prefetch(){
echo '<link rel="dns-prefetch" href="http://cloudflare.com">';
echo '<link rel="preconnect" href="https://cdnjs.cloudflare.com">';
}
add_filter( 'wp_head' , 'add_preconect_prefetch' );
function add_style_attr_rel_preload($html, $handle, $href, $media) {
if (is_admin()) {
return $html;
}
$html = '<link rel="preload" as="style" onload="this.onload=null;this.rel=\'stylesheet\'" id=' . $handle . ' href="' . $href . '" type="text/css" media="all" />';
return $html;
}
add_filter( 'style_loader_tag', 'add_style_attr_rel_preload', 10, 4 );
if ( ! defined( '_WPE_THEME_URI' ) ) {
define( '_WPE_THEME_URI', get_template_directory_uri() );
}
if ( ! defined( '_S_VERSION' ) ) {
// Replace the version number of the theme on each release.
define( '_S_VERSION', '1.2.0' );
}
function wpe_enque_scripts() {
wp_enqueue_style( 'bnm-style', _WPE_THEME_URI . '/css/main.css', array(), _S_VERSION );
wp_dequeue_script( 'jquery' );
wp_dequeue_script( 'jquery-core' );
wp_deregister_script( 'jquery' );
wp_enqueue_script( 'jquery', '//cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js', array(), '3.6.0', true );
wp_register_script( 'wpe-main', _WPE_THEME_URI . '/js/main.js', array('jquery'), _S_VERSION, $in_footer = true );
$public_settings = array(
'custom_variable' => 'custom_variable_value',
'ajax' => array(
'url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('wpe-nonce')
)
);
wp_localize_script( 'wpe-main', 'wpeSettings', $public_settings );
wp_enqueue_script( 'wpe-main' );
}
add_action( 'wp_enqueue_scripts', 'wpe_enque_scripts' );
function deregister_useless_styles() {
wp_dequeue_style('full-screen-search');
wp_dequeue_style('prettyPhoto');
wp_deregister_style('full-screen-search');
wp_deregister_style('prettyPhoto');
}
add_action( 'wp_print_styles', 'deregister_useless_styles', 100 );
function add_async_attribute($tag, $handle) {
// add script handles to the array below
$scripts_to_async = array('my-js-handle', 'another-handle');
foreach($scripts_to_async as $async_script) {
if ($async_script === $handle) {
return str_replace(' src', ' async="async" src', $tag);
// return str_replace(' src', ' defer="defer" src', $tag);
}
}
return $tag;
}
add_filter('script_loader_tag', 'add_async_attribute', 10, 2);
// defer script loading
function load_script_after_page_loaded($tag, $handle, $src) {
// add script handles to the array below
$scripts_to_defer = array(
'bnm-compiled',
'bnm-main',
);
foreach($scripts_to_defer as $defer_script) {
if ($defer_script === $handle) {
return $tag = '<script>if(document.addEventListener){console.log("'.$handle.'"); window.addEventListener("DOMContentLoaded", function() {var s = document.createElement("script");s.src = "' . $src . '";document.body.appendChild(s);});}</script>';
}
}
return $tag;
}
add_filter('script_loader_tag', 'load_script_after_page_loaded', 10, 3);