Globals aren’t passed into functions. You have to declare them.
Change this:
function test() {
return $post->ID; //or echo $post->ID;
}
…to this:
function test() {
global $post;
return $post->ID; //or echo $post->ID;
}
Related Posts:
- Get the blog page URL set in Options
- Using classes instead of global functions in functions.php
- What is the difference between wp_register_sidebar_widget and register_widget?
- Change admin bar to default:off
- Create “File-less” Page Template in Functions.php
- When to use esc_url, esc_html, esc_attr, and friends?
- How to edit bbPress template files – WordPress + BuddyPress + bbPress? [closed]
- How to change post thumbnail title and alt attributes to post title?
- Why might $input (Settings API) be coming through empty?
- Override default cropping in WordPress [duplicate]
- Get password when user registers and save it sha1 into database
- How do I “unhook” / de-register jQuery so that it’s not called as part of wp_footer();?
- Removing the default sidebar from admin panel
- Merging PHP download script into `functions.php`
- Is there an error in get_the_tag_list()?
- Returning Variables back into a template
- Allow users to add custom functions to wordpress theme
- Change date number to another language/script?
- How to add custom template tag in wordpress theme?
- Nesting Functions within Functions
- Is using eval() ok in this scenario
- Custom php page in WordPress theme?
- Can’t access WordPress functions in file called via Ajax?
- How can I customize wp_footer, where is the code that controls what this function does?
- How to list all images in uploads directory except those that are attached to any post
- More than one meta field in a single meta box?
- Is there a theme function for is_password_protected()?
- how do you create an admin interface in plugin for your theme
- How to determine which custom header image is being shown
- Toggle Sidebar Display
- Unhook jQuery from WooCommerce via `functions.php`? [closed]
- trying to use wp_handle_upload with ajax
- Should I use include or load_template for including shortcodes, plugins and so on?
- Check if home.php and set home.php as page_on_front
- Should I use add_filter for functions in function.php of the theme?
- after renaming my wp-content folder, how do I upgrade my wordpress version?
- Pass variable to hook. Its possible?
- Theme Customizer not loading JS for live preview
- Remove “You are using WordPress 3.2.1” from Right Now Dashboard Widget
- Replace function in a child theme
- Custom theme, contact form 7 & fast secure form doesn’t work
- Change the “Default Avatar” admin option via functions.php
- Replace single_template filter with what for default posts?
- JQuery undefined and Stylesheet loads in bottom along with js files
- How to call the_time current?
- Add content after get_header
- Can’t change theme name
- How to set default values for edit_post_link() in my theme?
- How to make excerpt image be full size instead of thumbnail?
- enqueue script if page is not equal to
- apply_filters to featured image
- Mamp pro permalink issues. Pages keep reverting to index.php
- loading custom.js file after jquery is loaded
- Creating custom function in wordpress to return data from database
- Getting URL of Resized Image
- Adding a new layout for genesis
- themeforce (happytables framework) implementation
- Is wp_is_mobile() effective?
- Display Menu Name using wp_nav_menu
- What questions do you ask when asked to give an estimate on theme development?
- How to remove dashicons.min.css from frontend?
- Hide certain pages / posts on wp-admin, show custom filter
- Dynamically change feature image in customiser
- use add_action(‘wp_head’) in a widget for generating dynamic CSS styles
- Problem with registering menus – What to do when other solutions aren’t working?
- Front End Post Submit Form
- Displaying wp menus by name without using theme locations
- Do I really need the div class entry?
- How to Take Ownership of a Theme
- WordPress with broken paging page 3
- Location of theme options page menu icon
- Is it possible to edit the styling of the admin panel from within a custom theme?
- Can’t login unless twentyfifteen theme is active
- the_excerpt(); tag not working
- How to show custom meta_key in each li of menu
- Can I add multiple arrays within add_theme_support( ‘colors’ )?
- Customizer – loading settings/controls/sections/panels based on a id/page id
- Where to place template files?
- [&hellip appearing instead of […]
- Getting author URL outside the loop
- Is there Photo Categories?
- Why still output /wp-content/themes/twentynineteen?
- add shortcode support in customizer
- add jquery file if a certain page is included
- Exclude subcategory from wp_query
- Archives and Categories in Custom Menu
- Custom search template is showing 404 when adding query string
- How to render block editor in wp-admin custom pages programmatically
- Fetch data from database with dropdown selected option
- How do I keep my iframes responsive and scaled to fit their container?
- Let user publish posts on community page
- How to perform str_replace on the results of wp_list_pages
- How would I get this to work – send to post from thick box
- Show category and description
- How can I demonstrate themes well?
- How to update my own theme?
- trying to figure out how to use more that one image upload in the same section in theme customizer
- WordPress custom jquery not found
- How to using custom DB tables
- Replacing static code in a template file with a sidebar and widgets?