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
- Change media item permalink
- Is the permalink structure /%post_id%/%postname% faster or slower than just /%postname%?
- Assigning a role to a specific custom post type (and ignoring other post types)
- WordPress Permalinks %postname% for RSS2 Feed URL
- wordpress permalinks tweeks
- Getting links to work the same on development and production
- Setting up two separate blogs while using WordPress as a CMS
- Custom theme navigation
- get permalink and append it
- Moving local wordpress page to a real server subdomain broke my permalinks?
- next_posts_link URL does not include name of custom post type
- WordPress disallows changing page to a specific permalink
- 404 when going to /blog
- WordPress keeps giving me the wrong permalink
- how to make a custom field readonly or disabled by user role?
- How to disable permalinks to some custom post content?
- Permalinks problem woocommerce no separating slash between categories
- Change url of page according to my requirements in wordpress
- Open login logo URL in new tab
- MySQL-inserted custom taxonomy term lead to 404, flush rewrites doesn’t help
- Some custom post types did not return an object
- Posts containing a specific tag and a category in one permalink
- Custom permalink question
- How to search for images and get it’s link?
- Post redirected to page with same name but DIFFERENT permalink
- permalink to single page
- How do you intercept the page requests in WordPress?
- Pretty Permalink for Search Queries Not Working
- How to update permalink on the fly?
- Custom rewrites for pages and categories