Skip to content

Instantly share code, notes, and snippets.

View samholguin's full-sized avatar

Sam Holguin samholguin

View GitHub Profile
@samholguin
samholguin / wc-add-admin-page-endpoint.php
Created April 10, 2018 21:42
WordPress - add admin page endpoint
/**
* Account menu items.
*
* @param arr $items
*
* @return arr
*/
function swd_account_menu_items($items)
{
$items['profile'] = 'Profile';
@samholguin
samholguin / htaccess-rules
Last active August 29, 2015 14:24
.htaccess Rules
Negative lookahead based rule:
RewriteRule ^products/(?!certain-category).*$ http://shop.newurl.co.uk/ [NC,L,R=301]
(?!certain-category) is a negative lookahead that will fail the match if certain-category comes right after /products/ in URL.
RedirectMatch 301 /products(.*) http://shop.sunwise.co.uk/
Redirect 301 /shop http://shop.sunwise.co.uk
@samholguin
samholguin / wp-process-remove_unwanted_shortcode_tags
Created June 27, 2015 18:11
WordPress - Remove empty <p> tags and <br> tags from shortcodes
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
function wpse_wpautop_nobr( $content ) {
return wpautop( $content, false );
}
add_filter( 'the_content', 'remove_empty_p', 20, 1 );
function remove_empty_p( $content ){
// clean up p tags around block elements
@samholguin
samholguin / wp-filter-add_custom_image_sizes
Last active August 29, 2015 14:22
WordPress - Filter [ image_size_names_choose ] - Adding Custom Images Sizes to the WordPress Media Library
/**
* Adding Custom Images Sizes to the WordPress Media Library
*
* @access public
* @param array $sizes
* @return array
*/
function shgist_add_image_sizes($sizes) {
$addsizes = array(
"new-size" => __( "New Size")
@samholguin
samholguin / wp-action-modify_the_post_object
Last active August 29, 2015 14:22
WordPress - Action [ the_post ] - Modify the WordPress post object
/**
* Modify the WordPress post object
*
* @param obj $post_object
* @return obj
*/
function shgist_my_the_post_action( $post_object ) {
// modify post object here
}
add_action( 'the_post', 'shgist_my_the_post_action' );
@samholguin
samholguin / wp-filter-modify_nav_menu_objects
Last active August 29, 2015 14:22
WordPress - Filter [ wp_nav_menu_objects ] - Modify WordPress nav menu objects
/**
* Modify WordPress nav menu objects
*
* @param array $menu_items
* @return array
*/
function shgist_nav_menu_item_classes( $menu_items ) {
foreach ( (array) $menu_items as $key => $menu_item ) {
// Work on menu item objects
@samholguin
samholguin / wp-func-get_child_pages
Last active August 29, 2015 14:22
WordPress - Function - Get child pages
/**
* Get child pages
*
* @access public
* @return array
*/
function shgist_get_child_pages() {
global $post;
$args = array(