Skip to content

Instantly share code, notes, and snippets.

View CapWebSolutions's full-sized avatar

Matt Ryan CapWebSolutions

View GitHub Profile
@CapWebSolutions
CapWebSolutions / add_widget_after_third_post_in_archive.php
Created February 7, 2018 23:08
Adds specified widget area after 3rd post in archive
//* Add widget area after the third post in archives
add_action( 'genesis_after_entry', 'prefix_archive_widgets' );
function prefix_archive_widgets() {
if ( !is_archive() ) return;
global $wp_query;
if ( 2 == $wp_query->current_post ) {
genesis_widget_area( 'archive-content-ad', array(
'before' => '<div class="archive-ad archive-content-ad clearfix">',
'after' => '</div>',
) );
@CapWebSolutions
CapWebSolutions / custom-taxonomy-shortocde.php
Created February 7, 2018 23:05
Create custom-post-meta shortcode to insert custom taxonomy into genesis post_meta
/** A custom shortcode to fetch terms of a custom taxomomy for any post **/
add_shortcode( 'prefix-custom-post-meta', 'prefix_custom_post_meta' );
function prefix_custom_post_meta( $atts ) {
$defaults = array(
'prepend' => 'Listed Under: ', // Text to be added before the terms output.
'append' => '', // Text to be added after the terms ouptut.
'separator' => '&middot; ', // Separator used to separate multiple terms.
'taxonomy' => '', // Taxonomy name to fetch the terms from. Replace to set a default.
);
@CapWebSolutions
CapWebSolutions / add_cpt_to_posts_archives.php
Created February 7, 2018 23:02
Two functions to add CPT archives into the mix for post archives and front page loops.
add_filter( 'pre_get_posts', 'prefix_cpk_show_cpt_archives' );
add_action( 'pre_get_posts', 'prefix_cpk_add_custom_post_types_to_loop' );
/**
* prefix_cpk_show_cpt_archives - Display job posting entires on taxonomy archive pages
*
* @param [type] $query
* @return void
*/
function prefix_cpk_show_cpt_archives( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
@CapWebSolutions
CapWebSolutions / editor-intro.php
Created February 7, 2018 23:00
Add a small introduction before editor content meta box
/**
* Add a little intro above the post editor screen for Job_post CPT.
*/
add_action( 'edit_form_after_title', 'prefix_add_editor_intro' );
function prefix_add_editor_intro() {
global $post, $post_type;
if( is_admin() && 'job_posting' == $post_type ) {
echo 'Enter full job description in box below, including, but not limited to: education requirements, experience needed, recommended skills, job responsibilities, benefits, application requirements, salary, etc.';
}
}
@CapWebSolutions
CapWebSolutions / gist:9fe95c7426324242c45cba97e7cc4d8f
Created January 3, 2018 15:47
Detect MSIE running, include Trident and perform specific code.
add_filter( 'ssp_episode_meta_details', 'ssp_remove_download_links', 10, 3 );
function ssp_remove_download_links ( $meta, $episode_id, $context ) {
$agent=strtoupper($_SERVER['HTTP_USER_AGENT']);
if ( strpos($agent,'MSIE') !== false || strpos($agent,'TRIDENT')!== false ) {
// Someone is STILL using IE. Don't show the downlolad links since they won't work in SSP.
/* IE specific code here */
return /*filtered result*/;
}
return $meta;
}
@CapWebSolutions
CapWebSolutions / MySQL inquiry to find all additional post type in db
Created December 21, 2017 20:32
Use this gist in phpmyadmin to find extraneous stuff in db. Use Custom Post Type Cleanup PI to get rid of the stuff.
SELECT `ID`, `post_title`, `post_type`
FROM `wp_posts`
WHERE `post_type` NOT IN ('post','page','attachment','revision','nav_menu_item','custom_css','customize_changeset')
LIMIT 100
@CapWebSolutions
CapWebSolutions / add-ads-after-2nd-para.php
Created November 9, 2017 15:37
nsert ads after second paragraph of single post content.
<?php
//Insert ads after second paragraph of single post content.
add_filter( 'the_content', 'wsm_insert_post_ads' );
function wsm_insert_post_ads( $content ) {
$ad_code = '<div class="content-ad-block"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Top Posts 300 250 -->
<ins class="adsbygoogle"
style="display:inline-block;width:300px;height:250px"
data-ad-client="ca-pub-2169025261524250"
<?php
/**
* Ref: https://kuttler.eu/en/code/wordpress-emergency-admin/
* Upload to wp-content/mu-plugins/whichevernameyoulike.php
*/
$login = 'foobar'; # New username
$password = 'barbaz'; # Password for the new user
$email = 'you@example.com'; # Email address of the new user
$ip = '127.0.0.1'; # Insert your IP, http://google.com/search?&q=what%20is%20my%20ip
@CapWebSolutions
CapWebSolutions / gist:250976f3df9abb5a2b4e39c1b5b8ee0d
Created October 3, 2017 21:45
Hide Category Count WooCommerce
add_filter( 'woocommerce_subcategory_count_html', '__return_null' );
@CapWebSolutions
CapWebSolutions / gist:edbb26f9e64fe10d1d31695dd5e64a9f
Created September 11, 2017 20:00
Enable WooCommerce Product Gallery Features
// Disabling gallery features
// This new gallery is off by default for custom and 3rd party themes since it's common to disable the WooCommerce gallery
// and replace with your own. To enable the gallery, you can declare support like this
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
// You do not have to support all 3; you can pick and choose.
// If a feature is not supported, the scripts will not be loaded and the gallery code will not execute on product pages.