Your code works to create links, and WordPress should make a valiant effort to find the correct post, but it doesn’t get complete permalinks. To do that you will need to query the database for the post and construct a permalink if one is found.
function transform_pseudo_anchor_wpse_101201($match) {
global $wpdb;
if (isset($match[1])) {
$name = sanitize_title_with_dashes($match[1]);
$p = new WP_Query(
array(
'name'=>$name,
'post_type' => 'post',
'posts_per_page' => 1,
'suppress_filters' => true,
'ignore_sticky_posts' => true
)
);
if (!empty($p->posts[0])) {
$link = get_permalink($p->posts[0]);
return '(link: <a href="'.$link.'" title="'.$match[1].'">'.$match[1].'</a>)';
} else {
return 'nada';
}
}
}
Related Posts:
- Menu Link Redirect Based on Username or User ID
- How to display a public profile page for registered users with custom slug?
- How to use relative links on my pages?
- How can I store page ID in a post instead of other selected permalink?
- WordPress Permalink changes to question mark (?) in URL
- Redirect old permalinks to new permalinks
- How to get a page url by a page id?
- Why does WP not use relative links when linking pages?
- Social Media Links on homepage – within posts/post loop
- Change website URL without breaking links or images? WP 3.3
- Navigation link to specific user page
- Remove Custom Taxonomy Slug from Permalink
- Redirect user if it’s not logged in
- echo post-permalink without http and www
- I copied my site to another site but all links point to old site
- Best way to add internal link in widget
- Confusion about how a URL is being parsed
- Woocommerce Product Attribute Permalink doesn’t work?
- Automatically append ID to at the end of specific URLs
- why some permalinks adding characters/ruining links
- How to change old permalink?
- Title attributes on Permalinks for posts and products
- Migrated from Windows to Linux. Any bulk methods for fixing case sensitivity?
- How to eliminate permalink prefix in WordPress Multisite
- Get the url of a page template without using the page slug and ID
- How to generate a list of all urls
- Rewriting single post url; add_rewrite_rule problem?
- Advanced author permalinks
- WordPress 3.1 .htaccess contents keep dissappearing?
- Change Buddypress Admin Profile Page Permalink
- How do I reclaim either deleted pages or their permalinks?
- Format HTTP links
- Edit permalink for certain pages
- cannot link a external url, present page url acting as parent url
- Can WP give a value a post ID?
- how to find duplicated permalinks?
- I’ve removed my /author/ slug but it clashes with new and existing pages. Any fixes?
- Moved site, Old links in pages still pointing to old host
- How to use page jumps to top of banner and page title?
- How can I link to the author’s page
- How to remove the link of an image on WP 4.2
- replacing post ID by custom post name in url
- Create custom links for excerpts with php dynamically
- How can I see a list of all pages my WordPress site has generated?
- Auto Changing Text Case
- Post with no tag permalink problem
- How to make different urls for some tags pages
- A dash can replace a period in a link, how to fix it
- My WP homepage works, but the other pages don’t when accessing from out side of my network
- Can I link to content dynamically from a page to a new page?
- Propper way to set anchor and url param
- Structure of post types for TV Shows and episodes
- Find internal links to post
- rebuilding/ rewriting a url to make it SEO friendly
- Remove link function from oembed image or video
- Author permalink
- Add a product attribute to permalink in WooCommerce
- How to change dynamic link to relevant post
- Difference and usage of uri (e.g. get_directory_uri) and absolute path (e.g. get_directory)
- Possible to hide parts of the slug from get_template_directory_uri and bloginfo(‘template_directory’)
- After changing permalink settings, everything works fine except for the two most recent posts
- My posts section for logged in user
- Latin character conversion
- Pretty links for PHP pages above WP /blog directory?
- Permalink / sub-template issue
- What is the issue with our links? It creates a loop
- wp_get_attachment_url not working
- URL to an image in a post is changing when permalink is set to custom. Can I avoid this?
- Redirect Loops Problems
- Make all internal links relative, or otherwise make a website accessible from multiple domains
- WordPress Version 6.6 facing “This block has encountered an error and cannot be previewed.” which edit text on page with link
- Unable to access a folder that does not belong to WordPress installation
- After post URL change also automatically change references in posts to that new URL?
- Page linking issue
- Changing permalink won’t redirect to new version of page
- Yoast SEO canonical URL gets pointed to the homepage
- Append slug of each blog post with a hash based on a custom field
- Removing /wp in Permalink URL of subdomain led to inaccessibility to WP Dashboard
- Custom permalinks for post formats
- Accidentally Changed Permalink Structure
- How to get selected variation from URL?
- taxonomies ACF WordPress
- Where does the redirect from shortlink to permalink happen?
- how to ensure url uses post_name and not query post id?
- When accessing all pages except the homepage I get Nothing Found
- Custom permalink structure for posts in specific category not working
- Not able to change WordPress Permalink Settings
- My posts images and links are not correct when I publish my home page
- changing the default structure of category & tag permalinks
- Creating WordPress pages with post name as slug
- I want to change my permalink structure
- Permalink issue with new blog posts > getting 301 redirect
- All WP pages direct to 404 or index.php
- I have two different parent menus in my main menu. the first parent menu with a dropdown is called “services” and the second dropdown is called
- How to remove parent slugs from child pages permalinks?
- How to add .html extension only to pages without child pages?
- Permalinks and redirects
- WP Category Archive /page/2+ pagination issue 404
- No route was found that is identical to the URL and request method
- Category url; have it only answer to 1 category