Skip to content

Instantly share code, notes, and snippets.

@adeel-raza
adeel-raza / functions.php
Created December 19, 2019 00:15
Add new tag to lessons/topics/quizzes inside LeanrDash course table which are updated within 30 days
<?php
add_action( 'learndash-lesson-row-title-after', 'learndash_add_tag_to_new_lessons', 10, 3);
function learndash_add_tag_to_new_lessons( $lesson_id, $course_id, $user_id ) {
$lesson = get_post( $lesson_id );
if ( strtotime( $lesson->post_modified ) > strtotime( '-30 days' ) ) {
echo "<span class='ld-content-new-tag'>" . __( "(New)", 'sfwd-lms' ) . "</span>";
}
}
@davewarfel
davewarfel / default-wordpress-blocks-sass.scss
Last active November 8, 2023 11:31
WordPress Blocks Styles - Cleaned Up, Commented & Sassified
/**
* WordPress Blocks
*
* Default block styling included with WordPress core.
* Provides a better starting point for WordPress theme developers,
* especially when using Sass.
*
* @link https://github.com/WordPress/WordPress/blob/master/wp-includes/css/dist/block-library/style.css
*
* Most styles from the above file are included.
@FranciscoG
FranciscoG / acf_repeater_shortcode.php
Last active April 18, 2024 00:00
An Advanced Custom Fields shortcode that allows to loop through a field with a repeater. This only handles simple cases, it can't handle nested repeater fields
<?php
/**
* ACF Pro repeater field shortcode
*
* I created this shortcode function because it didn't exist and it was being requested by others
* I originally posted it here: https://support.advancedcustomfields.com/forums/topic/repeater-field-shortcode/
*
* @attr {string} field - (Required) the name of the field that contains a repeater sub group
* @attr {string} sub_fields - (Required) a comma separated list of sub field names that are part of the field repeater group
* @attr {string} post_id - (Optional) Specific post ID where your value was entered. Defaults to current post ID (not required). This can also be options / taxonomies / users / etc
@slushman
slushman / customizer-links.php
Last active September 23, 2023 13:03
How to link into the WordPress Customizer
@devinsays
devinsays / tracking.js
Created December 21, 2015 17:01
Track JetPack Shares in Google Analytics
/**
* Javacript for loading custom Google Analytics events
*
* @since 1.0.0
*/
(function($) {
// GA Docs for Social Interactions:
// https://developers.google.com/analytics/devguides/collection/analyticsjs/social-interactions
@devinsays
devinsays / redirect-admin.php
Last active May 14, 2022 15:54
Redirects subscribers back to the home page if they attempt to access the dashboard.
<?php
/**
* Redirects subscribers back to the home page if they attempt to access the dashboard.
*/
function prefix_redirect_admin() {
if ( ! current_user_can( 'edit_posts' ) && ! defined( 'DOING_AJAX' ) ) {
wp_safe_redirect( home_url() );
exit;
}
}
@devinsays
devinsays / hide-admin-bar.php
Last active February 7, 2021 15:16
Disables the #wpadmin bar for users without "edit_posts" permissions.
<?php
/**
* Disables the #wpadmin bar for users without "edit_posts" permissions.
*/
function prefix_hide_admin_bar() {
if ( ! current_user_can( 'edit_posts' ) ) {
add_filter( 'show_admin_bar', '__return_false' );
}
}
add_action( 'after_setup_theme', 'prefix_hide_admin_bar' );
@devinsays
devinsays / authenticate-by-email.php
Last active January 4, 2016 01:14
Allows visitors to log in using e-mail address
<?php
/**
* Allows visitors to log in using e-mail address
*
* @param string username passed by reference
*/
function prefix_authenticate_by_email( &$username ) {
$user = get_user_by( 'email', $username );
@cfxd
cfxd / shortcode.css
Last active November 17, 2021 05:53
How to Make the WordPress Video Shortcode Responsive. See http://cfxdesign.com/how-to-make-the-wordpress-video-shortcode-responsive
.wp-video, video.wp-video-shortcode, .mejs-container, .mejs-overlay.load {
width: 100% !important;
height: 100% !important;
}
.mejs-container {
padding-top: 56.25%;
}
.wp-video, video.wp-video-shortcode {
max-width: 100% !important;
}
<?php
/**
* Generate the CSS in the <head> section using the Theme Customizer
* @since 0.1
*/
add_action('generate_head_css','generate_your_css');
if ( !function_exists( 'generate_your_css' ) ) :
function generate_advanced_css()
{
$your_option = get_option( 'your_saved_db_entry' );