Skip to content

Instantly share code, notes, and snippets.

View macgraphic's full-sized avatar
💣

Mark Smallman macgraphic

💣
View GitHub Profile
@macgraphic
macgraphic / macg_change_post_label
Created February 17, 2017 11:42
Change Admin Menu For Blog Posts
// Change Admin Menu For Blog Posts
function macg_change_post_label() {
global $menu;
global $submenu;
$menu[5][0] = 'Blogs';
$submenu['edit.php'][5][0] = 'Blogs';
$submenu['edit.php'][10][0] = 'Add Blogs';
$submenu['edit.php'][16][0] = 'Blogs Tags';
}
function macg_change_post_object() {
@macgraphic
macgraphic / remove_extra_field_profile
Created March 17, 2017 15:20
Remove un-needed fields from the user profile page in /wp-admin. Add this to the theme functions.php
<?php
// Remove un-needed fields from the user profile page in /admin
function remove_extra_field_profile() {
$current_file_url = preg_replace( '#\?.*#' , '' , basename( $_SERVER['REQUEST_URI'] ) );
if ( $current_file_url == 'profile.php' ) {
add_action( 'wp_loaded', function(){ ob_start( 'profile_callback' );
} );
add_action( 'shutdown', function(){ ob_end_flush();
@macgraphic
macgraphic / single.php
Last active October 26, 2017 15:29
Show or hide the featured image thumb if post has gallery
<?php
// if the post does NOT have a [gallery], show the featured image
if ( strpos( $post->post_content,'[gallery' ) === false ) {
$gallery = 0;
if ( has_post_thumbnail() && 'gallery' != get_post_format() ) {
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
if ( ! empty( $large_image_url[0] ) ) {
echo '<a rel="lightbox" href="' . esc_url( $large_image_url[0] ) . '" title="' . the_title_attribute( array( 'echo' => 0 ) ) . '">';
echo get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'class' => 'float-right thumbnail' ) );
echo '</a>';
@macgraphic
macgraphic / tooltip-shortcode
Last active November 16, 2017 11:34
Adds the foundation Tooltip as a shortcode
// Add Shortcode
function foundation_tooltip( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'content' => 'Default Content',
'title' => 'Default title',
),
$atts,
'tooltip'
<!-- Add this to your theme functions.php file -->
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
// This theme uses a custom image size for featured images, displayed on "standard" posts.
if ( function_exists( 'add_theme_support' ) ) {
@macgraphic
macgraphic / simple.php
Created March 2, 2018 12:29
Woo simple - single product page, adding svg icon to button _ theme/woocommerce/single-product/add-to-cart.php/simple.php
<?php
/**
* Simple product add to cart
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product/add-to-cart/simple.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@macgraphic
macgraphic / Woo header icons function
Last active March 5, 2019 21:24
Displays SVG icon in header for Yith Woo wishlist
function items_in_whishlist() {
if ( yith_wcwl_count_all_products() == 0 ) { ?>
<a data-toggle="wishlist-empty">
<img src="<?php echo esc_url( get_stylesheet_directory_uri() . '/assets/images/heart-empty-24px.png' ); ?>">
</a>
<?php
} else { ?>
<a href="<?php echo esc_url( site_url( '/wishlist' ) ); ?>" data-toggle="wishlist-fill">
<img src="<?php echo esc_url( get_stylesheet_directory_uri() . '/assets/images/heart-fill-24px.png' ); ?>">
</a>
var savedRuler= app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var w = app.activeDocument.width;
var h = app.activeDocument.height;
if(w>h) app.activeDocument.resizeCanvas (w, w, AnchorPosition.MIDDLECENTER);
if(w<h) app.activeDocument.resizeCanvas (h, h, AnchorPosition.MIDDLECENTER);
//if w==h already square
app.preferences.rulerUnits = savedRuler;
// Add Supporter Levels (Taxonomies)
// Register Custom Taxonomy
function supporter_lvl_taxonomy() {
$labels = array(
'name' => _x( 'Supporter Levels', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Supporter Level', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Supporter Levels', 'text_domain' ),
'all_items' => __( 'All Levels', 'text_domain' ),
'parent_item' => __( 'Parent Item', 'text_domain' ),
@macgraphic
macgraphic / newsslider.php
Last active August 14, 2019 18:11
News Slider Block Template
<?php
/**
* News Slider Block Template.
*/
// Create id attribute allowing for custom "anchor" value.
$id = 'newsslider-' . $block['id'];
if ( ! empty( $block['anchor'] ) ) {
$id = $block['anchor'];