Skip to content

Instantly share code, notes, and snippets.

@maxyudin
maxyudin / [WordPress] Recursive wp_parse_args
Last active April 19, 2017 16:03 — forked from boonebgorges/gist:5510970
A recursive sorta-version of wp_parse_args()
<?php
/**
* Recursive argument parsing
*
* This acts like a multi-dimensional version of wp_parse_args() (minus
* the querystring parsing - you must pass arrays).
*
* Values from $a override those from $b; keys in $b that don't exist
* in $a are passed through.
<?php
/**
* Plugin Name: WooCommerce Plugin Templates
* Plugin URI: http://jeroensormani.com
* Description: A simple demo plugin on how to use template files within your plugin.
*/
/**
* Locate template.
/*
From http://jakeparis.com/2015/05/debugging-wordpress-rewrite-rules/
*/
function jp_debug_rewrite_rules($where = 'head') {
// only do this on public side
if( is_admin() ) return false;
switch($where) {
case 'foot' :
<?php
// Edition 1
$taxonomy_name = 'sample-cpt-category';
if ( is_tax( $taxonomy_name ) ) {
$current_taxonomy_term = get_queried_object_id();
$args = array(
<?php
/*
From:
http://www.rarescosma.com/2010/11/add-a-class-to-wp_nav_menu-items-with-urls-included-in-the-current-url/
*/
add_filter( 'nav_menu_css_class', 'add_parent_url_menu_class', 10, 2 );
function add_parent_url_menu_class( $classes = array(), $item = false ) {
// Get current URL
.element {
text-indent: -9999px;
line-height: 0; /* Collapse the original line */
}
.element::after {
content: "New text";
text-indent: 0;
display: block;
line-height: initial; /* New content takes up original line height */
@maxyudin
maxyudin / wordpress-foundation-interchange.php
Last active April 22, 2017 11:02 — forked from Shelob9/foundation-interchange.php
Function to use Foundation's Interchange to make WordPress images automatically responsive. Also included is a function to add Interchange to the theme if Foundation is not already being used.http://foundation.zurb.com/docs/components/interchange.html
add_filter('post_thumbnail_html', 'slug_responsive_img', 5, 5);
//Image sizes for Interchange
add_image_size( 'fd-lrg', 1024, 99999);
add_image_size( 'fd-med', 768, 99999);
add_image_size( 'fd-sm', 320, 9999);
function slug_responsive_img($html, $post_id, $post_thumbnail_id, $size, $attr) {
//make image links
$attachment_id = $post_thumbnail_id;
$default = wp_get_attachment_image_src($attachment_id);
<?php
// get post ID from the URL query
$post_id = $_GET['post'];
// get post object
$new_item_to_add = get_post($post_id, OBJECT);
// get menu to add the item into (change to the relevant slug, ID, or name)
$existing_menu = wp_get_nav_menu_object('test-nav-menu-slug');
$existing_menu_id = $existing_menu->term_id;
<?php
function wpse267737_add_nav_menu_items($nav_menu_items) {
// get post ID from URL
$post_id = $_GET['post'];
// get current post data
$link_url = get_permalink( $post_id );
$link_anchor = get_the_title( $post_id );
<?php
function mxd_columns($columns) {
$columns['template'] = 'Template';
return $columns;
}
function mxd_show_template_columns($name, $post_id) {
$template = get_post_meta($post_id, '_wp_page_template', true);
echo $template;
}