Show or hide custom menu widget in side bar conditionally

I have been trying and searching to accomplish this. I have the "custom menu" widgets "Members Area", "Admin Area" in side bar, assigned menus to them. Fine, they display. I want to show "Admin Area" widget only when the current user is admin. I believe it has something to do with adding a filter to "sidebars_widgets". Honestly, i do not have a clue to target the "Admin Area" widget. How do I handle this ?
Category: Web

WordPress 6.0 class-wp-widget.php fatal errors in PHP 8.1.6

/wp-includes/class-wp-widget.php gives me an error for one blog, but not the other, and both have the same version of class-wp-widget.php which makes no sense to me. PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function WP_Widget::__construct(), 0 passed in /home/www/stackexchange.com/wp-includes/class-wp-widget-factory.php on line 61 and at least 2 expected in /home/www/stackexchange.com/wp-includes/class-wp-widget.php:162 Reading the code, it appears class-wp-widget.php is the root of the problem, but I could be wrong. My other (working) blog on the same server has this same file …
Category: Web

wp_editor in widget breaks after save (no buttons and visual tab broken)

My goal is to get wp_editor working in a simple widget which the admin can use to add text content on an admin options page. Here we go in wp-admin/widgets.php everything looks sooo good right. When we try to save... Oh no..... Buttons are gone and the Visual tab no longer works When I look at the HTML it appears as though after updating TinyMCE just decides it doesn't need to load any buttons... Any ideas? Edit: here's the source …
Category: Web

How to get widget content in Wordpress based on it's ID?

I need to parse widget content based on it's ID. But a widget works like a function that pulls data based on it's arguments, right? So when I pull the widget data, I can only get it's arguments, not the actual output. How can I parse the widget content based on it's ID? Example code: // Update widget rounds automatically function automatize_games_rounds($instance, $widget, $args){ // Check if there is a caption if (isset($instance['caption']) && !empty($instance['caption'])) { // If there is, …
Category: Web

How to get sidebar widgets in leftsidebar template

I have created a custom sidebar widgets using below code : register_sidebar(array( 'id' => 'sidebar-widget-1', 'name' => 'Sidebar Widget 1', 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', )); and it is showing in Appearance -> Widgets and it is also showing content on frontend using dynamic_sidebar('Sidebar Widget 1'). But I want to get content of this register_sidebar by using its id into a variable. How to get sidebar content by using its id?
Category: Web

How to show a feed that requires user/pass within a sidebar widget?

I'm trying to do something and I don't seem to yield any successful results when searching neither at wordpress.org forums nor here. I would like to extend the standard RSS widget so that I can set an user/password for HTTP Authentication in order to fetch the feed items. If there is an existing solution that I'm missing and already provides this feature, any pointer will be much appreciated. Thanks.
Category: Web

Full width layout for custom post type pages

I'm trying to remove a widget area called 'Primary' from a certain page on a site. This is the function where I manage the sidebars: //ADD CATEGORIES IN SIDEBAR OF SINGLE POST TYPE add_action( 'genesis_sidebar', 'add_mysite_sidebar' ); function add_mysite_sidebar() { if( get_post_type() == 'post' ){ dynamic_sidebar( 'News Categories' ); } else if( get_post_type() == 'events' ){ dynamic_sidebar( 'Event Categories' ); } else if( get_post_type() == 'documentlibrary' ){ dynamic_sidebar( 'Document Categories' ); } else if( get_post_type() == 'bp_members' ){ include(members_sidebar.php); unregister_sidebar( …
Category: Web

How to add image uploader to a custom widget?

I'v built a custom widget that will show some sport scores. Scores are added trough custom post. When i open new custom post(scores) i enter their team names, score, scores. Now i want to add an option to show team logos next to the team name. In the last couple of days every tutorial here and elsewhere i could find didnt worked. I have no idea why, as i am newbie with all this. With many of it, upload button …
Category: Web

Table of contents (TOC) plugin is not showing header tag

I made a post template using meta box(custom field). If I put data into metabox, the template part (contents with h2, h3, p) shows up at the bottom of post (not on post edit page). However, every TOC plugins use "revisions" to check if there is h2 or h3 like this code. public function widget( $args, $instance ) { global $ht_kb_toc_tools, $wp_query; if( ! is_singular() ) return; if ( ! isset( $wp_query ) ) { return; } if( is_a($ht_kb_toc_tools, 'HT_KB_TOC_Tools') …
Category: Web

isSavingPost() for widgets

I want to get the block ID of my widgets (e.g. #block-1, which is displayed on the frontend after saving a widget) on the widgets screen in the backend. What I try to achieve is to display the ID of the widget in the toolbar so that you can easily copy it. I currently use a custom API endpoint to receive the ID but it will trigger a request on every render (I already debounced it, but am searching for …
Category: Web

how to get value of a select box in custom widget wordpress

I am trying to make a custom widget. My codes are as follows: class techno_widget extends WP_Widget { function __construct() { parent::__construct( 'techno_widget', __('Recent Full Post', 'techno_widget_domain'), array( 'description' => __( 'A full post will be appeared on Sidebar', 'techno_widget_domain' ), ) ); } public function widget( $args, $instance ) { $title = apply_filters( 'widget_title', $instance['title'] ); $blog-title = $instance['blog-title']; echo $args['before_widget']; if ( ! empty( $title ) ) echo $args['before_title'] . $title . $args['after_title']; echo $instance['blog-title']; echo $args['after_widget']; } …
Category: Web

Console errors in 6.0-RC1 Widget screen

Sine 6.0-RC1 the following console error appears on the block widgets screen, on Firefox: Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. NotEmpty@https://betatest.opajaap.nl/wp-includes/js/dist/widgets.js?ver=80e98954519d1dad7a91a2248dbc2cc9:1118:7 div Edit@https://betatest.opajaap.nl/wp-includes/js/dist/widgets.js?ver=80e98954519d1dad7a91a2248dbc2cc9:1051:7 Edit@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:12908:7 withToolbarControls</<@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:12263:7 withInspectorControl</<@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:12475:26 custom_class_name_withInspectorControl</<@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:12582:35 withBlockControls</<@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:36311:33 withDuotoneControls</<@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:36678:32 withInspectorControls</<@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:36924:7 queryTopInspectorControls</<@https://betatest.opajaap.nl/wp-includes/js/dist/block-library.js?ver=c0a77efe7e30b81595292ba7bdec3d8f:35990:7 withMoveToWidgetAreaToolbarItem</<@https://betatest.opajaap.nl/wp-includes/js/dist/edit-widgets.js?ver=6d1c3f1e5fbca4e69781de58b399425e:2327:7 FilteredComponentRenderer@https://betatest.opajaap.nl/wp-includes/js/dist/components.js?ver=704ed65a1b8b5c891184113526f15ce4:73834:9BlockListBlock@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:18670:7 withDataAlign</<@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:12314:7 withBorderColorPaletteStyles</<@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:32258:7 withColorPaletteStyles</<@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:34086:7 withFontSizeInlineStyles</<@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:35312:31 withElementsStyles</<@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:36324:112 withDuotoneStyles</<@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:36722:29 withLayoutStyles</<@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:36944:7 FilteredComponentRenderer@https://betatest.opajaap.nl/wp-includes/js/dist/components.js?ver=704ed65a1b8b5c891184113526f15ce4:73834:9 ifCondition/</<@https://betatest.opajaap.nl/wp-includes/js/dist/compose.js?ver=da94d523b115836ddbf0b3b774ddd94a:2201:8 withDispatch/</<@https://betatest.opajaap.nl/wp-includes/js/dist/data.js?ver=38ad563aa39c8f314fe6f6e430d81a69:4316:46 withSelect/</<@https://betatest.opajaap.nl/wp-includes/js/dist/data.js?ver=38ad563aa39c8f314fe6f6e430d81a69:4160:31 @https://betatest.opajaap.nl/wp-includes/js/dist/compose.js?ver=da94d523b115836ddbf0b3b774ddd94a:2236:12 Items@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:31568:7 BlockListItems BlockContextProvider@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:12861:7 UncontrolledInnerBlocks@https://betatest.opajaap.nl/wp-includes/js/dist/block-editor.js?ver=e2ef0c6eb29e06ea9efedec924f1b9a8:31358:7 …
Category: Web

Defer Code in Widgets - Page Speed

How to UP Page Speed With Widget Defer? Is there a way to defer a widget in the footer? I have an external API in a footer widget which is slowing down my page. It is not needed until the page is loaded. The caching plugin I use (W3 Total Cache) gives me the option to defer other scripts, but not scripts directly coded into the widget. What is the best way to manually defer custom code API that is …
Category: Web

Script widget works only in admin view but not in Public

Script Widget bug in WordPress. The embed widget from Funda was working before, clueless why it suddenly stopped working. In Public view, it's not working. Preview mode while logged in to WordPress shows the correct page. Actually, the same embedded script from FUNDA is working on this page https://www.homecrew.nl/rent-out/. But the issue is with this page. The script isn’t working on this page https://www.homecrew.nl/reviews-recensies-beoordelingen-klanten-engels/. The Editor & method of placing the script is the same. I cleared the cache etc. …
Category: Web

Custom Widget WP_Query problem

I have everything working on my widget except the results! I created a taxonomy called country names that we use for several custom post types. I created this widget to display tour guides (CPT) from the selected country. The widget is working properly on the back end, but I am getting no results on the front end (ie. "No listing found"). I have echoed the $instance to the screen and it is correct, so my args or query must be …
Category: Web

Display widget outside sidebar?

I want to display a widget outside the sidebar, but I can't get my code to work. The theme name is radius-primary-sidebar and my widget id is text-20 (according to the html in the admin page. See image #1). I've tried using the_widget("radius-primary-sidebar", "widget-id=text-20"), but that didn't return anything. What I'm I doing wrong? I'm using wordpress 3.5.2. From /wp-admin/widgets.php in the admin panel.
Category: Web

How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?

I added the following to my functions.php: add_action('pre_get_posts', 'keyl_get_emp_posts'); function keyl_get_emp_posts($query) { if ($query->is_main_query()) $query->set('post_type', 'employee'); } and so far it's effectively filtering out the search results. The default widgets Recent Posts and Recent Comments aren't budging, though. What gives?
Category: Web

How to add multiple footer widgets?

I am new to WordPress. I would am currently using the Twenty Seventeen Theme. I would like to add multiple Footer Widgets, however WordPress is limiting me to only two. Is it possible to add a few more footer widgets? If so how to do I do that? I have spent two days searching the internet for an answer to avail. I would prefer PHP or CSS file modification answers. Thank you in advance...
Category: Web

how to remove wrapping widget

I want to remove the default wrapping ul and li class="page_item page-item-2" on the widget this is my code register_sidebar([ "id" => "footer1", "name" => __("Footer 1"), "description" => __("A short description of the footer."), 'before_widget' => '<ul>', 'after_widget' => '</ul>', 'before_title' => ' <li><span class="footer-links-title">', 'after_title' => '</span></li>', ]); I want the result like this: <ul> <li><span class="footer-links-title">Information</span></li> <li><i class="fa fa-chevron-circle-right"></i> <a href="" class="links">Terms & Conditions</a></li> </ul> when I try it the result is like this: <ul> <li> <span …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.