Skip to content

Instantly share code, notes, and snippets.

Avatar

Hedley Phillips DigitalEssence

View GitHub Profile
@DigitalEssence
DigitalEssence / Database Many to Many Relationship
Last active Nov 16, 2021
Database Many to Many Relationship
View Database Many to Many Relationship
user
+----+-----------+----------+-------+
| id | firstname | lastname | email |
+----+-----------+----------+-------+
| 1 | Peter | Jones | email |
| 2 | Bob | Smith | email |
| 3 | Sarah | Peters | email |
| 4 | Christine | Hall | email |
+----+-----------+----------+-------+
@DigitalEssence
DigitalEssence / WordPress - Enfold - PHP - Add Sticky button
Created Apr 9, 2021
WordPress - Enfold - PHP - Add Sticky button
View WordPress - Enfold - PHP - Add Sticky button
// Add Header Code
function de_sticky_button() {
?>
<!-- Start of Sticky Button -->
<a href="https://www.givey.com/renewcrew" target="_blank" title="Click to donate" class="sticky-button">CLICK TO DONATE</a>
<!-- End of Sticky Button -->
<?php
}
add_action('wp_body_open', 'de_sticky_button');
@DigitalEssence
DigitalEssence / Powershell - Replace space in filename with hyphen
Created Apr 29, 2020
Powershell - Replace space in filename with hyphen
View Powershell - Replace space in filename with hyphen
dir | rename-item -NewName {$_.name -replace " ","-"}
@DigitalEssence
DigitalEssence / Javascript-Enqueue
Last active Apr 28, 2020
WordPress - Javascript - Enqueue javascript
View Javascript-Enqueue
// Add Javascript to select default options in Product Add on
function digitalessence_new_scripts(){
wp_enqueue_script( 'product-addon-default-values', get_stylesheet_directory_uri() . '/js/product-addon-default-value.js', array(), true );
}
add_action( 'wp_enqueue_scripts', 'digitalessence_new_scripts' );
@DigitalEssence
DigitalEssence / WordPress - Enfold - PHP - Detect if a post date is in the past and add a class
Created Apr 11, 2019
WordPress - Enfold - PHP - Detect if a post date is in the past and add a class
View WordPress - Enfold - PHP - Detect if a post date is in the past and add a class
// Detect if post is in the past and if so add a custom Class "oldpost"
if (strtotime(get_the_date( "Y-m-d", $the_id )) < strtotime(date("Y-m-d"))) {
$post_class = "post-entry post-entry-{$the_id} oldpost slide-entry-overview slide-loop-{$post_loop_count} slide-parity-{$parity} {$last}";
}
else {
$post_class = "post-entry post-entry-{$the_id} slide-entry-overview slide-loop-{$post_loop_count} slide-parity-{$parity} {$last}";
}
@DigitalEssence
DigitalEssence / WordPress - PHP - Display posts dated in the future
Created Apr 11, 2019
WordPress - PHP - Display posts dated in the future
View WordPress - PHP - Display posts dated in the future
//Display Future Posts
function de_prevent_future_type( $post_data ) {
if ( $post_data['post_status'] == 'future' && $post_data['post_type'] == 'post' )
/*Here I am checking post_type='post' , you may use different post type and if you want it
for all post type then remove "&& $post_data['post_type'] == 'post'"
*/
{
$post_data['post_status'] = 'publish';
}
return $post_data;
@DigitalEssence
DigitalEssence / WordPress - PHP - Add og Open Graph data to header
Created Mar 14, 2019
WordPress - PHP - Add og Open Graph data to header
View WordPress - PHP - Add og Open Graph data to header
//Add Open Graph
add_action('wp_head', 'fb_opengraph');
function fb_opengraph() {
if( is_single() || is_page() ) {
echo '
<meta property="og:title" content="Osso Restaurant - Peebles" />
<meta property="og:description" content="Osso Restaurant Peebles - Michelin Bib Gourmand Winner 2011 to 2018" />
<meta property="og:image" content="https://www.ossorestaurant.com/wp-content/uploads/2019/03/facebook-og-image.jpg" />';
}
}
@DigitalEssence
DigitalEssence / WordPress - MYSQL - Delete all post revisions from database
Created Mar 13, 2019
WordPress - MYSQL - Delete all post revisions from database
View WordPress - MYSQL - Delete all post revisions from database
DELETE FROM wp_posts WHERE post_type = "revision";
View WordPress - Debug Pending Updates
/**
* Debug Pending Updates
* Displays hidden plugin and theme updates on update-core screen.
*/
function debug_pending_updates() {
// Rough safety nets
if ( ! is_user_logged_in() || ! current_user_can( 'update_plugins' ) || ! current_user_can( 'update_themes' ) ) return;
$output = "";
@DigitalEssence
DigitalEssence / WordPress - Enfold - PHP - Add Div using functionand add_action
Created Feb 18, 2019
WordPress - Enfold - PHP - Add Div using functionand add_action
View WordPress - Enfold - PHP - Add Div using functionand add_action
// Simple function to add a div
// Note, the display is set to none so it is only visible in the source code
function custom_stuff(){
?>
<div style="display:none">Find this</div>
<?php
}
add_action('wp_footer', 'custom_stuff');