Skip to content

Instantly share code, notes, and snippets.

View finalwebsites's full-sized avatar

Olaf Lederer finalwebsites

View GitHub Profile
@finalwebsites
finalwebsites / shortcode_image_tag.php
Last active March 4, 2025 16:47
Add the shortcode option to dynamic tags for background images in Elementor
<?php
// place the snippet inside the functions.php file from your WordPress child theme
use Elementor\Controls_Manager;
add_action( 'elementor/dynamic_tags/register_tags', function( $dynamic_tags ) {
class Custom_Image_Tag extends Elementor\Core\DynamicTags\Data_Tag {
public function get_name() {
return 'shortcode-image';
}
@finalwebsites
finalwebsites / 404.php
Created March 2, 2025 15:13
Static 404 page template for WordPress
<!doctype html>
<html lang="nl">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>404 - page not found</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<style>
body { background: #dedede; }
.page-wrap { min-height: 100vh; }
@finalwebsites
finalwebsites / .htaccess
Created September 3, 2022 06:52
Ignore missing files and report a 404 status
# add this code to your .htaccess file (Apache based servers only)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} \.(jpg|jpeg|png|gif|bmp|ico|css|js|swf|htm|html|txt|php|asp|aspx)$ [NC]
RewriteRule .* - [L,R=404]
</IfModule>
@finalwebsites
finalwebsites / functions.php
Created December 31, 2024 15:17
Send WordPress emails with a template created in Maileroo
<?php
// replace the template ID 123 with your own
add_filter('ssbm_add_template_data', function($payload, $atts) {
if ($atts['message'] == strip_tags($payload['html'])) {
$message = nl2br($atts['message']);
unset($payload['html']);
$payload['template_id'] = 123;
$payload['template_data'] = json_encode(
array('content' => $message)
@finalwebsites
finalwebsites / functions.php
Last active December 11, 2024 14:35
WordPress shortcodes for the Event Organiser plugin
<?php
// place this code into the functions.php file from your child theme
// Show date info on a single event page
add_shortcode('fw_eo_date_time', function($atts) {
$atts = shortcode_atts( array(
'timelabel' => __('Time', 'eventorganiser'),
'to' => '-',
'prefix' => ''
@finalwebsites
finalwebsites / functions.php
Created December 9, 2024 07:11
Contact Form 7 - Submit subscriber data to EmailOctopus
<?php
// Place this code into the functions.php file or your WordPress child theme
add_action('wpcf7_mail_sent', 'fw_wpcf7_subscribe_to_eo4wp' );
function fw_wpcf7_subscribe_to_eo4wp( $contact_form ){
// get form id
$form_id = $contact_form->id();
// get submission data
$submission = WPCF7_Submission::get_instance();
@finalwebsites
finalwebsites / phpmailer_action.php
Created December 4, 2024 08:28
Example: Overide the PHPMailer object in WordPress
<?php
add_action( 'phpmailer_init', 'fw_prepare_email' );
function fw_prepare_email( $phpmailer ) {
$host = get_option('fw_tools_smtp_host');
$port = get_option('fw_tools_smtp_port');
$login = get_option('fw_tools_smtp_login');
$password = get_option('fw_tools_smtp_password');
$from = get_option('fw_tools_from_address');
@finalwebsites
finalwebsites / functions.php
Created November 21, 2024 10:51
Disable WordPress update email notifications
<?php
// place the code below into the functions.php file from your WordPress child theme
// disable core update notifications
add_filter( 'auto_core_update_send_email', 'fws_stop_auto_update_emails', 10, 4 );
function fws_stop_update_emails( $send, $type, $core_update, $result ) {
if ( ! empty( $type ) && $type == 'success' ) {
return false;
}
@finalwebsites
finalwebsites / functions.php
Last active November 15, 2024 15:20
WordPress afbeeldingen: ALT tags automatisch aanmaken tijdens uploaden
<?php
// Plaats deze code in het functions.php bestand van je WordPress Child Theme
add_action( 'add_attachment', 'fws_set_image_alt_after_upload' );
function fws_set_image_alt_after_upload( $post_ID ) {
if ( wp_attachment_is_image( $post_ID ) ) {
$post = get_post( $post_ID );
update_post_meta( $post_ID, '_wp_attachment_image_alt', $post->post_title );
}
}
@finalwebsites
finalwebsites / functions.php
Last active October 19, 2024 14:14
WordPress: Disable dashboard widgets, like new & events or quick press
<?php
// add this code to the functions.php file from your chilc theme
add_action('wp_dashboard_setup', 'fws_remove_dashboard_widgets', 100);
function fws_remove_dashboard_widgets(){
remove_meta_box('dashboard_quick_press', 'dashboard', 'side'); // Quick draft
remove_meta_box('dashboard_primary', 'dashboard', 'side'); // WordPress Events and News
remove_meta_box('dashboard_activity', 'dashboard', 'side'); // Activity
remove_meta_box('dashboard_site_health', 'dashboard', 'side'); //Site Health Status