Skip to content

Instantly share code, notes, and snippets.

View sabotawsh's full-sized avatar

Natasha McDiarmid sabotawsh

View GitHub Profile
@sabotawsh
sabotawsh / header.js
Created July 14, 2020 21:18
When a site wide banner is toggled on, push the fixed header down so they do not overlap.
// IF SITEWIDE BANNER IS ON
// PUSH SECONDARY ANCHOR NAV DOWN LOWER
(function($) { // Begin jQuery
$(function() { // DOM ready
if ($('.sitewide-banner')[0]) {
$('header').addClass('header--low');
};
}); // end DOM ready
})(jQuery); // end jQuery
@sabotawsh
sabotawsh / woocommerce_sitewidebanner
Created July 14, 2020 21:17
If site wide banner is toggled on, nudge fixed header down
// WOOCOMMERCE – IF SITE WIDE BANNER IS ACTIVE
// DROP MAIN NAV DOWN
if ( jQuery('.woocommerce-store-notice').css('display') == "block") {
$('header.navigation').addClass('drop-low');
}
// IF SITE WIDE BANNER IS DISMISSED
// BRING MAIN NAVIGATION BACK TO TOP
$('.woocommerce-store-notice__dismiss-link').on('click', function(){
$('header.navigation.drop-low').removeClass('drop-low');
})
@sabotawsh
sabotawsh / wp_alt_title_thumb.php
Created April 28, 2020 21:51 — forked from fjaguero/wp_alt_title_thumb.php
Wordpress: Get ALT and TITLE for the post thumbnail
<?php if ( has_post_thumbnail() ) :?>
<a href="<?php the_permalink() ?>" class="thumb"><?php the_post_thumbnail('thumbnail', array(
'alt' => trim(strip_tags( $post->post_title )),
'title' => trim(strip_tags( $post->post_title )),
)); ?></a>
<?php endif; ?>
@sabotawsh
sabotawsh / gist:2ef62b52b62876b200dc291061b7f819
Created May 19, 2019 01:18 — forked from dhigginbotham/gist:3718052
Custom Post Type w/ Taxonomies and Categories
// let's create the function for the custom type
function custom_post_example() {
// creating (registering) the custom type
register_post_type( 'custom_type', /* (http://codex.wordpress.org/Function_Reference/register_post_type) */
// let's now add all the options for this post type
array('labels' => array(
'name' => __('Custom Types', 'bonestheme'), /* This is the Title of the Group */
'singular_name' => __('Custom Post', 'bonestheme'), /* This is the individual type */
'all_items' => __('All Custom Posts', 'bonestheme'), /* the all items menu item */
'add_new' => __('Add New', 'bonestheme'), /* The add new menu item */
@sabotawsh
sabotawsh / functions.php
Created May 1, 2019 16:59 — forked from vishalbasnet23/functions.php
Simple Post View Counter WordPress
<?php
/**
* Post view Count
*/
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
function wpb_set_post_views($postID) {
$count_key = 'wpb_post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
@sabotawsh
sabotawsh / remove-admin-features.php
Created February 13, 2019 15:14
WordPress – Removing Unused Admin Features from Dashboard
// REMOVES POST AND COMMENT SECTION FROM WP DASHBOARD
function post_remove () {
remove_menu_page('edit.php');
remove_menu_page( 'edit-comments.php' );
}
add_action('admin_menu', 'post_remove');
@sabotawsh
sabotawsh / random-background-generator.php
Created July 13, 2018 01:05
Random image background generator
<?php
$bg = array('bg-01.jpg', 'bg-02.jpg', 'bg-03.jpg', 'bg-04.jpg', 'bg-05.jpg', 'bg-06.jpg', 'bg-07.jpg' ); // array of filenames
$i = rand(0, count($bg)-1); // generate random number size of the array
$selectedBg = "$bg[$i]"; // set variable equal to which random filename was chosen
?>
<style type="text/css">
<!--
body{
@sabotawsh
sabotawsh / acf_image.php
Last active August 17, 2022 15:32
When using Advanced Custom Field plugin for WordPress, this allows you to target custom image sizes
<?php
$attachment_id = get_field('image');
$size = "square";
$image = wp_get_attachment_image_src( $attachment_id, $size );
?>
<img alt="Image of <?php the_title(); ?>" src="<?php echo $image[0]; ?>">
// IF GROUP
<?php
$attachment_id = get_sub_field('image');
<?php if (($wp_query->current_post +1) == ($wp_query->post_count)) {
echo 'This is the last post';
} ?>
<?php if (($wp_query->current_post +1) != ($wp_query->post_count)) {
echo 'This is the not the last post';
} ?>
@sabotawsh
sabotawsh / ifcustomfield.php
Created May 6, 2018 00:04 — forked from adapicom/ifcustomfield.php
Print Custom Field IF Custom Field Exists
<?php if(get_post_meta($post->ID, 'single-bottom-ad', true)): ?>
<div id="single-bottom-ad">
<?php echo get_post_meta($post->ID, 'single-bottom-ad', true); ?>
</div>
<?php endif; ?>