Skip to content

Instantly share code, notes, and snippets.

View paaljoachim's full-sized avatar

Paal Joachim Romdahl paaljoachim

View GitHub Profile
@paaljoachim
paaljoachim / functions.php
Last active February 28, 2024 21:41
WooCommerce show/hide products based on if the user is logged inn or logged out.
<?php
// https://businessbloomer.com/woocommerce-remove-specific-category-shop-loop/
// https://stackoverflow.com/questions/34684881/hide-products-from-users-who-are-not-logged-in-using-tags/34689768#34689768
add_action( 'woocommerce_product_query', 'show_hide_products_category_shop' );
function show_hide_products_category_shop( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
if ( is_user_logged_in() ) {
@paaljoachim
paaljoachim / functions.php
Created September 2, 2017 07:55
Add image to category screen.
// Made by Isaac: https://gist.github.com/itzikbenh/16326bc3947f272cd6bb44de03c4774b?fref=gc&dti=168889943173228
// and improved by Ian. https://www.facebook.com/groups/advancedwp/permalink/1607185879343620/
function add_category_meta_fields( $taxonomy ) {
?>
<div class="form-field create-cat term-featured-image-wrap">
<label for="tax-featured-image">Featured Image</label>
<input id="tax-featured-image" type="text" name="featured_image">
<br>
<button id="add-cat-featured-img" class="button" name="button">Add Featured Image</button>
@paaljoachim
paaljoachim / hide-meta-boxes-single-post-page-screen.php
Last active October 14, 2018 08:33
Hide meta boxes in the single page and post screen. Turn them on again in the Screen Options. Add the code to your WordPress child theme functions file or a custom functions plugin.
// At http://wordpress.stackexchange.com/questions/15376/how-to-set-default-screen-options bottom comment the following code $hidden is mentioned.
// Hides meta boxes. Turn them on through the Screen Options.
add_filter( 'hidden_meta_boxes', 'custom_hidden_meta_boxes' );
function custom_hidden_meta_boxes( $hidden ) {
// Hide meta boxes on the single Post screen
// Left column
$hidden[] = 'postexcerpt'; // Post Excerpts
$hidden[] = 'trackbacksdiv'; // Send Trackbacks
$hidden[] = 'postcustom'; // Custom Fields
$hidden[] = 'commentstatusdiv'; // Discussion
@paaljoachim
paaljoachim / genesis-featured-image.php
Last active April 16, 2022 14:52
Featured image for Genesis themes. 1. Sets the featured image. 2. If no featured image get image from category. 3. If no category image then get the first post image. 4. If no post image or category image then sets a fallback image.
@paaljoachim
paaljoachim / featured-images.php
Last active September 12, 2018 10:44
Set Featured image. 1. Sets the featured image. 2. If no featured image get image from category. 3. If no category image then get the first post image. 4. If no post image or category image then sets a fallback image.
//Altitude Pro customize.php code -
// Tutorial I am brushing up is here: http://easywebdesigntutorials.com/customizing-altitude-pro-genesis-child-theme/
<?php
/**
* Customizer additions.
*
* @package Altitude Pro
* @author StudioPress
* @link http://my.studiopress.com/themes/altitude/
@paaljoachim
paaljoachim / filed-under-categories
Last active February 13, 2016 15:45
Post preview and posts - Genesis code snippets
// Customize the post meta "FILED UNDER: -category name-" categories text and below the post preview in a blog page and change it at the bottom of a post.
// http://wordpress.stackexchange.com/questions/50961/removing-post-meta-from-category-pages */
//
add_filter( 'genesis_post_meta', 'sp_post_meta_filter' );
function sp_post_meta_filter($post_meta) {
if ( !is_page() ) {
if (is_archive() ) $post_meta = '';
else $post_meta = '[post_categories before="Categories: "] [post_tags before="Keywords: "]';
return $post_meta;
}}
@paaljoachim
paaljoachim / global.js
Created August 24, 2015 09:49
Creating a sticky header.
// Adding code to create an effect on the header/nav on scroll
jQuery(function( $ ){
if( $( document ).scrollTop() > 0 ){
$( '.site-header' ).addClass( 'dark' );
}
// Add opacity class to site header
$( document ).on('scroll', function(){
@paaljoachim
paaljoachim / remove-default-WP-widgets.php
Created August 20, 2015 07:05
The code snippet added to the functions.php file will remove the default WordPress widgets. I have commented the widgets I do not want to remove.
/* The below code removes all the default WordPress widgets. I commeted the ones I do not want to remove. */
// unregister all widgets
function unregister_default_widgets() {
unregister_widget('WP_Widget_Pages');
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Archives');
unregister_widget('WP_Widget_Links');
unregister_widget('WP_Widget_Meta');
unregister_widget('WP_Widget_Search');
@paaljoachim
paaljoachim / default-post-thumbnail.php
Created August 20, 2015 06:52
Define a post thumbnail with Genesis child themes.
//* Define a default post thumbnail
//* http://dreamwhisperdesigns.com/genesis-tutorials/genesis-default-thumbnails/
add_filter('genesis_get_image', 'default_image_fallback', 10, 2);
function default_image_fallback($output, $args) {
global $post;
if( $output || $args['size'] == 'full' )
return $output;
$thumbnail = CHILD_URL.'/images/WordPress-info150x150.jpg';