Skip to content

Instantly share code, notes, and snippets.

Vladimir Lukyanov vladimirlukyanov

Block or report user

Report or block vladimirlukyanov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View webpack hot reload disable nuxt.js
// Add this to nuxt.config.js
build: {
publicPath: '/zenith/',
analyze: false,
hotMiddleware : {
reload:false
},
// watch: ['api', 'modules'],
extend(config, {isDev, isClient}) {
View programatically_add_route_nuxt.js
const { resolve } = require('path');
module.exports = function() {
this.extendRoutes(routes => {
routes.push({
name: 'admin',
path: '/admin',
component: resolve('./pages/index.vue')
})
@vladimirlukyanov
vladimirlukyanov / 404-redirect.js
Last active Apr 23, 2018
Nuxt.js 404 error handling | Nuxt.js 404 redirect | Nuxt.js middleware routing
View 404-redirect.js
// Add this file to /middleware
export default function ({params, route, redirect}) {
if(route.matched.length === 0) { // route is not found, redirect to homepage
redirect('302', '/');
}
}
View Get list of taxonomies for CPT.php
<?php
$args = array(
'object_type' => array( 'hotels' )
);
$output = 'names'; // or objects
$operator = 'and'; // 'and' or 'or'
$taxonomies = get_taxonomies( $args, $output, $operator );
if ( $taxonomies ) {
foreach ( $taxonomies as $taxonomy ) {
@vladimirlukyanov
vladimirlukyanov / hide_menus_for_non_admin_users_wordpress.php
Created Nov 16, 2016
Hide menu items for non-admin users WordPress
View hide_menus_for_non_admin_users_wordpress.php
<?php
// remove unnecessary menus
function remove_admin_menus () {
global $menu;
// all users
$restrict = explode(',', 'Links,Comments');
// non-administrator users
@vladimirlukyanov
vladimirlukyanov / search_by_sku.php
Created Nov 1, 2016
WordPress WooCommerce search by SKU
View search_by_sku.php
<?php
/**
* Add sku, author, publisher and format to product search
*/
// hook into wp pre_get_posts
add_action('pre_get_posts', 'woo_search_pre_get_posts');
/**
* Add custom join and where statements to product search query
View shortcode_method_4.php
<?php
function custom_shortcode_scripts() {
global $post;
if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'myshortcode') ) {
wp_enqueue_script( 'my-script');
}
}
add_action( 'wp_enqueue_scripts', 'custom_shortcode_scripts');
View shortcode_method_3.php
<?php
function your_prefix_detect_shortcode() {
global $wp_query;
$posts = $wp_query->posts;
$pattern = get_shortcode_regex();
foreach ($posts as $post){
if ( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches )
&& array_key_exists( 2, $matches )
View shortcode_method_2.php
<?php
class My_Shortcode {
static $add_script;
static function init() {
add_shortcode('myshortcode', array(__CLASS__, 'handle_shortcode'));
add_action('init', array(__CLASS__, 'register_script'));
add_action('wp_footer', array(__CLASS__, 'print_script'));
}
static function handle_shortcode($atts) {
View shortcode_method_1.php
<?php
class My_Shortcode {
function handle_shortcode( $atts, $content="" ) {
/* simply enqueue or print the scripts/styles in the shortcode itself */
?>
<style type="text/css">
</style>
<?php
You can’t perform that action at this time.