Skip to content

Instantly share code, notes, and snippets.

@levymetal
levymetal / direct_parent.php
Last active November 27, 2023 04:17
Custom Wordpress function which uses a nav walker to display a list of child pages from a common parent, which can be called from either the parent page (displays children) or any of the child pages (displays siblings). Detailed instructions available on my blog post here: http://christianvarga.com/how-to-get-submenu-items-from-a-wordpress-menu-…
<?php
wp_nav_menu( array(
'menu' => 'Menu Name',
'sub_menu' => true,
'direct_parent' => true
) );
@jlengstorf
jlengstorf / README.md
Created October 8, 2014 20:28
Adds responsive embedding to WordPress oEmbed content.

Responsive Embeds in WordPress

This snippet filters oEmbed output in WordPress (the_content()) to force responsive embeds.

Usage

To use, add the contents of responseive_embeds.less to your site's stylesheet (if you're not using LESS, don't forget to move the iframe,object,embed rule outside of .embed-container and change it to .embed-container iframe,.embed-container object,.embed-container embed).

Then add the responsive_embed() function to your theme's functions.php and insert the add_filter() call in your theme's setup function.

@atomtigerzoo
atomtigerzoo / wordpress-disable-yoast-seo-on-custom-post-type.php
Created March 31, 2016 12:39
Wordpress: Disable Yoast SEO on Custom Post Type
function my_remove_wp_seo_meta_box() {
remove_meta_box('wpseo_meta', YOUR_POST_TYPE_NAME_HERE, 'normal');
}
add_action('add_meta_boxes', 'my_remove_wp_seo_meta_box', 100);
@webdados
webdados / percentage_woocommerce_sale_flash.php
Last active March 22, 2019 08:03
Discount percentage on the WooCommerce "on sale" badge
<?php
add_filter( 'woocommerce_sale_flash', 'percentage_woocommerce_sale_flash', 10, 3 );
function percentage_woocommerce_sale_flash( $html, $post, $product ) {
if ( $html!='' ) {
$perc = round( 100 - ( $product->sale_price * 100 / $product->regular_price ) );
if ( $perc>0 ) $html = '<span class="onsale">-'.$perc.'%</span>';
}
return $html;
}
@marceltt
marceltt / flamingo_cf7_admin_menu_fix.php
Created May 29, 2017 03:46
Better integrate Flamingo admin menu with Contact Form 7
<?php
add_action( 'admin_menu', '_wp_flamingo_humility', 999 );
function _wp_flamingo_humility() {
// Only do if Contact Form 7 is active
if ( !is_plugin_active( 'contact-form-7/wp-contact-form-7.php' ) ) return;
// More descriptive CF7 menu label
$wpcf7_menu = _get_menu_index_by_slug( 'wpcf7' );
@seoagentur-hamburg
seoagentur-hamburg / .htaccess
Last active July 23, 2024 10:22
UPDATE 2024/03: Perfect .htaccess file for highspeed and security. You can use it for every WordPress-Website without problems. Highspeed and Security - testet on hundreds of Websites. If you are using a WordPress Multisite, change the last part of this file.
########################################################################
# OPTIMAL .htaccess FILE FOR SPEED AND SECURITY @Version 2.0.9 - 03/2024
# ----------------------------------------------------------------------
# @Author: Andreas Hecht
# @Author URI: https://seoagentur-hamburg.com
# License: GNU General Public License v2 or later
# License URI: http://www.gnu.org/licenses/gpl-2.0.html
########################################################################
@sabrina-zeidan
sabrina-zeidan / delete_404_attachments.php
Last active February 8, 2024 07:29
Clean Media Library from broken images. Delete attachments which files no longer available and return 404 error [Wordpress]
function delete_404_attachments(){
$attachments = get_posts( array(
'post_type' => 'attachment',
'numberposts' => -1,
'fields' => 'ids'
));
if ($attachments) {
foreach ($attachments as $attachmentID){
$file_url = wp_get_attachment_url( $attachmentID);
$file_headers = @get_headers($file_url);
@glueckpress
glueckpress / wp_rocket__wp_get_attachment_image__lazyload.php
Last active January 6, 2020 08:18
[WordPress][WP Rocket] [deprecated] Wrapper function: Applies WP Rocket’s LazyLoad to wp_get_attachment_image()
<?php
/**
* Wrapper function: Applies WP Rocket’s LazyLoad to wp_get_attachment_image()
*
* @link https://developer.wordpress.org/reference/functions/wp_get_attachment_image/
* @link https://github.com/wp-media/wp-rocket/blob/v2.10.9/inc/front/lazyload.php#L24-L47
*
* @param int $attachment_id (Required) Image attachment ID.
* @param string|array $size (Optional) Image size. Accepts any
* valid image size, or an array of width
@rynaldos-zz
rynaldos-zz / wc-force-tc-new-tab.php
Last active December 14, 2020 17:37
[WooCommerce 3.0+] Disable terms and conditions toggle and force it to open in a new tab
function disable_wc_terms_toggle() {
wp_enqueue_script( 'disable-terms-toggle', '/disable-terms-toggle.js', array( 'wc-checkout', 'jquery' ), null, true );
wp_add_inline_script( 'disable-terms-toggle', "jQuery( document ).ready( function() { jQuery( document.body ).off( 'click', 'a.woocommerce-terms-and-conditions-link' ); } );" );
}
add_action( 'wp_enqueue_scripts', 'disable_wc_terms_toggle', 1000 );
// This snippet can be used alongside https://gist.github.com/rynaldos/0bee7d84a83c5b52096c747c19d088c0 (custom terms and conditions link)