Got it.
I was already using the Advanced Custom Fields plugin so I just created a custom field called “old_url” with that.
Then I created a function:
function sharingurl () {
if(get_field('old_url') == "")
{
echo untrailingslashit(get_permalink());
} else {
echo get_field('old_url');
}
}
Then I just included <?php sharingurl(); ?>
in the data-href and data-counturl for Facebook and Twitter codes respectively.
Note: Facebook does not like trailing slashes, that’s why I had to remove it from the permalink.
Related Posts:
- Best way to allow manageable social media URLS?
- Displaying additional User Contact Information
- Create additional short URL with custom field and 301 redirect
- custom field with total count of Facebook likes, comments and shares
- Using a custom field value to redirect away from a 404 page
- Redirect users based on custom field
- Masking Affiliate URL using $post_slug after “/go/”
- Multiple URLS per post non-ascii
- How to redirect to home page according to a specific page custom fields value and user name
- Best Way to get facebook share count and update using wp_schedule_event or any other method
- No result update a custom field using wp_schedule_event
- Redirecting to an external URL
- Register author, facebook connect, publish posts from front end
- How to Pull Out Twitter Summary Data in other areas of my template?
- ORDER BY custom field value
- Best way to programmatically remove a category/term from a post
- display specific custom fields
- Add new “Insert Into Post” button with another function
- Can serialized arrays in DB be matched against serialized arrays with meta_query?
- Create a select drop down of available menus
- 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
- Slow meta query with multi meta keys
- Custom Field Multiple Clauses
- Custom field values repeating
- Adding a custom field or metabox to the post-thumbnail widget?
- Send Multiple Custom Field Values Through the URL
- Sort by posts that have a featured image?
- WP_Query display next custom post from today’s date
- Can ordering post list by meta_value cause performance issue?
- $wp_query meta_key naming issue [closed]
- Meta_query and numeric comparison [closed]
- Title and post URL based on custom fields?
- Separate table or usermeta
- Woocommerce with metabox plugin
- using multiple meta_key and meta_value in query_posts
- Multiple relationships in a query
- How Meta Data is different from Custom Fields of POST/PAGE in WordPress
- global function to apply filter to custom field
- How to add a new meta key and assign timestamp to posts
- Print custom field in Query Loop block
- Is there a simpler version of WP Media?
- Order RSS content by an advanced custom field value
- Advanced search by two criteria – sort by location and date (ascending or descending)
- 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
- Collect user custom field in product page woocommerce
- How can I save custom meta to one global value?
- Is there a social members only login plugin for WordPress? [closed]
- get posts where a custom field contains a text
- Displaying a custom field
- meta fields for the whole wordpress site
- 3.8 Media Upload and Custom Meta Box
- How to use media upload on metabox post page without breaking TinyMCE?
- Let’s Create Custom Field Template Documentation
- WordPress Settings API Repeatable fields
- WordPress creates new lines in postmeta table on post update
- How to add custom filed value after in wp post title
- User customising position of WordPress Featured Image
- Insert image into sub-field with update_post_meta
- How to Pass values to Custom Field through PHP in WordPress Posts?
- How to use conditional statement with custom field
- Custom field php
- SQL: Select wordpress posts with given text string and add a custom field to them?
- how to add product subscription field in woocommerce plugin
- How can I change the publish date based on a custom field?
- WP_query multiple custom fields not working
- Is it possible to use get_post_meta() to control HTML?
- Editing custom fields for comments
- Best way to sort estates and query them (for rent? yes/no. contains office space? yes/no)?
- Getting and calculating averge value of custom fields of the same tag
- Only admin should be able to add a particular custom field
- Automatically Add Custom Fields Value as Tags
- Custom date column in user table not sorting correcting
- How to speed up post list slowed by update_meta_cache()?
- Custom Fields displaying in single line
- Custom Field URL + description
- How to save multiple custom user profile fields using repeater JQuery
- Retrive acf fields in publish_post action for wp_mail
- Issue on Creating Checkbox Field On Custom Post type
- Update custom field on page specific to logged in user
- Get link picker custom field to show only if field exists
- Save input form on custom field
- Admin – Search Events by a custom field
- Paying to Access Custom Fields Per Post
- Change path to child of page when uploading image via custom field
- How can I hide my section title if there is no data in custom fields?
- wp_postmeta are updated for only one page
- Meta Box Data added to header redirect
- Form fields based on custom fields
- Post rating using Custom Field
- Inserting custom fields into new-post.php without using the Custom Fields Template plugin?
- woocommerce how in checkout to add my custom field check box, and when i check it hide the shipping adress and add tax 19% [closed]
- How can I attach files without using a plugin?
- Advanced Custom Fields for Header that are Editable from a Page [closed]
- Change Fields of Comments and make them searchable?
- Shortcode not picking up custom field