When there is a case – disable unused or system sections and tabs in the admin panel on the left, you can use this code for functions.php with a description in the comments: add_action('admin_menu', 'remove_admin_menu'); function remove_admin_menu() { //remove_menu_page('options-general.php'); // Delete the Settings section remove_menu_page('tools.php'); // Instruments remove_menu_page('users.php'); // Users …
Read More »Wordpress
Automatically text replacement via WordPress function
Someday I will describe the way of creating a multisite for WordPress without database clones and installing plugins. But in this article I am describing a solution when several sites work with the same database and with the same admin panel, and for example, for a subdomain I need to …
Read More »301 redirect to https via WordPress function
I don’t remember why I needed this solution at all, most likely because of infinitive redirects after editing .htaccess file. Below is a redirect option via functions.php: function force_https () { if ( !is_ssl() ) { wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 ); exit(); } } add_action ( 'template_redirect', 'force_https', …
Read More »301 redirect to https for WordPress multisite
The multisite mode in this case is when the main domain and its subdomains work in the same base and the subdomains are a mirror of the main site. If I add a standard 301 redirect to .htaccess then subdomains via http subdomains start redirecting to the main site. This …
Read More »How to hide any blocks when submitting Contact Form 7
Forms can easily be hidden after they’ve been filled out and submitted, because the form gets a class sent when submitted. But there are lot of cases when you need to hide blocks that are placed outside of this form, but which are logically related to the form. If you …
Read More »How to display page/post content in WordPress theme
This case is relevant for cases when you need to display all the content of a particular page in a template. Below is an example PHP include for implementation. <?php $post1 = get_post( 100500 ); $text = $post1->post_content; // post content echo apply_filters('the_content', $text); // output content ?> Instead of …
Read More »How to add widget for WordPress
You must first make an area for displaying the widget through the admin panel, then connect the widget in the template file. For the first part, use the code and place it in the template’s functions.php. register_sidebar(array( 'name' => 'newwidgetblock', // name of the area in admin panel 'id' => …
Read More »Display categories above product list for WooCommerce
To display categories above the list of products, you need to enable this checkbox in the WooCommerce settings, but then the categories will be displayed the same as the products, there will be no separator between categories and products. The following code makes it possible, with the “Show products only” …
Read More »How to allow HTML tags in WordPress category description
By default, the engine cuts out all HTML tags, and with them the content that we write in the description field for WordPress categories. To teach WordPress to understand tags, you need to add the following code to the functions.php file: remove_filter('pre_term_description', 'wp_filter_kses'); remove_filter('pre_term_description', 'wp_kses_data'); By the way, to add …
Read More »ACF not showing up in WooCommerce categories
By default, ACF fields can be displayed like this: <?php the_field('slogan');?> or like this: <?php if( get_field("slogan") ): ?> <?php the_field( "slogan" ); ?> <?php else :?> Custom text if needed. <?php endif; ?> In WooCommerce, this construction does not work, below are correct code example: $queriedObject = get_queried_object(); echo …
Read More »