How to Customize the Admin Sidebar Menu in WordPress Multisite Network by changing the backend code of the wp-admin code files?

Firstly, you should absolutely not modify core files. Ever. Any changes you make to core files can and will be overwritten any time WordPress updates. There are umpteen ways in which WP has been written to allow you to change its behaviour without hacking on core files: hooks, filters, APIs. Use those instead. In this … Read more

Add up all numbers from a WordPress query [closed]

.= does string concatention, eg, ‘hello ‘ . ‘world’ gets you hello world. To add, use + instead of .: // Set a default for $numbers. $numbers = 0; $query = new WP_Query($args); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $post_id = get_the_ID(); $party_size = get_field(‘reservation_party_size’, $post_id); $numbers += intval( $party_size ); } } return … Read more

Is it possible to remove the “Shop” title from the WooCommerce catalogue? [closed]

CSS METHOD To hide with CSS this should do the trick for you. Add the following to the theme’s or child theme’s style.css, or to the Customizer’s CSS section: body.post-type-archive-product .bs-card-box.page-entry-title { display: none; } What we’re doing here is targeting the product archive template file that WooCommerce uses to dynamically create that page. By … Read more

Hide ID for WordPress User Role Subscriber

You can use the body_class filter and the wp_get_current_user() function to add the current user’s role to the <body> element, and then hide your elements with that (untested): add_filter( ‘body_class’, static function ( $classes ) { $user = wp_get_current_user(); $roles = $user->roles; if ( ! is_array( $roles ) ) { $roles = array( ‘subscriber’ ); … Read more

Is there a way to get a path to the theme directory without the server name?

Yes get_template_directory: get_template_directory(): string Retrieves template directory path for the active theme. Returns an absolute server path (eg: /home/user/public_html/wp-content/themes/my_theme), not a URI. In the case a child theme is being used, the absolute path to the parent theme directory will be returned. Use get_stylesheet_directory() to get the absolute path to the child theme directory. To … Read more

Custom page template from plugin does not work with pre-installed themes in WordPress 6.6.1

Newer themes including Twenty Twenty Four use block themes/Full Site Editing. This means all the templates are created with HTML and theme.json, not using PHP templates at all anymore. You can read up on bloc themes, and see ways to create a “hybrid theme” which uses both PHP and HTML, here – https://fullsiteediting.com/courses/full-site-editing-for-theme-developers/

Function wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder

There are 2 places that could have issues: Your first wpdb::prepare() here: // Prepare and execute the count query $count_query = $wpdb->prepare( $count_sql, …$query_params ); The initial value you set for $count_sql is “SELECT COUNT(*) FROM $table_name WHERE 1=1”, and if $filters doesn’t have any key matching your switch, the value of $count_sql will remain … Read more

PHP Deprecated function Optional parameter $function

At your function declaration you need to set the required parameters first, the optional second, because you couldn’t skip $function if $page has to be given: function add_meta_box($id, $title, $page, $function = ”, $context=”advanced”, $priority = ‘default’): void { require_once(ABSPATH . ‘wp-admin/includes/template.php’); add_meta_box($id, $title, array(&$this, $function == ” ? $id : $function), $page, $context, $priority); … Read more