Skip to content

Instantly share code, notes, and snippets.

View wpexplorer's full-sized avatar
✍️
We create themes & plugins and run a popular blog about WordPress.

WPExplorer wpexplorer

✍️
We create themes & plugins and run a popular blog about WordPress.
View GitHub Profile
@wpexplorer
wpexplorer / gist:abe1a77e3ae7758271e41ab18d3a9698
Created November 8, 2021 00:07
Slider revolution - post template for different post types
// Set slider template ID based on post type.
add_filter( 'get_post_metadata', function ( $value, $post_id, $meta_key, $single ) {
if ( $meta_key === 'slide_template' ) {
$post_type = get_post_type( $post_id );
switch ( $post_type ) {
case 'post':
$value = 56; // change this to the template you want for this post type.
break;
case 'page':
$value = 56; // change this to the template you want for this post type.
<?php
namespace WPExplorer\Avatars;
defined( 'ABSPATH' ) || exit;
class Self_Hosted {
public function __construct() {
add_filter( 'user_contactmethods', array( $this, 'add_option' ) );
add_filter( 'pre_get_avatar', array( $this, 'alter_avatar' ), 1 , 3 );
@wpexplorer
wpexplorer / gist:0f4a428fadb179e6627920ba1a68163b
Created October 3, 2021 23:44
Add some customizer settings for CPT - Total WP Theme
// Return array of CPT's that we want to add customizer panels for.
function my_cpts() {
return array( 'cars' );
}
// Register new customizer panels.
add_filter( 'wpex_customizer_panels', function( $panels ) {
$cpts = my_cpts();
@wpexplorer
wpexplorer / gist:6d0ae9b369272135cc0f6d26c2081159
Created September 3, 2021 23:06
Category Icon Overlay | Total WP Theme
<?php
defined( 'ABSPATH' ) || exit;
if ( 'outside_link' !== $position ) {
return;
}
$taxonomy = wpex_get_post_primary_taxonomy(); // NOTE, if you know the taxonomy name you want to use, use that!!
$term_id = wpex_get_first_term_id( get_post(), $taxonomy );
@wpexplorer
wpexplorer / total-lightbox-small-btn
Last active September 1, 2021 00:41
Only show close button in lightbox | Total WP Theme
// Filter lightbox settings.
add_filter( 'wpex_lightbox_settings', function( $settings ) {
$settings['smallBtn'] = true;
return $settings;
} );
@wpexplorer
wpexplorer / gist:0820ce0e1cd9ba8d7d5b6c8a04003feb
Last active September 1, 2021 00:40
JS for checkbox to show/hide next button
add_action( 'wp_footer', function() { ?>
<script>
var checkboxes = document.getElementsByClassName( 'hh-toggle-next-disabled-button' );
for (let i = 0; i < checkboxes.length; i++) {
hh_button_toggle( checkboxes[i] );
}
function hh_button_toggle( checkbox ) {
var parent = checkbox.closest( '.wpb_raw_html' ) || checbox.closest( '.wpb_text_column' );
var button = parent.nextElementSibling;
@wpexplorer
wpexplorer / gist:33811c988bae14e64cc83cda9d7494ec
Last active August 26, 2021 01:36
Text Block More Toggle - Total WP Theme
// Hook into the vc_shortcode_content_filter flter to modify the vc_column_text content
// and covert the more tag into an actual toggle button.
add_filter( 'vc_shortcode_content_filter', function( $content, $shortcode ) {
if ( 'vc_column_text' !== $shortcode ) {
return $content;
}
$is_inline = vc_is_inline();
$needle = $is_inline ? '<!--more-->' : '<span id="more';
$pattern = $is_inline ? '#<!--more-->#' : '#<span id=\"more-\d+\"><\/span>#';
@wpexplorer
wpexplorer / total-insert-template-after-header
Last active September 1, 2021 00:42
Insert custom template after the site header | Total WP Theme
// Insert custom template after site header.
add_action( 'wpex_hook_header_after', function() {
echo do_shortcode( '[templatera id="15528"]' );
} );
@wpexplorer
wpexplorer / gist:eada43e45f2882586f1213891f640dad
Last active October 11, 2020 03:14
Add multiple fonts to Total Theme via code.
function wpex_add_custom_fonts() {
return array( 'Font 1', 'Font 2', 'Font 3', 'Font 4' );
}
@wpexplorer
wpexplorer / gist:23f6da2b6f1c0e52f336750a5733c945
Last active September 7, 2020 01:33
PHP Singleton Example
class My_Class {
/**
* Our single My_Class instance.
*
* @var My_Class
*/
private static $instance;
/**