The task in short: you need to make the delivery date + 5 days from the current date in PHP, with the output of the month in the genitive case in RU. But you can ignore custom edits for that language version. The method with date( ‘d FY’ ); is …
Read More »PHP
Css styles for WordPress admin in functions.php
If you need to add individual styles, and they are only a couple of lines, you can add them directly to functions.php: add_action('admin_head', 'webinp_style'); function webinp_style() { print '<style> tr[data-slug="to-top"] {display: none !important;} </style>'; } Between <style> and <style> you need to write your own CSS styles.
Read More »Different content for More Lang language versions in a template using a shortcode
I like More Lang plugin because there are no duplicate pages and posts for other language versions in the admin panel. But I had a problem – for the banners on the home page (which are embedded in the theme) there was no way to change the texts dynamically, depending …
Read More »How to add 301 redirect to https for Yii2 without .htaccess
I’ve tested different redirect options for .htaccess, but sites keep giving “redirected you too many times” error. Here is the working code to solve the problem. In the file /config/web.php you need to find: 'bootstrap' => [ 'log', 'app\components\Bootstrap', ], and place below: 'on beforeRequest' => function ($event) { if(!Yii::$app->request->isSecureConnection){ …
Read More »How to randomly display multiple words using PHP
Without long preliminary explanations, I am posting the working code here. <?php $input = array("test1", "test2", "test3", "test4", "test5", "test6", "test7", "test8", "test9", "test10"); $rand_keys = array_rand($input, 5); echo $input[$rand_keys[0]] . ", "; echo $input[$rand_keys[1]] . ", "; echo $input[$rand_keys[2]] . ", "; echo $input[$rand_keys[3]] . ", "; echo $input[$rand_keys[4]] …
Read More »301 redirect in PHP
There are different reasons for different engines to add 301 redirects not in .htaccess. For DLE, PHP redirects are the only way to avoid looking at dynamic garbage generated in links. Examples implementation in PHP: if ( getenv('REQUEST_URI') == '/page-before-redirect/' ) { header( "HTTP/1.1 301 Moved Permanently" ); header( "Location: …
Read More »Fatal error: Allowed memory size when executing a script or importing a dump into a database
The Fatal error: Allowed memory size error indicates that there is not enough time and limits on the server to complete the process that you started. Here is the actual block for inserting into .htaccess, with which the limits from php.ini will be increased, after that you can import a …
Read More »If the link contains another domain/subdomain
The task is relevant if hosting subdomains refer to the root of the main site, or if several domains are registered as aliases to each other. If you need to write noindex/nofollow etc., you can simply write a condition in index/header section: <?php $host = $_SERVER['HTTP_HOST']; if($host == "old.domain.com" or …
Read More »How to change text for Add to Cart button for Woocommerce
This task can be solved by editing the translation files of your theme. But you can use a hook that allows you to rename the “Add to Cart” button faster. In the file functions.php add the following code: add_filter( 'woocommerce_product_single_add_to_cart_text', 'tb_woo_custom_cart_button_text' ); add_filter( 'woocommerce_product_add_to_cart_text', 'tb_woo_custom_cart_button_text' ); function tb_woo_custom_cart_button_text() { return …
Read More »Include the file and display the value if it is specified in this file
This method was created for SEO edits on the Bitrix site (generated h1 values were entered in the file and displayed in the template). Today I returned to this solution for canonical edits, here is the code and description: <?php include($_SERVER['DOCUMENT_ROOT']."/seo.php"); if(isset($seoh1) AND $seoh1!='') {echo $seoh1;} else {echo $heading_title;} ?> …
Read More »