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
- How can I avoid re-inventing the Custom Fields wheel in my Plugin’s Metabox?
- Using wordpress post data as input for google visualisations
- Does wordpress have something like content-type?
- Order Posts by Closest Numeric Values
- How to get and edit custom fields if in Quick Edit
- Order posts by custom field and if custom field is empty return remaining posts
- Create custom field on post draft or publish?
- Adding a prefix to a post title
- copy attachments to another post type and change attachment url
- Cannot edit post meta fields with rest API
- Only display custom field if it there is a value inside
- Add a post meta key and value only if it does not exist on the post
- Custom field values repeating
- Function to change meta value in database for each post
- Sorting posts by multiple values, combined
- WP_Meta_Query causing long-running MySQL queries
- trim custom field text value and show (…)
- Duplicate posts being displayed when querying Custom Fields
- How to validate custom field on lost password form before the user id field?
- Json api does not return all metadata
- Use custom field as a variable
- ACF: How to get the full field name (meta_key) by a field key?
- Woocommerce: Custom fields and email shortcodes, ec_custom_field
- Tweak Meta for Post to work it for Pages also
- Adding an editable field to template?
- Transferring author information from a custom field to a proper author
- How to select posts from multiple categories and metavalues?
- modify wordpress caption shortcode
- UPDATE on SELECT results. A SQL query to swap Author with Meta Box value
- Alter main archive, to show posts with meta as last
- Add microdata from schema.org [closed]
- Displaying multiple URLs as custom field values
- Linking Custom Fields to Database Records
- Stop sending email everytime I updates my post
- Best way to store everyday post views?
- Display list of terms having the same custom field value
- How to display custom field in woocommerce email orders? [closed]
- Custom meta is not being saved
- How to use media upload on metabox post page without breaking TinyMCE?
- Branch made by several custom values
- How can I activate custom fields checkbox in pages?
- Can I save post meta programatically without setting metaboxes?
- Insert image into sub-field with update_post_meta
- Show custom field on attachment page?
- WP Insert post with post_thumbnail
- Custom meta boxes in RSS feed
- How to pass custom field value to shortcode?
- custom comment_form fields not displaying
- WP_Query () using taxonomy, custom post types
- Ordering by ‘Title’ OR ‘Custom Field’
- How can I add/update post meta in a admin menu page?
- pull all posts’ meta key values from current category only
- Is it possible to use get_post_meta() to control HTML?
- Order by custom date field
- Group Posts By Custom Meta Value: Date
- Custom Field: how to save array of multiple key-values in WordPress
- How can I detect user’s timezone?
- ACF field group not showing in page
- Filter post style attribute
- Update some (not all) post titles with custom field values before running the Loop
- Arrays in custom fields or is there a better way?
- Custom field in media library not saving, selected() function not adding “selected” to select list input type
- Setting user permissions per post
- Weird custom fields data lost
- Showing the post only when there is title, thumbnail and the content in Custom Fields
- Show Custom Taxonomy as Headline for related posts
- WooCommerce 3 get custom variation on process order [closed]
- Custom field group on page
- Output Custom Field value to shortcode
- Update custom table on metabox POST
- display custom media folders to wordpress media popup
- display Flexible Fields from options
- change attachment custom field onChange event
- Custom Meta Boxes and Fields for WordPress: Change directory upload based on user-edit page
- How to filter post using custom feild value in shortest and longest duration?
- Get custom field from other post in carousel
- show custom field content in jquery tabs
- Create citation and url in post using 3 custom fields with conditions for each field… So close!
- Advenced custom fields auto fill problem
- Show only first image of multiple image field
- Custom Fields after update to WordPress 6
- Archive for custom fields?