Skip to content

Instantly share code, notes, and snippets.

@finalwebsites
finalwebsites / functions.php
Created October 16, 2024 19:19
Structured organization data for WordPress websites
<?php
add_action('wp_head', 'fws_create_organisatie_data');
function fws_create_organisatie_data() {
$data = array(
'@context' => 'https://schema.org',
'@type' => 'Organization',
'name' => 'Bedrijfsnaam',
'legalName' => 'Volledig bedrijfsnaam',
'url' => 'https://www.website.nl/',
@finalwebsites
finalwebsites / functions.php
Created September 26, 2024 08:59
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');
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
@finalwebsites
finalwebsites / functions.php
Last active September 21, 2024 13:31
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
Created August 21, 2024 13:48
Alternative related posts on the single product page (used it for the Bootscore starter theme)
<?php
// requirements: Bootscore + bs Swiper extension
remove_action('woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
add_action('woocommerce_after_single_product_summary', function() {
if (function_exists('bootscore_product_slider')) {
echo '
<div class="related-posts mb-3">
<hr>
<h2 class="h4 text-center my-4">'.apply_filters('bootscore/bs-swiper/related-posts/heading', __('You might also like', 'bootscore')).'</h2>';
@finalwebsites
finalwebsites / functions.php
Last active August 16, 2024 10:19
Delete permanently WooCommerce products including the attached images
<?php
// check the information in the comments
add_action( 'before_delete_post', 'fws_delete_images_for_product', 99, 2 );
function fws_delete_images_for_product( $postid, $post ) {
if ( 'product' !== $post->post_type ) {
return;
}
$img_ids = array();
@finalwebsites
finalwebsites / bounceforward.php
Last active July 30, 2024 13:10
Use this small PHP script to forward email bounce messages (via Mailersend)
<?php
$msg = '';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$data = json_decode(file_get_contents('php://input'), true);
parse_str($_SERVER['QUERY_STRING'], $qs_array);
@finalwebsites
finalwebsites / nginx.conf
Created July 13, 2024 18:55
Instruct NGINX about a custom 404 error page
location ~* \.(gif|jpg|jpeg|png|webp|avif|css|js|svg|txt|rar|gz|zip|html|json|map|woff2|woff)$ {
error_page 404 /404.html;
expires 1y;
access_log off;
}
@finalwebsites
finalwebsites / .htaccess
Created July 13, 2024 18:49
Show a static 404 error page for static files
ErrorDocument 404 /404.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} \.(gif|jpg|jpeg|png|webp|avif|css|js|svg|txt|rar|gz|zip|html|json|map|woff2|woff)$ [NC]
RewriteRule .* - [L,R=404]
</IfModule>
@finalwebsites
finalwebsites / functions.php
Last active June 15, 2024 15:50
Filter hook examples for the EmailOctopus for WordPress plugin
<?php
add_filter('fweo_emailoctopus_show_static', function($show, $post) {
/*
add here the conditions and return $show = true
for example:
*/
if (is_category()) $show = true;
return $show;
}, 10,2);
@finalwebsites
finalwebsites / gratis_verzending.php
Created March 26, 2024 18:46
WooCommerce: Overige verzendmethoden verbergen indien gratis verzending van toepassing is
<?php
function fws_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
break;
}
}