Try this:
// Filter wp_nav_menu() to add additional links and other output
add_filter('wp_nav_menu_items','add_pdf_to_menu', 10, 2);
function add_pdf_to_menu( $items, $args ) {
if( $args->theme_location == 'extra-menu') {
$pdf = get_post_meta( get_the_ID(), 'mcf_uppsagning-pdf', true );
if ( $pdf )
$items .= '<li><a href="' . wp_get_attachment_url( $pdf ) . '">Uppsägning</a></li>';
}
return $items;
}
Essentially because you’re in the context of the single page get_the_ID() will return the id for the post/page you’re on. If that doesn’t work try using get_queried_object_id() in place of get_the_ID().
EDIT:
changed the above code to return the attachment permalink.
Related Posts:
- How to add a custom field in the advanced menu properties?
- Adding a custom field to the site identity menu
- Add meta data to the menu
- Create a select drop down of available menus
- Dynamic User State & City selection
- Creating a custom menu/widget area
- Nav Menu – Add class based on meta keys
- Add image to menu item with ACF
- Declaring in variables [closed]
- How to add a custom field in the advanced menu properties?
- Walker class for sub-menu with ACF fields
- Show Custom field value instead of title in WP Menu
- How to make menu country specific?
- How to check custom fields from functions.php
- Override edit_custom_walker.php to conditionally show input depending on menu position
- How to use page metadata while using wp_list_pages()?
- Add custom fields to specific menus
- Add CSS class to posts with certain meta key
- Is it safe to store a user setting you don’t want the user to ever modify as a user option?
- Can I count the number of users matching a value in a multiple value key?
- extend Meta Box / Document Panel
- Add multiple images to a page sidebar
- getEntityRecord without knowing the post type
- How to delete custom field “suggestions” from dropdown list
- How to load php file for specific page in admin?
- How to set default metaboxes on user creation?
- Metabox nonce PHP notice
- ajax jquery update custom field meta value front end
- How to break meta values into different items and avoid duplicates?
- ajax delete value from custom field array
- Add input field to ‘Pages > Edit Page’ through functions.php
- How can I query on the year part of a complete date in a custom field?
- WordPress Custom Field Should be Unique. Is it possible?
- How to display Meta Field Value?
- Upcoming Event: How do I sort database by custom date field, but ignore past dates?
- What is the cleanest way to extract custom variables from a post
- Add source URL from Feed WordPress (Syndication) plugin to a custom field in post editor
- Auto populate a meta box field from another meta box field when publish or save
- Order query by meta_value with multiple custom fields
- Display only past events on that page using Visual Composer Grid Bulider
- user Profile meta value as custom field
- Remove Body Classes
- Use WPbakery for own custom field [closed]
- Add custom field to all posts in specific post_type
- Change the sort order for posts to include custom field
- Button inside Custom Meta Box triggering the Update Button
- Define a post’s title and slug from Custom Fields
- How can you include custom post meta in search without calling each key?
- Custom wysiwyg editor doesn’t execute shortcodes?
- How to hide a div based on contents of custom field
- Hook after meta created
- What is the largest value you can store in a custom field (as meta data for a post)?
- Where does this field get its value?
- ORDER BY custom field value out of where clause
- Get all the posts where meta field with multiple choice has several values checked
- Warn user that data may be lost for custom pages
- List custom field values in alphabetical order without repetition
- Can’t query by meta_key
- Display MP3 as media using an URL from a custom field
- WordPress custom fields feature is missing in my installation
- Print Posts if Custom Field Value Date equal or greater than Today Date
- Update post meta custom field using block editor
- If I update WordPress my custom data will be deleted from the wp_users table?
- Save all custom field data into one “master” custom field
- Convert all dates stored in custom field
- Plugin or shortcode for ISBN number?
- HM CMB: Role Select
- WP-eComerce Advance Meta Tag data in descending order [closed]
- Custom Query Fields – Altering Meta Value
- Problem with writting correctly a query posts args in WordPress
- Add a field to just ONE page
- get_post_custom_values problem, please help
- How to parse a huge list of users using a CRON function?
- How To Save Data From Remote APIs To ACF?
- comments_where Hook
- add_comment_meta not working properly
- how to enable custom fields in the Gutenberg post editor
- Missing Custom Fields
- Is there any way to make a custom field for a post only if the author is a certain user?
- Use WP_Meta_Query To List All Values For 1 Key On Page Template
- Check for meta data before it is published
- Stop truncation of shortcodes in custom text fields?
- Save custom post data outside of default post form
- Sort custom fields in admin by last field added
- Call the latest posts from a custom field group to be displayed on front-page
- Wrap this custom field with hyperlink link
- custom select field populated by allocated post category
- Metabox nonce not allowing update
- Basics: adding template tag to display custom fields in the post
- Create widget that filters posts on current page based on entered value
- Undefined Variable (Displaying image via custom field)
- I would like to display different text on different pages
- Cannot get tags working from a WPAlchemy metabox with wp_editor()
- get adjacent post by meta key and meta value
- Adding custom field to an array
- unlink() doesn’t delete the uploaded file
- file upload user profile
- Tons of Custom Fields [closed]
- How to make donation button dynamic on chariti theme [closed]
- ACF in radio button cf7