When is is_admin() available?

When is is_admin() available? Pretty much everywhere. The only example I can think of where it wouldn’t be available, is super early in files such as wp-config.php, and some drop-ins. But by the time an mu-plugin, a theme, or a plugin is loaded it’s present. Now, it would work to wrap the inner workings of … Read more

Show Specific Footer Widget for Specific Pages

There are several ways you can achieve this: A. Use CSS to hide and show widgets based on which page you are on. This is fine as a workaround, but it isn’t really solving your problem, especially if you have lots of pages/widgets. B. Call a different widget area in your template file with conditional … Read more

wp_embed_register_handler to embed html files

Fixing the regex pattern To match an url of the type: https://coptic-treasures.com/ {Some string with a mix of a-z letters and hyphen}/{Some number}.html like this example: https://coptic-treasures.com/html-test-filed/02.html you can try this kind of pattern: ‘#https://coptic-treasures.com/([a-z-]+)/([0-9]+)\.html$#i’ and then you have to update the iframe output accordingly: … src=”https://coptic-treasures.com/%1$s/%2$s.html” … with the corresponding matches. Demo Here’s a … Read more

Include a Gutenberg Block in a PHP file

You need to use Custom Post Type for blocks. What it does is you can register your own post template with predefined blocks in it. Which I believe is what you are looking for. Here’s example of that – function myplugin_register_book_post_type() { $args = array( ‘public’ => true, ‘label’ => ‘Books’, ‘show_in_rest’ => true, ‘template’ … Read more

Add to checkout total lines an additional line below shipping in WooCommerce

You could use the Fee API that will create in totals line below shipping optionsCode goes in function.php file of your active child theme (or active theme). Tested and works., based on the shipping total x 1.5 (+50%), where you can include your conditional logic, like: add_action( ‘woocommerce_cart_calculate_fees’,’custom_pack_fee’, 10 , 1 ); function custom_pack_fee( $cart … Read more

Add a custom text field to WooCommerce admin product data “Variations”

Overriding core files is really something to avoid absolutely for many reasons. To add a custom field to product variations options prices and save the value on save, use this: // Admin: Add custom field in product variations options pricing add_action( ‘woocommerce_variation_options_pricing’, ‘add_variation_custom_option_pricing’, 10, 3 ); function add_variation_custom_option_pricing( $loop, $variation_data, $variation ){ woocommerce_wp_text_input( array( ‘id’ … Read more

How to display product cropped thumbnail (150×150) for WooCommerce product categories

To include the product category thumbnail (125 × 125 px) in your product category items (buttons), use the following: $product_cats = get_terms([ ‘taxonomy’ => ‘product_cat’, ‘hide_empty’ => true, ‘parent’ => 0, ]); foreach ( $product_cats as $key => $parent_term ) { $thumb_id = get_woocommerce_term_meta( $parent_term->term_id, ‘thumbnail_id’, true ); $size=”thumbnail”; $image = wp_get_attachment_image_src($thumb_id, $size); printf( ‘<button … Read more

How can I default to all WordPress roles when parameter is not included in shortcode?

Try this: function profile_counts($atts) { $atts = shortcode_atts( array( ‘metakey’ => ”, ‘metavalue’ => ”, ‘userrole’ => ”, ), $atts ); $user_ids = get_users( array( ‘meta_key’ => $atts[‘metakey’], ‘meta_value’ => $atts[‘metavalue’], ‘role__in’ => wp_parse_list( $atts[‘userrole’] ), ‘fields’ => ‘ID’, // retrieve just the IDs ‘count_total’ => false, // no need for FOUND_ROWS() ) ); return … Read more

How to Add a Link to the Drop-Down User Menu in the Admin Bar?

You want to use $wp_admin_bar->add_node( $args ). Below is a tested working example. function wpse_add_toolbar_edit($wp_admin_bar) { $wp_admin_bar->add_node( array( ‘id’ => ‘mylink’, ‘title’ => ‘My New Link’, ‘href’ => ‘mailto:[email protected]’, ‘parent’ => ‘user-actions’ ) ); } add_action(‘admin_bar_menu’, ‘wpse_add_toolbar_edit’, 999); Note: The parent param adds the link to an existing ID. If you need to find the … Read more