Skip to content

Instantly share code, notes, and snippets.

@stkdr
stkdr / WordPress Conditional Custom Meta Box
Created Jan 9, 2021 — forked from WagnerMatos/WordPress Conditional Custom Meta Box
WordPress Custom Meta Box that can used only on certain post types, pages, etc.
View WordPress Conditional Custom Meta Box
<?php
/*/////////////////////////////////////////////////////////////////////////////////////
//// Load scripts and styles for Meta box */
// enqueue scripts and styles, but only if is_admin
if(is_admin()) {
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_script('jquery-ui-slider');
wp_enqueue_script('custom-js', get_template_directory_uri().'/library/metaboxes/js/custom-js.js');
wp_enqueue_style('jquery-ui-custom', get_template_directory_uri().'/library/metaboxes/css/jquery-ui-custom.css');
@stkdr
stkdr / gulpfile.js
Created Oct 4, 2020 — forked from braginteractive/gulpfile.js
Gulp 4 and WordPress Development
View gulpfile.js
// Load all the modules from package.json
var gulp = require( 'gulp' ),
plumber = require( 'gulp-plumber' ),
autoprefixer = require('gulp-autoprefixer'),
watch = require( 'gulp-watch' ),
jshint = require( 'gulp-jshint' ),
stylish = require( 'jshint-stylish' ),
uglify = require( 'gulp-uglify' ),
rename = require( 'gulp-rename' ),
notify = require( 'gulp-notify' ),
View zip-excluding-specific-directories-and-files.md

Zip excluding specific directories

Exclude .git file and node_modules directory

$ zip -r9 [target_file] [source_file] -x *.git* node_modules/\*

Exclude .git file and files in node_modules directory, but keep node_modules directory

$ zip -r9 [target_file] [source_file] -x *.git* node_modules/**\*
View translation.php
<?php
/**
* Escape all translations with
*/
__( ‘Some String’, ‘text-domain’ ); _e( ‘Some string’, ‘text-domain’ );.
/**
* When there is no HTML use:
*/
@stkdr
stkdr / WP Customizer - Select
Created Feb 2, 2019 — forked from ajskelton/WP Customizer - Select
Add a Select field to the WordPress Customizer.
View WP Customizer - Select
$wp_customize->add_setting( 'themeslug_select_setting_id', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => 'themeslug_sanitize_select',
'default' => 'value1',
) );
$wp_customize->add_control( 'themeslug_select_setting_id', array(
'type' => 'select',
'section' => 'custom_section', // Add a default or your own section
'label' => __( 'Custom Select Option' ),
@stkdr
stkdr / wp-updates-theme.php
Created Aug 9, 2018 — forked from gilbitron/wp-updates-theme.php
WPUpdates Theme Updater Class (with Envato API verification)
View wp-updates-theme.php
<?php
/*
WPUpdates Theme Updater Class (with Envato API verification)
http://wp-updates.com
v1.1
Example Usage:
require_once('wp-updates-theme.php');
new WPUpdatesThemeUpdater( 'http://wp-updates.com/api/1/theme', 1, basename(get_template_directory()) );
*/
@stkdr
stkdr / wp-get-image-alt-text.php
Created Jul 4, 2018 — forked from patrickgilmour/wp-get-image-alt-text.php
WordPress Images - echo the Alt text of the Featured image (and other image attributes)
View wp-get-image-alt-text.php
<?php
/**
* Get the Alt text of a Featured Image
*
* And other image attributes
*/
add_action('genesis_before_sidebar_widget_area', 'pgwp_genesis_before_sidebar_widget_area' );
function pgwp_genesis_before_sidebar_widget_area () {
@stkdr
stkdr / custom_excerpt_wp.php
Created Jun 11, 2018 — forked from sammdec/custom_excerpt_wp.php
Wordpress Custom Excerpt function
View custom_excerpt_wp.php
<?php
function get_excerpt($count, $post_id){
$permalink = get_permalink($post_id);
$excerpt = get_post($post_id);
$excerpt = $excerpt->post_content;
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $count);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = $excerpt;
// Want a read more link and ellipsis, remove the line above this and replace it with the one below.
@stkdr
stkdr / functions.php
Created Jun 11, 2018 — forked from jaredatch/functions.php
WordPress Search Autocomplete using admin-ajax.php
View functions.php
<?php
/**
* Enqueue scripts and styles.
*
* @since 1.0.0
*/
function ja_global_enqueues() {
wp_enqueue_style(
'jquery-auto-complete',
@stkdr
stkdr / functions.php
Created Jun 11, 2018 — forked from jaredatch/functions.php
WordPress Search Autocomplete using WP REST API v2
View functions.php
<?php
/**
* Enqueue scripts and styles.
*
* @since 1.0.0
*/
function ja_global_enqueues() {
wp_enqueue_style(
'jquery-auto-complete',