As you said per page/post basis, this would work for each post
add_action('wp_head', 'add_link_in_head');
function add_link_in_head()
{
global $post;
if(!empty($post))
{
$alternate = get_post_meta($post->ID, 'alternate', true);
$hreflang = get_post_meta($post->ID, 'hreflang', true);
if(!empty($alternate) && !empty($hreflang))
{
?>
<link rel="alternate" href="https://wordpress.stackexchange.com/questions/110260/<?php echo $alternate; ?>" hreflang="<?php echo $hreflang; ?>" />
<?php
}
}
}
If there is no $alternate and $hreflang then there would be no link.
Related Posts:
- How do I force wp_enqueue_scripts to load at the END of ?
- adding meta data using plugin to top of head
- Adding Plugin Assets to Header
- force enqueue script to be first in order of prominence
- How to set back-end language per user?
- How to keep plugin translations after updates?
- How do I make my plugin load before the headers are output so I can redirect wordpress?
- What is the best page ordering plugin that works well with WPML? [closed]
- How can I modify what is being output in wp_head, whether by a theme or WordPress in general?
- Change Page’s Tag Using functions.php File
- How can I reduce the amount of files loaded/included per plugin?
- Disable qTranslate by post type in admin + disable per page / post ID on front-end [closed]
- Force Plugin to English Translation
- How to load different css file for different pages
- What is the purpose of adding a .po file?
- How to remove/hide action links cluttering under specific plugins’ names
- Qtranslate displays empty categories with get_categories()
- append stylesheet via shortcode
- Change My Basket text in the header of WooCommerce Artificer theme
- How to load plugin before the wordpress jquery?
- How to send “Location” header on plugin form submit event?
- Meteor Slides as header only for homepage and Use featured image of each page as header for respective pages
- Disable wordpress from including jQuery in the head section
- Why load_textdomain work but not load_plugin_textdomain?
- Language Translation is not working?
- How to add inline css/js inside a shortcode
- Strip HTML comments from plugins in header/footer
- Setting up a multilingual wordpress site
- How WordPress knows where to find locale files?
- Prepare plugin options for multi-lingual support
- Popup Cookie WordPress select language and section (Elementor)
- send_headers don’t work on wordpress multisite
- add action wp_head not working
- How to set a custom title per language?
- More than one text-domain is being used because of the included templates for plugins
- how to load the language file in plugin?
- WordPress Redirect Not Working – AJAX Callback Response Not Picked Up
- Headers already sent when I try to add headers via a shortcode
- Create mobile navigation header with settings integration
- How to query the custom fields by language?
- Add javascript to wp_head with call to plugin options?
- WordPress repository forbids me call wp-load.php in non-WordPress file
- CSS from textarea in options page to frontend what to do
- Multi language site [closed]
- Show an image in my header.php
- Headers Content-Security-Policy CSP Major Issue
- How to debug error message: Cannot modify header information
- Custom rewrite rules not working with WPML
- Force language in translate function
- polylang + category/tag custom language link
- wp_footer hook only working on homepage not in other pages
- How WordPress is able to change locale without using setlocale
- Xili language plugin not showing language flag [closed]
- Inject HTML meta tag inside wordpress tag using add_shortcode
- Object method calling for global $wpdb in header.php
- What does making sure “that your theme is WordPress header and footer tag enabled” mean?
- Know which plugin is calling JS in wp_head()?
- Translation plugin to translate another plugins
- My single.php page does not show the related data to the post which is clicked
- Enqueue stylesheet in plugin for wp-login.php
- Get ‘Headers already sent’ error for the plugin I am creating when I try to login
- Custom Login Page — wp_signon Headers Already Sent?
- Content-Security-Policy Headers are there and showing the correct settings, but still getting a refused connection
- echo get_option in header template
- wp_enqueue_style on template_redirect level?
- Plugin translation not working on WordPress.org
- How to manipulate the content within wp_head
- Grab ID from post from plugin and use it to create an object
- Translation to ACF relationship field
- How to handle a WordPress blog with articles in different languages?
- Cannot access WP admin because plugin returns 204
- force jQuery to load in the head
- Language translation on a fresh english installation
- How to enable WPML in BuddyPress Multilingual Plugin in a single website? [closed]
- Edit page header on a custom plugin
- How do i ‘deactivate’ a plugin only on a certain page template?
- how would I include some html in the header section of a wordpress plugin? I get an error
- is_front_page breaks with url parameters generated by a plugin
- How do I fill the Home Description?
- Hook for plugin to insert into entry-meta
- sliding/fading header plugin or approach suggestion
- How to make a slider hearder?
- Translation for a text that is not printed on the screen
- is there a way to preload specific images for desktop users only? (excluding mobile users)
- Identify User Language, Redirect to the corresponding page and Save the chosen language as Cookie
- Prevent WordPress from sending set-cookie http header
- How to implement data residency in my WordPress site
- i create functions.php in plugin files but add_action (‘wp_head’, ‘function_name’) don’t work
- I have English words in Kurdish pages
- Loading a plugin in a post template without using wp_head()
- WPML – Stop language redirection in initial load
- How do I make my site multi language? [closed]
- How to change the width of certain paragraph or header blocks?
- Modifying server’s response to API endpoint
- WPGlobus Multilingual – REST API
- How to fix shifting header after installing speed / cache plugins?
- Cannot modify header information – headers already sent during plugin activation
- Debug in WP backend
- How to overlay a webcomic plugin on top of a header image?
- Set Content-Type header in do_parse_request filter