Skip to content

Instantly share code, notes, and snippets.

@Treast
Created November 26, 2021 08:40
Show Gist options
  • Save Treast/f58a41c3bb2ee987a126128cb461a2ce to your computer and use it in GitHub Desktop.
Save Treast/f58a41c3bb2ee987a126128cb461a2ce to your computer and use it in GitHub Desktop.
WordPress snippets
$fontPath: '../../fonts';
@mixin fonts($name, $file, $fontWeight) {
@font-face {
font-family: $name;
src: url('#{$fontPath}/#{to-lower-case(#{$name})}/#{$file}.eot');
src: url('#{$fontPath}/#{to-lower-case(#{$name})}/#{$file}.eot?#iefix') format('embedded-opentype'),
url('#{$fontPath}/#{to-lower-case(#{$name})}/#{$file}.woff2') format('woff2'),
url('#{$fontPath}/#{to-lower-case(#{$name})}/#{$file}.woff') format('woff'),
url('#{$fontPath}/#{to-lower-case(#{$name})}/#{$file}.ttf') format('truetype'),
url('#{$fontPath}/#{to-lower-case(#{$name})}/#{$file}.svg') format('svg');
font-weight: $fontWeight;
font-style: normal;
font-display: swap;
}
}
@include fonts($fontText, 'roboto-regular-webfont', 400);
/**
* Grid
*/
$gridGap: 80px;
$containerPadding: 20px;
$maxWidthContainer: 1100px;
.grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: $gridGap;
row-gap: $gridGap;
@include max-desktop {
grid-template-columns: 1fr;
}
}
:root {
--container-padding: #{$containerPadding};
--container-width: calc(100% - var(--container-padding) * 2);
}
.container {
@extend .grid;
width: 100%;
padding-left: calc(50% - var(--container-width) / 2);
padding-right: calc(50% - var(--container-width) / 2);
}
@media only screen and (min-width: (#{$maxWidthContainer + 2 * $containerPadding })) {
:root {
--container-width: #{$maxWidthContainer};
}
}
/**
* Responsive
*/
$tablet-width: 768px;
$desktop-width: 1024px;
$large-width: 1600px;
@function rem($pixel) {
@return #{$pixel / $fontSize}rem;
}
@mixin phone {
@media (max-width: #{$tablet-width - 1px}) {
@content;
}
}
@mixin tablet {
@media (min-width: #{$tablet-width}) and (max-width: #{$desktop-width - 1px}) {
@content;
}
}
@mixin desktop {
@media (min-width: #{$desktop-width}) {
@content;
}
}
@mixin max-desktop {
@media (max-width: #{$desktop-width - 1}) {
@content;
}
}
*,
*::before,
*::after {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
box-sizing: border-box;
}
html,
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
a {
color: inherit;
text-decoration: none;
}
html,
body,
div,
span,
object,
iframe,
figure,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
code,
em,
img,
small,
strike,
strong,
sub,
sup,
tt,
b,
u,
i,
ol,
ul,
li,
fieldset,
form,
label,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
main,
canvas,
embed,
footer,
header,
nav,
section,
video {
margin: 0;
padding: 0;
border: 0;
font: inherit;
font-size: 100%;
vertical-align: baseline;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
text-size-adjust: none;
}
footer,
header,
nav,
section,
main {
display: block;
}
body {
line-height: 1;
}
ol,
ul {
list-style: none;
}
blockquote,
q {
quotes: none;
}
blockquote::before,
blockquote::after,
q::before,
q::after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
input {
-webkit-appearance: none;
border-radius: 0;
}
/**
* Disable Contact Form 7 on all pages
*/
add_filter('wpcf7_load_js', '__return_false');
add_filter('wpcf7_load_css', '__return_false');
/**
* Enable Contact Form 7 on specific page
*/
add_action('wp_enqueue_scripts', function () {
if (is_page('Contact')) {
if (function_exists('wpcf7_enqueue_scripts')) {
wpcf7_enqueue_scripts();
}
if (function_exists('wpcf7_enqueue_styles')) {
wpcf7_enqueue_styles();
}
}
}, 100);
/**
* Setup custom SMTP parameters
*/
add_action('phpmailer_init', function ($phpmailer) {
$phpmailer->Host = 'smtp.gmail.com';
$phpmailer->Port = 587;
$phpmailer->Username = 'yourname@gmail.com';
$phpmailer->Password = 'yourpassword';
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPSecure = 'tls';
$phpmailer->IsSMTP();
});
/**
* Remove jQuery on front
*/
add_action('init', function () {
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', false);
}
});
/**
* Remove WP Emoji
*/
add_action('init', function () {
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');
// Remove from TinyMCE
add_filter('tiny_mce_plugins', function ($plugins) {
if (is_array($plugins)) {
return array_diff($plugins, array('wpemoji'));
} else {
return array();
}
});
});
/**
* Remove Gutemberg styles
*/
add_action('wp_enqueue_scripts', function () {
wp_dequeue_style('wp-block-library');
wp_dequeue_style('wp-block-library-theme');
wp_dequeue_style('wc-block-style');
}, 100);
/**
* Remove Jetpack CSS
*/
add_filter('jetpack_implode_frontend_css', '__return_false');
add_action('wp_print_styles', function () {
wp_deregister_style('AtD_style'); // After the Deadline
wp_deregister_style('jetpack_likes'); // Likes
wp_deregister_style('jetpack_related-posts'); //Related Posts
wp_deregister_style('jetpack-carousel'); // Carousel
wp_deregister_style('grunion.css'); // Grunion contact form
wp_deregister_style('the-neverending-homepage'); // Infinite Scroll
wp_deregister_style('infinity-twentyten'); // Infinite Scroll - Twentyten Theme
wp_deregister_style('infinity-twentyeleven'); // Infinite Scroll - Twentyeleven Theme
wp_deregister_style('infinity-twentytwelve'); // Infinite Scroll - Twentytwelve Theme
wp_deregister_style('noticons'); // Notes
wp_deregister_style('post-by-email'); // Post by Email
wp_deregister_style('publicize'); // Publicize
wp_deregister_style('sharedaddy'); // Sharedaddy
wp_deregister_style('sharing'); // Sharedaddy Sharing
wp_deregister_style('stats_reports_css'); // Stats
wp_deregister_style('jetpack-widgets'); // Widgets
wp_deregister_style('jetpack-slideshow'); // Slideshows
wp_deregister_style('presentations'); // Presentation shortcode
wp_deregister_style('jetpack-subscriptions'); // Subscriptions
wp_deregister_style('tiled-gallery'); // Tiled Galleries
wp_deregister_style('widget-conditions'); // Widget Visibility
wp_deregister_style('jetpack_display_posts_widget'); // Display Posts Widget
wp_deregister_style('gravatar-profile-widget'); // Gravatar Widget
wp_deregister_style('widget-grid-and-list'); // Top Posts widget
wp_deregister_style('jetpack-widgets'); // Widgets
});
/**
* Remove type attributes on link & scripts
*/
add_filter('style_loader_tag', 'codeless_remove_type_attr', 10, 2);
add_filter('script_loader_tag', 'codeless_remove_type_attr', 10, 2);
add_filter('autoptimize_html_after_minify', 'codeless_remove_type_attr', 10, 2);
function codeless_remove_type_attr($tag, $handle)
{
return preg_replace("/type=['\"]text\/(javascript|css)['\"]/", '', $tag);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment