Depending on how the page’s query and loop are constructed, when you access the post object from the sidebar or footer, you sometimes get the last post in the loop rather than the page itself.
You can ensure you’re getting the original (page) object by running wp_reset_query() from inside your widget (before you access the post object or run any functions that assume the current post as their target).
One caveat here: make sure there’s nothing after your widget that would be affected by this post reset.
Related Posts:
- Shortcode from a widget is wrapped in unwanted element
- How can I whitelist only specific shortcodes for processing in text widgets?
- When to use which plugin output method?
- Custom shortcode in widget forced to top of widget
- Shortcode in Text Widget not working
- Inserting shortcode [stream /] into a Text widget
- check for shortcode in post/pages AND widgets AND template files
- the_widget() and widget’s ID
- How the widget can be run by shortcode
- How do i display the built-in gallery inside a widget?
- Shortcode displays always first. Once again
- Create a widget to use shortcode?
- Check if the current shortcode is being used in a widget
- Display custom widget, added as a shortcode in the correct place
- Allow shortcode for custom widget
- Shortcode not working in widget
- How to add urls in html widget in a gravity form? [closed]
- call widget from within shortcode
- Transform php shortcode into a widget [duplicate]
- Can I use widgets & shortcode if I need to return an array?
- How do I get shortcode, widget and template tag CSS to load in the head only as required? [duplicate]
- Loading scripts only if a particular shortcode or widget is present
- Encode text string being appended as query to URL [closed]
- How to use is_active_widget?
- Get page IDs based on which template they are using?
- Add filter to blogroll widget
- Widget Options Not saving
- Embed iframe or html page into dashboard widget
- Loop through widgets in sidebar
- Where to find the source code of a widget?
- How to add author details in the post sidebar?
- Woocommerce Product Category Widget – hide categories that have no products in stock [closed]
- Hide widget to non-logged in users without plugin (functions.php) [closed]
- how to extend a WP_widget twice
- How to add css classes to widgets using functions.php?
- How to add Shortcode (font awesome) in widget title?
- duplicate sidebar
- How to check if searchform.php is being included as widget?
- Is it possible to enqueue a script from a widget method (of extended WP_Widget object)?
- wp_count_posts, wp_count_terms and wp_count_comments for specific user?
- what is option_name on database that store the information of current initiate widget in frontend sidebar?
- Widget – Store and update data
- passing variables inside a widget add_action
- Making the default “Latest Posts” WordPress Widget Show Thumbnails
- Text Widget Links Not Working
- When adding a widget, what kind of widget should I used to add images and text and styling?
- Add description to custom text widget and display the 5 recent post titles
- Add individual tag to widget title in sidebar
- How to allow your custom widget as block in gutemberg editor
- How to save widget fields generated from an array?
- Remove image height/width attributes from Image Widget
- How to display an RSS feed widget inside a page?
- Newbie: Help with Vertical Spacing on Footer Widget [closed]
- Copy Widget Settings because of changed IDs
- How to call widget by widget’s id?
- Why is my custom widget breaking another one?
- Show a widget as a sidebar fallback
- disbale default widgets on theme activation
- in_widget_form detect sidebar id
- function WP_Widget::widget() must be over-ridden in a sub-class. when create new Widget
- change widget to display excerpt instead of content
- How to move top widget to the left – Responsive Theme WordPress
- How do I deactivate widgets by name?
- How to register a widget when saving a post?
- Can’t display custom widget
- Need to convert image url to a Base_64 data url with wordpress function..
- Using more widget in main page cause slow loading WordPress? [closed]
- add_action not working within widget() of WP_Wdiget
- Add links widget to self-hosted blog?
- How to add Ajax to the default widget calendar to support next/previous months loading?
- prevent custom widget file names from showing in Appearance > Editor
- Add a widget to a static front page
- Last Update time in widget
- Adding dashboard widgets to show – custom post type stats, information from other plugins
- Upgraded to 3.3, My Widgets Disappeared
- How to use register_sidebar’s ‘before_widget’ unique id generator into its other parameters like ‘before_title’?
- Dynamic Bootstrap Carousel ID per widget on same page
- Tabs widget from Elementor is not showing the content in it to users. But at admin side it is working fine
- URLs for (MultiSite) link images are always relative
- Widget title showing below widget
- Shortcode generated widget to appear on same line as heading text and button
- Need to Echo A Url path to show on a wordpress page
- Title not Emptying in a Widget
- Get a list of all Widgets registered in WordPress admin widgets-area
- How to implement widgets error output with data validation?
- how to get value of a select box in custom widget wordpress
- Using the_widget Multiple Times
- Conditionally Load a Script if a Certain Widget is Shown on a Page
- Does current page contain widget or sidebar
- Nonce and widget
- How to give a File Upload option in wordpress Widget backend?
- Pass widget variable to external function
- Adding Widgets to Reactor Theme (based on Foundation 4)
- Widget area does not show any contents for specific users in admin interface. How to go about debugging?
- Creating an custom admin page for editing widgets
- Show or hide a widget from pages
- Author Link in Recent Posts Widget
- How to find the exact widget details
- Widgets are not showing after moving domain
- Keeping shortcode-generated widget and theme element in one line [closed]