How to add Shortcode (font awesome) in widget title?

I checked your code in my install. It works, except that you made a typo (missing backslash): [icon]cog[/icon] Few notes: You must make sure to enqueue the Font Awsesome stylesheet. You must close the shortcode, like: [icon]cog[/icon] Remember to escape the class name with esc_attr(). Another shortcode idea: [fa icon=”cog”]

Bolding specific word(s)/parts of widget title

This bolds the first words (or entire word, if only one) of my widget titles: add_filter( ‘widget_title’, function ( $title ) { return preg_replace(“/^(.+?)( |$)/”, “<strong>$0</strong>”, $title, 1); }, 10, 1); Breaking down the regex pattern, we have: ^ is the start of the line (.+?) is anything between our next group (in this context, … Read more

Find if widget block is active

One could e.g. get the widget blocks data with: $widget_blocks = get_option( ‘widget_block’ ); and then loop through the array and run has_block() on the contant part, e.g. like (untested): function is_active_block_widget_wpse( $blockname ) $widget_blocks = get_option( ‘widget_block’ ); foreach( (array) $widget_blocks as $widget_block ) { if ( ! empty( $widget_block[‘content’] ) && has_block( $blockname, … Read more

Schedule cron event from widget

wp_schedule_event takes a hook as parameter, not a function. Try: wp_schedule_event(time(), ‘daily’, ‘my_daily_event’); add_action(‘my_daily_event’, array(&$this, ‘my_widget_cron’)); if ( !wp_next_scheduled( ‘my_daily_event’ ) ) { wp_schedule_event(time(), ‘hourly’, ‘my_daily_event’) } If you remove the widget from the sidebar, the cron will still continue to run. You can run the following code (outside of the widget class) to clear … Read more

Creating your own widgets: using cache?

take a look at WordPress Transients API which offers a simple and standardized way of storing cached data in the database temporarily by giving it a custom name and a timeframe after which it will expire and be deleted. The transients API is very similar to the Options API but with the added feature of … Read more

How to limit wp_get_archives to show months for the X years only

If using “regular” query in theme file (sidebar.php for example), this code will help do the trick: <?php wp_get_archives(‘type=monthly&limit=12’); ?> The above (and below) will only show the last 12 months. However if using a widget, then add this code to your functions.php file: function my_limit_archives( $args ) { $args[‘limit’] = 12; return $args; } … Read more