<?php
global $related_posts_thumbnails;
if ($related_posts_thumbnails->get_html()) { ?>
<div id="relatedproducts">
<h1>Related Products</h1>
<?php get_related_posts_thumbnails() ?>
</div>
<?php } ?>
A quick look at the get_related_posts_thumbnails()
shows that it is simply echoing the HTML returned from the get_html()
method of the $related_posts_thumbnails
object. By checking the returned HTML first, you can make sure it is not an empty string (or any falsy value).
Note for the plugin author: picking the name get_related_posts_thumbnails()
and making it echo the output is quite unintuitive. Other WordPress functions use the get_
prefix for functions that return data, and leave it out to echo it. For example: get_bloginfo('url')
vs bloginfo('url')
.
Related Posts:
- Remove “Category:”, “Tag:”, “Author:” from the_archive_title
- get_template_directory_uri pointing to parent theme not child theme
- Get the ID of the page a menu item links to?
- Add container to nav_menu sub menu
- Link to user’s profile settings page?
- One Child Functions.php for Multiple Child Themes
- Shared functions.php across multiple WordPress websites
- How to restrict actions and filters “properly” by conditions
- Extending auth_cookie_expiration based on user role
- Disabling pingback and trackback notifications
- AJAX handler throws 400 (Bad request) – why?
- How to get comments with mixed status using get_comments?
- How to display the_post_thumbnail if a post has one or otherwise display the first image in a post?
- Return only top-level navigation items from a menu using wp_get_nav_menu_items
- How to add .htaccess code through a function?
- Conditional tag is_page with a custom post type
- Is it possible to be more page/post specific with admin_enqueue_script?
- radio button is checked but display not check
- Theme options WP Editor
- Enqueue styles after a plugin
- Properly applying nonce to a form using AJAX
- What is the $context in remove_meta_box function?
- Conditions for Users and Visitors
- add_filter priority problem
- wp_enqueue JavaScript in child-theme (ReferenceError) using Search & Go
- How can I enable uploading excel files?
- Super simple shortcode not working
- Using “Read More” link with custom excerpt
- Enqueue scripts not working with if is page conditional tag in functions.php
- what function can I use to automatically output og tags per page/post?
- Why does the ‘wp_nav_menu’ function work only until a menu is created?
- Add error message on password protected page ONLY when password introduced was incorrect
- Twentyten Child Theme: header images display messed up in admin panel
- Get Current Post ID in functions php, meta query filter
- Where to start learning more about wordpress templates [closed]
- What did I do wrong in my functions code, that will not change the “Get New Password” text to “Send It”?
- Jquery implementation not working on page reload
- Parse error after modifying the template menu [closed]
- Reuse variable in hook callback
- PHP mixed with some JS code to update WordPress theme settings
- What does this code do? (Injected code hacked)
- Pass parameter to hooked function using custom page template
- the_posts_pagination() function returns missing page numbering on some blog pages
- Get array of metakey in all posts
- How do I hook into the container of wp_nav_menu?
- Remove links from the_content when using filters wp_trim_excerpt
- content editor format style tags
- Custom Behavior when Adding New Custom Post Type in Dashboard
- Does size of a theme’s functions.php file matter?
- How to add custom user avatar in wordpress
- custom functions in function file delete automatically daily
- Enable right click on WordPress site
- Init action and refresh page after form action
- This code works, but the way I integrated it is breaking the media uploader. How can I integrate it properly?
- Delay a function, any function!
- How to overwrite template.php file
- Fill empty custom field with other custom field
- Limit number of characters in different excerpts
- Creating a custom wordpress widget and stopping js from running twice(once in active widget once in widget selector)?
- How do I find the code executed when wp_head() is called?
- Editor cannot access Theme Options
- How to avoid saving empty data to sql while using add_meta_box
- How to assign php file(template) to several pages with same prefix page name/slug
- Is this a backup door?
- Include widget file in functions.php of child theme
- Need help making a short code work
- How to fix Function create_function() is deprecated in / themes
- Block all plug-ins from initiating redirection upon activation?
- Is there a function for setting a password to a post?
- WordPress functions.php conditional include another functions file
- How to display my comment count in the wordpress admin bar?
- reWrite wp-content url to point on my cdn
- Modifying a WordPress Plugin
- Last updated posts shortcode in functions.php
- How to reference different css (bootstrap) stylesheets for the header and body of a page?
- sort title descending with title with number
- I have an fatal error on my funcyions.php
- Get post_author email for Zapier Integration
- Author social media aren’t shown on the page
- If click on Save/Publish change Post Status to Pending Review instead Publish
- Remove the delete link from pages without a plugin
- Custom download page
- HowTo: Add wrapper to columns shortcode?
- Get title from IDs in a string
- uninstall a theme programmaticlly
- Could you please correct the code is_admin()
- get_comments not working properly after WordPress v4.4 update
- Update add_image_size
- What add_action reference should I be using or should I use do_action?
- Allow the access over wp-login.php
- Create input select image URL?
- Including one page with WordPress functions into another
- Dynamically Generating User Meta Field
- Limit length of headline in Editor
- Check if there is an post to be published in future
- Unhook the comment form in Buddypress
- Why my wp_enqueue_script doesnt work on some page?
- Trying to get this function to show below the content
- is_preview() always return false
- How do i set global variable in a function in wordpress functions.php