Skip to content

Instantly share code, notes, and snippets.

@nameDark
nameDark / Youtube lazy
Created December 18, 2019 11:07
Youtube lazy
// functions.php
add_filter( 'embed_oembed_html', function ($html, $url, $attr, $post_ID) {
$youtube_pattern = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#';
if ( preg_match( $youtube_pattern, $url ) ) {
$html = str_replace( 'src="', 'class="lazy-youtube" src="" data-src="', $html);
}
return $html;
}, 11, 4);
//js
@nameDark
nameDark / functions.php
Created July 12, 2019 11:30
Gutenberg Reusable Blocks
<?php
final class WP_Gutenberg_Reusable_Blocks_Widgets {
private static $instance;
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Gutenberg_Reusable_Blocks_Widgets ) ) {
self::$instance = new WP_Gutenberg_Reusable_Blocks_Widgets;
self::$instance->initing();
@nameDark
nameDark / map.php
Last active February 7, 2019 13:27
Gmap. Adding few markers (with InfoWindow)
<div id="map" style="height: 500px;"></div>
<script>
function initMap() {
var locations = [
['InfoWindow Content', -33.890542, 151.274856,],
['InfoWindow Content', -33.923036, 151.259052,],
['InfoWindow Content', -34.028249, 151.157507,],
['InfoWindow Content', -33.800101, 151.287478,],
['InfoWindow Content', -33.950198, 151.259302,]
];
@nameDark
nameDark / functions.php
Created December 19, 2018 14:00
Remove emoji
add_action( 'init', 'dark_remove_emoji' );
function dark_remove_emoji() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
@nameDark
nameDark / functions.php
Last active July 12, 2019 11:32
SEO. Remove attr text/javascript, text/css, hentry class
add_filter('style_loader_tag', 'dark_theme_remove_type_attr', 10, 2);
add_filter('script_loader_tag', 'dark_theme_remove_type_attr', 10, 2);
function dark_theme_remove_type_attr($tag, $handle) {
$tag = str_replace( 'type="text/javascript"', '', $tag);
$tag = str_replace( "type='text/javascript'", '', $tag);
$tag = str_replace( 'type="text/css"', '', $tag);
$tag = str_replace( "type='text/css'", '', $tag);
return $tag;
}
@nameDark
nameDark / class-breadcrumbs-dark.php
Last active January 16, 2020 12:55
Class for breadcrumbs
<?php
class Dark_Breadcrumbs {
/**
* A reference to an instance of this class.
*/
private static $instance = null;
/**
@nameDark
nameDark / functions.php
Created December 22, 2016 09:27
removing category form slug
add_filter('request', 'change_term_request', 1, 1 );
function change_term_request($query){
$tax_name = 'category';
if( $query['attachment'] ) :
$include_children = true;
$name = $query['attachment'];
else:
$include_children = false;
@nameDark
nameDark / .htaccess
Created September 13, 2016 20:29
Wordpress. htaccess
#close listing for files and folders
#Options +FollowSymLinks -Indexes
RewriteEngine On
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
@nameDark
nameDark / function.php
Last active September 13, 2016 10:41
get current URL
<?php
// get current URL
function get_current_URL() {
$current_url = 'http';
$server_https = $_SERVER["HTTPS"];
$server_name = $_SERVER["SERVER_NAME"];
$server_port = $_SERVER["SERVER_PORT"];
$request_uri = $_SERVER["REQUEST_URI"];
if ($server_https == "on") $current_url .= "s";
$current_url .= "://";
@nameDark
nameDark / header.php
Last active September 13, 2016 10:30
og example
//og example
<?php if (is_singular( )) { ?>
<meta property="fb:app_id" content="<?php if( $mytheme['fb_app_id']!='') {
echo "background-color:" . $mytheme['fb_app_id']; } ?>" />
<meta property="og:type" content="website" />
<meta property="og:locale" content="ru_RU" />
<meta property="og:title" content="<?php the_title( ); ?>" />
<meta property="og:description" content="<?php echo get_the_excerpt(); ?>" />
<meta property="og:url" content="<?php echo get_current_URL(); ?>"/>
<meta property="og:site_name" content="<?php bloginfo('name'); ?>"/>