Skip to content

Instantly share code, notes, and snippets.

View moritzbappert's full-sized avatar
🚀
Building WordPress Websites for Growing Companies.

Moritz Bappert moritzbappert

🚀
Building WordPress Websites for Growing Companies.
View GitHub Profile
@MogulChris
MogulChris / functions.php
Created August 26, 2020 23:52
WP Bakery / Visual Composer custom css on WooCommerce shop page
<?php
// The issue:
// You want to use WP Bakery for your WooCommerce shop page.
// You can enable WP Bakery for that page, but custom Design Options are not showing.
// The explanation:
// WP Bakery keeps those custom design changes as a CSS string, stored as post meta on the page you are using for your shop page.
// Unfortunately that CSS is not being output by your theme, hence your custom design changes are not working.
<?php
/*
Plugin Name: WP All Import - Redirection AddOn
Description: Add a redirect for each post imported.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
@logichub
logichub / acf-cpt-custom-post-title-slug.php
Last active September 9, 2022 10:30 — forked from philhoyt/advanced-custom-fields-post-title.php
Using Advanced Custom Fields to create Post Title & Slug for different CPTs
<?php
// Auto fill Title and Slug for 'companies' CPT
function acf_title_companies( $value, $post_id, $field ) {
if ( get_post_type( $post_id ) == 'companies' ) {
$new_title = get_field( 'company_name', $post_id ) . ' ' . $value;
$new_slug = sanitize_title( $new_title );
wp_update_post( array(
@djrmom
djrmom / custom-hooks.php
Created November 15, 2018 00:17
facetwp woocommerce _product_attributes
<?php
/** some types of product attributes for woocommerce (those that are not taxonomies or used for variations
** are saved only in the _product_attributes custom field as an array
** select "_product_attributes" as the datasource in the facet and use facetwp_index_row to find and index
** the correct attributes
**/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'attributes' == $params['facet_name'] ) { //change 'attributes' to name of your facet
$values = maybe_unserialize( $params['facet_value'] );
@saas786
saas786 / wp-localhost-requests.php
Created September 7, 2017 06:20
WordPress annoying issue, while working locally using http api you keep getting "A valid URL was not provided", or using functions such as "wp_safe_remote_request,wp_safe_remote_get or wp_safe_remote_post" and you are unable to request local website and you are not sure why its not working, because same code work on live.
<?php
/**
* Plugin Name: Allow localhost http requests.
* Plugin URI: https://gist.github.com/saas786/a567363477df7e28b0c1df6295cadf75/
* Description: Note: Please don't use it on live website. If you are working locally, sometimes you get errors such as "A valid URL was not provided" or such, specially when you are interacting with website which is also hosted locally, so it becomes annoying at times to find the cause, and most of the time its wp_safe_remote_request, wp_safe_remote_get or wp_safe_remote_post functions who are the culprit. So this plugin is a quick fix.
* Author: saas786
* Version: 0.1
*/
add_filter( 'http_request_host_is_external', 'wplr_http_request_host_is_external' );
function wplr_http_request_host_is_external(){
@amboutwe
amboutwe / yoast_seo_canonical_change_woocom_shop.php
Last active April 11, 2024 02:02
Code snippets for the Yoast SEO canonical output
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Change the canonical link for the shop page
* Credit: Scott Weiss of somethumb.com
* Yoast Doc: https://developer.yoast.com/features/seo-tags/canonical-urls/api/
* Last Tested: Jan 25 2017 using Yoast SEO 6.0 on WordPress 4.9.1
*/
add_filter( 'wpseo_canonical', 'yoast_seo_canonical_change_woocom_shop', 10, 1 );
@obiPlabon
obiPlabon / wp-async-script-loader.php
Created May 15, 2017 11:20
Modify script tag in WordPress to load scripts in async mood or defer mood
<?php
/**
* Add async boolean attribute to script tag
* @param string $tag Default script tag
* @return string Modified script tag
*/
function omm_add_async_loading( $tag ) {
return str_replace( '<script', '<script async', $tag );
}
add_filter( 'script_loader_tag', 'omm_add_async_loading' );
@ollietreend
ollietreend / acf-php-to-json.php
Last active April 22, 2024 11:12
Convert Advanced Custom Fields Pro configuration from PHP to JSON.
<?php
/**
* Plugin Name: Convert ACF PHP to JSON
* Description: Convert Advanced Custom Fields Pro configuration from PHP to JSON.
*/
namespace ConvertAcfPhpToJson;
/**
* Add submenu item under 'Custom Fields'
@apermo
apermo / enqueue_filemtime.php
Last active July 3, 2019 05:09
wrapper for wp_enqueue_style using filemtime
<?php
// has been taken from a class, globals are just a quick and dirty workarround
// This Wrapper is one example for a simple use of cached filemtime version strings, in this case for the parent theme.
// Needs small changes to work for childtheme, javascript, plugins or register
function local_enqueue_style( $handle, $src, $deps = array(), $media = 'all' ) {
wp_enqueue_style( $handle, get_template_directory_uri() . $src, $deps, local_get_version( get_template_directory() . $src ), $media );
}
@amboutwe
amboutwe / yoast_seo_breadcrumb_remove_link.php
Last active April 12, 2024 06:43
These snippets are examples of how you can modify the Yoast SEO breadcrumb visual output. These snippets will not alter the breadcrumb schema output. Please consult the schema documentation to change the breadcrumb schema: https://developer.yoast.com/features/schema/api#to-add-or-remove-graph-pieces