//remove sidebar from section templates in elementor editor
function remove_sidebar_elementor_section_templates( $layout ) {
if ( is_singular( 'elementor_library' ) ) {
$template_type = get_post_meta( get_the_ID(), '_elementor_template_type', true );
if ( 'section' === $template_type ) {
return 'no-sidebar';
}
}
return $layout;
}
add_filter( 'generate_sidebar_layout', 'remove_sidebar_elementor_section_templates' );
categories and tags archive page
// create category and tags page - add a page called Categories for output
add_filter( 'template_include', 'to_category_page_template' );
function to_category_page_template( $template ) {
if ( ! is_page( array( 'categories', 'category' ) ) ) return $template;
add_filter( 'the_content', 'to_render_category_list' );
return $template;
}
function to_render_category_list( $content ) {
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
'number' => 0, // get all, no limit
) );
if ( empty( $categories ) ) return $content;
// Index by term_id for easy lookup
$indexed = array();
foreach ( $categories as $cat ) {
$indexed[ $cat->term_id ] = $cat;
}
// Build tree
$tree = array();
foreach ( $categories as $cat ) {
$tree[ $cat->parent ][] = $cat;
}
$output = '<ul>' . to_render_category_branch( $tree, 0 ) . '</ul>';
// Tags
$tags = get_terms( array(
'taxonomy' => 'post_tag',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
'number' => 0,
) );
if ( ! empty( $tags ) && ! is_wp_error( $tags ) ) {
$output .= '<h2>Tags</h2><ul>';
foreach ( $tags as $tag ) {
$output .= '<li><a href="' . esc_url( get_tag_link( $tag->term_id ) ) . '">' . esc_html( $tag->name ) . '</a>';
if ( ! empty( $tag->description ) ) {
$output .= ' — ' . esc_html( $tag->description );
}
$output .= '</li>';
}
$output .= '</ul>';
}
return $content . $output;
}
function to_render_category_branch( $tree, $parent_id ) {
if ( empty( $tree[ $parent_id ] ) ) return '';
$output = '';
foreach ( $tree[ $parent_id ] as $category ) {
$output .= '<li>';
$output .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->name ) . '</a>';
if ( ! empty( $category->description ) ) {
$output .= ' — ' . esc_html( $category->description );
}
if ( ! empty( $tree[ $category->term_id ] ) ) {
$output .= '<ul>' . to_render_category_branch( $tree, $category->term_id ) . '</ul>';
}
$output .= '</li>';
}
return $output;
}
create page ‘categories’ for it to display on.
// [current_year] auto update year anywhere shortcodes can be used
// [current_year] auto updates for footer
function current_year_shortcode() {
// Get the current year
$current_year = date('Y');
// Return the year inside a span
return '<span class="current-year">' . $current_year . '</span>';
}
add_shortcode('current_year', 'current_year_shortcode');
masonry for wordpress gallery
remove default styles
galleryadd_filter( 'use_default_gallery_style', '__return_false' );masonry for wordpress gallery
css for basic masonry grid
.masonry-grid{margin:auto; column-count:3;column-gap:0;}
.masonry-grid img{max-width:100%;height:auto;border:none !important; padding: 1rem;}
.masonry-grid-item{margin:0;display:inline-block;width:100%;width:100%;margin-top:0;}
note column count
elementor flip card for masonry
enlarges elementor flip card background for masonry layouts.
(() => {
const elementorFlipBoxEls = document.querySelectorAll('.elementor-flip-box')
if (!elementorFlipBoxEls) {
return;
}
// match elementor flip card height setting
const outerHeight = 120;
elementorFlipBoxEls.forEach(flipBox => {
const imgEl = flipBox.querySelector('.elementor-flip-box__image img');
if (!imgEl) {
return;
}
flipBox.style.height = (imgEl.clientHeight + outerHeight) + 'px';
});
})();
gp control footer widths
.footer-widgets .footer-widget-1 {
flex-basis: 40%;
}
.footer-widgets .footer-widget-2 {
flex-basis: 20%;
}
.footer-widgets .footer-widget-3 {
flex-basis:30%;
}
.footer-widgets .footer-widget-4 {
flex-basis: 10%;
}
woo add to cart – display price in button with text according to category
add_filter( 'woocommerce_product_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 ); // Shop and other archives pages
add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 ); // Single product pages
function custom_add_to_cart_price( $button_text, $product ) {
// Check if the product belongs to a specific category (e.g., 'tickets' or 'camping')
$categories = array( 'tickets', 'camping' );
if ( has_term( $categories, 'product_cat', $product->get_id() ) ) {
$product_price = wc_price( wc_get_price_to_display( $product ) );
return strip_tags( $product_price ) . ' Per Person';
} elseif( $product->is_type('variable') ) {
// For variable products
if( ! is_product() ){
$product_price = wc_price( wc_get_price_to_display( $product, array( 'price' => $product->get_variation_price() ) ) );
return $button_text . ' - From ' . strip_tags( $product_price );
}
// Single product pages
else {
return $button_text;
}
} else {
// For all other product types
$product_price = wc_price( wc_get_price_to_display( $product ) );
return strip_tags( $product_price );
}
}
wp cli for hacked sites
rm -rf wp-admin
rm -rf wp-includes
wp core download --force --skip-content
wp core verify-checksums
wp plugin install $(wp plugin list --field=name) --force
wp theme install $(wp theme list --field=name) --force
(run wordfence scan)
wp user list --role=administrator
-remove spammy users
-verify default user role in General
-reset salts
woocommerce button color control
.woocommerce #content input.button.alt:hover, .woocommerce #respond input#submit.alt:hover, .woocommerce a.button.alt:hover, .woocommerce button.button.alt:hover, .woocommerce input.button.alt:hover, .woocommerce-page #content input.button.alt:hover, .woocommerce-page #respond input#submit.alt:hover, .woocommerce-page a.button.alt:hover, .woocommerce-page button.button.alt:hover, .woocommerce-page input.button.alt:hover {
background:#126b11;
background-color:#126b11;
color:white !important;
text-shadow: transparent !important;
box-shadow: none;
border-color:#126b11 !important;
}
.woocommerce #content input.button:hover, .woocommerce #respond input#submit:hover, .woocommerce a.button:hover, .woocommerce button.button:hover, .woocommerce input.button:hover, .woocommerce-page #content input.button:hover, .woocommerce-page #respond input#submit:hover, .woocommerce-page a.button:hover, .woocommerce-page button.button:hover, .woocommerce-page input.button:hover {
background:#126b11;
background-color:#126b11;
color:white !important;
text-shadow: transparent !important;
box-shadow: none;
border-color:#126b11 !important;
}
.woocommerce #content input.button, .woocommerce #respond input#submit, .woocommerce a.button, .woocommerce button.button, .woocommerce input.button, .woocommerce-page #content input.button, .woocommerce-page #respond input#submit, .woocommerce-page a.button, .woocommerce-page button.button, .woocommerce-page input.button {
background: #126b11 !important;
color:white !important;
text-shadow: transparent !important;
border-color:#126b11 !important;
}
.woocommerce #content input.button.alt:hover, .woocommerce #respond input#submit.alt:hover, .woocommerce a.button.alt:hover, .woocommerce button.button.alt:hover, .woocommerce input.button.alt:hover, .woocommerce-page #content input.button.alt:hover, .woocommerce-page #respond input#submit.alt:hover, .woocommerce-page a.button.alt:hover, .woocommerce-page button.button.alt:hover, .woocommerce-page input.button.alt:hover {
background: #126b11 !important;
box-shadow: none;
text-shadow: transparent !important;
color:white !important;
border-color:#126b11;
}
// GeneratePress Search Box Clear
add_filter( 'generate_navigation_search_output', 'tu_remove_search_query' );
function tu_remove_search_query() {
printf( // WPCS: XSS ok, sanitization ok.
'<form method="get" class="search-form navigation-search" action="%1$s">
<input type="search" class="search-field" value="" name="s" title="%2$s" />
</form>',
esc_url( home_url( '/' ) ),
esc_attr_x( 'Search', 'label', 'generatepress' )
);
}