$post->post_parent
returns 0 when there’s no parent associated. You need to check if the value is greater than 0.
<?php global $post;
if ( $post->post_parent > 0 ) { ?>
<a href="<?php echo get_permalink( $post->post_parent ); ?>" >
<?php echo get_the_title( $post->post_parent ); ?>
</a> <Br><?php echo get_permalink( $post->post_parent ); ?>
<?php } ?>
Also, check your permalink settings URL base.
Related Posts:
- After server migration only the homepage works
- How do I add /blog/ as a prefix to permalink structure for blog posts, tag pages, etc.?
- What is the best permalink structure for SEO?
- Custom post type permalink endpoint
- How do I set a custom base URL for standard posts?
- Permalink with sub-sub-category and post name
- Remove index.php in permalink structure on IIS server
- WooCommerce return 404 on category pages
- URL rewrite based on a custom field value
- why does anchor name add a slash to url?
- the_title() and the_permalink() won’t work on AJAX calls
- What is the best practice to check for pretty permalinks?
- How to create a permalink structure for posts in a specific category
- How to map permalinks with accented letters to sanitized slugs?
- Using two permalinks for one post
- How to use first tag in permalinks
- Changing URL from /%postname%/%post_id to /%category%/%postname%/%post_id%
- Put post ID on the custom post type URL
- How to change the permalink structure of a master page?
- Permalinks without subdirectories
- Remove the Parent category from the permalink but leave the child category
- shortcode to output multiple images urls from media library id
- Apostrophe in permalink results in page not found
- How to generate random numeric slugs for a custom post type?
- WP Site in subdirectory Joomla! Site – Permalinks not working
- How to get full content including template HTML
- I copied my site to another site but all links point to old site
- WordPress on Ubuntu 12.10: permalinks problem
- How to protect htaccess so it can’t be overwritten?
- How to link to current post in WordPress?
- wordpress api using rest_route for other pages
- Infinite redirects after changing the permalink of a page
- Remove custom taxonomy base from URL
- How to have extra permalink for posts
- How to get post object on blog template
- How to make /search/ without parameters not return a 404?
- WordPress auto generates small medium and large of an image on upload, how can we guess their links?
- Get post text (by its URL) from database dump
- Plain to postname permalinks not working
- Permalinks dropping after 3-4 weeks with no changes in theme or plugins
- WordPress Sub domain
- How can i have a custom post type with more slugs for each post?
- Google webmaster duplicate url issue with /page/01 /page/400
- URL rewriting: removing the site’s basename for a specific category
- Migrated from Windows to Linux. Any bulk methods for fixing case sensitivity?
- Redirect all posts permalinks from “.html” to “/”
- Unable to get /%postname%/ permalinks working, 404 on all links
- Permalink structure between 2 custom post types and a taxonomy
- How to use all tags in post permalinks
- Stop Images Linking to Themselves?
- Resolve 404 on posts without category
- Remove parent page from url
- Remove “attachment/” from the URL of attachment pages
- Inserting a string in the middle of page’s permalink?
- 404 on internal pages, in all sites in my local server
- how to alter permalink in wordpress?
- Adding User Info to Permalink of User pages – is it neccessary?
- Pagination using paginate_links
- add_rewrite_rule – Page Slug from “/foo-bar/” to “/foo/bar/”
- Permalink will not change – it wants to have -2 slug [duplicate]
- Permalinks 404 after Subdirectory to Root Migration
- Access or edit custom generated permalinks with WP_Rewrite
- Add custom query vars to pretty permalinks
- Custom permalink structure only saves with index.php inserted
- Two custom taxonomies in permalink structure
- What is the simplest way to create a redirect
- the_permalink() not working
- All in One Seo and Permalinks
- Already have htaccess but permalink settings not working. Getting 404
- Add .html permalink to post if specific category
- What permalinks do I use in the redirection
- WP Multisite Subdirectory Custom Permalinks 404
- WordPress’ «post name» setting broken
- Whole site’s pagination not working after rewriting product permalink
- Convert $ _GET to permalink
- Permalink blog page (only) not working
- Link to a page before launch
- My WP homepage works, but the other pages don’t when accessing from out side of my network
- CPT links error: each one links to next one further along in the list
- Disable “similar permalink” redirect [duplicate]
- Logging in to installation in subdirectory renders broken dashboard (no CSS, broken links)
- Woocommerce product page 404 not found
- WordPress and NGINX – permalinks are not working with ending slash
- Get value from URL with different types of parameters
- a way to support totally different url structure
- Page permalink redirects to home page
- I have to specifiy port otherwise the website doesnt work
- Permalinks for thumbs with get_post_gallery
- Permalinks/Pretty links aren’t working on my site
- How to hide slug numbers with htaccess
- Once redirected by Rewrite rules, how can WordPress know the page?
- Redirect Pretty Permalinks to Ugly Permalinks
- Slug adding -2 even though the other posts with the same name is in a separate post type
- Generate multiple tag query URLs
- Change permalink in wp-property
- Search results highlight breaks my read more link
- How to get WordPress to NOT alter the permalink structure when adding a static page?
- Custom Permalinks Structure with particular word
- Permalinks, how to show them in post
- Image not Showing (Can see image in inspect element)