Skip to content

Instantly share code, notes, and snippets.

@theposudka
theposudka / add noindex meta tag to filtered pages with only one product.php
Last active April 2, 2025 16:53
Add noindex meta tag to filtered pages with only one product
// Add noindex meta tag to filtered pages with only one product
add_action('wp_head', 'override_robots_meta_for_filtered_pages', 1); // Priority set to 1 to override Rank Math
function override_robots_meta_for_filtered_pages() {
if( class_exists( 'FilterEverything\Filter\Container' ) && flrt_is_filter_request() ) {
global $wp_query;
// Check if there's only one product on the filtered page
if ( $wp_query->found_posts == 1 ) {
// Remove the existing robots meta tag output by SEO plugins like Rank Math
remove_action('rank_math/head', 'RankMath\\Frontend\\Robots::robots_meta');
echo '<meta name="robots" content="noindex, follow"/>';
@theposudka
theposudka / make '?add-to-cart=' element noindex.php
Last active April 2, 2025 16:50
make '?add-to-cart=' woocommerce URL element noindex
add_filter('rank_math/frontend/robots', function ($robots) {
$url = home_url($_SERVER['REQUEST_URI']);
if ((strpos($url, '?add_to_wishlist=') !== false) || (strpos($url, '?add-to-cart=') !== false)) {
$robots["index"] = 'noindex';
$robots["follow"] = 'follow';
}
return $robots;
});
@theposudka
theposudka / Hide free shipping text on Woocommerce Cart page.php
Last active April 2, 2025 16:51
Hide free shipping text on Woocommerce Cart page
function hide_free_shipping_text() {
?>
<style>
.wc-block-components-totals-item__value strong,
.wc-block-components-shipping-rates-control__package__description--free {
display: none;
}
</style>
<script type="text/javascript">
jQuery(document).ready(function($) {
@theposudka
theposudka / gist:85ac93ebaa02a8c628dfa3a6f38ad835
Last active April 2, 2025 16:51
Add 'Price' before woocommerce product price
function bd_rrp_price_html( $price, $product ) {
$return_string = 'Ціна: ' . $price;
return $return_string;
}
add_filter( 'woocommerce_get_price_html', 'bd_rrp_price_html', 100, 2 );
@theposudka
theposudka / Rename "home" in breadcrumb.php
Last active April 2, 2025 16:51
Rename "home" in Woocommerce breadcrumb - WP code snippet
/**
* Rename "home" in breadcrumb
*/
add_filter( 'woocommerce_breadcrumb_defaults', 'wcc_change_breadcrumb_home_text' );
function wcc_change_breadcrumb_home_text( $defaults ) {
// Change the breadcrumb home text from 'Home' to 'Інтернет‐магазин посуду theposudka'
$defaults['home'] = 'Інтернет‐магазин посуду theposudka';
return $defaults;
}
@theposudka
theposudka / Change add to cart text on product archives page.php
Last active April 2, 2025 16:52
Change add to cart text on product archives page - WP code snippet
// Change add to cart text on product archives page
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_add_to_cart_button_text_archives' );
function woocommerce_add_to_cart_button_text_archives() {
return __( 'КУПИТИ', 'woocommerce' );
}
@theposudka
theposudka / Change add to cart text.php
Last active April 2, 2025 16:52
Change add to cart text on single product page - WP Code snippet
// Change add to cart text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_add_to_cart_button_text_single' );
function woocommerce_add_to_cart_button_text_single() {
return __( 'КУПИТИ', 'woocommerce' );
}