Skip to content

Instantly share code, notes, and snippets.

@brynzovskii
brynzovskii / woo-events.js
Created March 29, 2022 06:05 — forked from bagerathan/woo-events.js
[Woocommerce Javascript events] #woo
//Woocommerce Checkout JS events
$( document.body ).trigger( 'init_checkout' );
$( document.body ).trigger( 'payment_method_selected' );
$( document.body ).trigger( 'update_checkout' );
$( document.body ).trigger( 'updated_checkout' );
$( document.body ).trigger( 'checkout_error' );
//Woocommerce cart page JS events
$( document.body ).trigger( 'wc_cart_emptied' );
$( document.body ).trigger( 'update_checkout' );
@brynzovskii
brynzovskii / wp-new-page-template.php
Created March 19, 2020 20:11
Wp new page template starter
<?php
/**
*
* Template Name: New Template
*
*/
get_header();
while ( have_posts() ) : the_post(); ?>
@brynzovskii
brynzovskii / redirect-wp-post.php
Created January 30, 2020 22:08 — forked from Bobz-zg/redirect-wp-post.php
Redirects wordpress posts to new url: site.com/blog/post-name
<?php
/**
* Add new rewrite rule
*/
function create_new_url_querystring() {
add_rewrite_rule(
'blog/([^/]*)$',
'index.php?name=$matches[1]',
'top'
);
@brynzovskii
brynzovskii / gist:0a44d203c586516bc7f02ed6b4c853f0
Created March 14, 2019 17:44 — forked from pitch-gist/gist:2999707
HTML: Simple Maintenance Page
<!doctype html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
@brynzovskii
brynzovskii / anchor.js
Last active January 10, 2019 21:31
Scroll to anchor with offset when coming from another page
jQuery(function($) {
$('a[href*="#"]:not([href="#"])').click(function() {
var target = $(this.hash);
$('html,body').stop().animate({
scrollTop: target.offset().top - 100
}, 'linear');
});
if (location.hash){
var id = $(location.hash);
}
@brynzovskii
brynzovskii / flexbox.scss
Created July 8, 2018 21:10 — forked from richardtorres314/flexbox.scss
CSS Flexbox - Sass Mixins
// --------------------------------------------------
// Flexbox SASS mixins
// The spec: http://www.w3.org/TR/css3-flexbox
// --------------------------------------------------
// Flexbox display
@mixin flexbox() {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
<?php
$tags = get_tags();
if ($tags) {
foreach ($tags as $tag) {
echo '<p>Tag: <a href="' . get_tag_link( $tag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a> </p> ';
}
}
?>
<?php
$tags = wp_get_post_tags($post->ID);
@brynzovskii
brynzovskii / get-ip-address-optimized.php
Created May 1, 2018 13:28 — forked from cballou/get-ip-address-optimized.php
PHP - Advanced Method to Retrieve Client IP Address
<?php
function get_ip_address() {
$ip_keys = array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR');
foreach ($ip_keys as $key) {
if (array_key_exists($key, $_SERVER) === true) {
foreach (explode(',', $_SERVER[$key]) as $ip) {
// trim for safety measures
$ip = trim($ip);
// attempt to validate IP
if (validate_ip($ip)) {
@brynzovskii
brynzovskii / before-post-inserting-hook.php
Created March 15, 2018 13:17
WP before post inserting hook
<?php
add_action( 'wp_insert_post', 'wpse128767_add_meta' );
function wpse128767_add_meta( $post_id ) {
// do something here, add post meta for example
add_post_meta( $post_id, 'key', 'value' );
}
@brynzovskii
brynzovskii / remove_post_type_slug_from_url.php
Last active March 15, 2018 13:18
Remove the slug from published post permalinks - Wordpress
<?php
/**
* Remove the slug from published post permalinks. Only affect our custom post type, though.
*/
function prefix_remove_cpt_slug( $post_link, $post, $leavename ) {
$custom_post_types = array( 'custom_post_type', 'custom_post_type_2', 'custom_post_type_3' );
if ( ! in_array( $post->post_type, $custom_post_types ) || 'publish' != $post->post_status ) {
return $post_link;