Read array in php?

Fastest way would be something like this: $fruit_id = get_user_meta($user_id, ‘fruit’, true); //returns 1 $display_fruit = some_fruits($fruit_id); //will return ‘Apple’

Printing HTML codes

If I understand your question well, your result shows your <hr> in text form. When you’re using esc_html__( string $text, string $domain = ‘default’ ), the returned output is escaped, it means : ” is replaced with &quot; & is replaced with &amp; < is replaced with &lt; > is replaced with &gt; So your … Read more

Extend Woocommerce Widget Class – WC_Widget_Product_Categories

When calling parent::__construct() from WC_Widget_Product_Departments the constructor of WC_Widget_Product_Categories immediately overwrites the class properties (especially the widget_id), see here at GitHub. So you have to extend WC_Widget to create a new widget and then you can copy anything what you need in your widget from WC_Widget_Product_Categories to WC_Widget_Product_Departments.

deactivating an active plugin using if page

Instead of deactivating the plugin completely (which would deactivate it everywhere on your site) look at the plugin’s code and determine what JS and CSS it is enqueuing. Then in your theme’s functions.php you can dequeue that plugin’s JS/CSS – but only on whatever pages you want to disable the plugin on. So for example, … Read more

Remove Custom Divs from AMP pages

Thanks to Thomas’ answer to my question at StackOverflow – https://stackoverflow.com/questions/53158606/remove-div-with-a-class-without-removing-content Here’s how you can do it on WordPress for AMP. In your theme’s functions.php add the following:- add_action( ‘pre_amp_render_post’, ‘amp_vid_rmv’ ); function amp_vid_rmv() { add_filter( ‘the_content’, ‘amp_vid_div_rmv’ ); } function amp_vid_div_rmv($content) { $content = preg_replace(‘#<div class=”yt”>([\s\S]*?)</div>#’, ‘$1’, $content); return $content; } Please feel free … Read more

3 different times on my WordPress website

In short, the server shows 13h (correct in current time in São Paulo DST), but PHP shows15h and WordPress shows 12h. This is intentional, and needs additional clarification, but to expand you have: The server local time UTC timestamps Localised WP time These needs to be separate, e.g. if I host a Japanese website on … Read more

Unset session variable on page reload / setup but exclude AJAX

Try using wp_doing_ajax() like so: function unset_filter_session() { if ( ! wp_doing_ajax() ) { //Reset sessions on refresh page unset( $_SESSION[‘expenditure_filter’] ); } } UPDATE You can check the answer’s revision for this update part.. UPDATE #2 Sorry, I didn’t realize that you’re loading a page fragment (#content-area) using the jQuery.load() method. Or that you’re … Read more

Underscore – Self hosted fonts

Using @import is the way to go, you can do something like this on your stylesheet: @font-face { font-family: FontName; src: url(public_html/your-site/wp-content/themes/your-theme/fonts/FontName-Regular.ttf); font-weight: normal; } Then you simply use it as usual. p { font-family: FontName; }