I think what you mean is do an onclick event.
So, you can do this with JavaScript. Create your link as per usual <a id=“myCustomLink” href=“#” onclick=“MyFunction();return false;”>huh! I’m a link!</a>
And now some script
<script>
function MyFunction() {
//Make it do whatever here! For example:
document.getElementById("demo").innerHTML = "Hello World";
}
</script>
Rerun false; will prevent the browser directing to the link… unless you want it to? If so then just remove this and add a link in-place of the # after the href.
However! A much cleaner way of doing this would be to do it as JQuery and attach the ID as an onclick handler. Like so:
$(‘#myLink’).click(function(){ MyFunction(); return false; });
Hope this helps!
Related Posts:
- Fetch All Posts (Including Those Using a Custom Post Type) With WordPress API
- importing third party json feed as custom post type [closed]
- Full-Ajax Theme: parseJSON error while building a JSON object from a WordPress custom template
- Recommended way to remove WP REST API returned data for custom post
- How to add/edit advanced custom fields on custom post type’s WordPress REST API?
- Using wp_localize_script to get data from cpt and pass it to maplace-js locations
- Getting a GET error in console – 404 not found for wp-json
- Run shortcode in custom script in wp_head if post type is CPT ‘Jobs’
- Importing JSON feed giving Notice: Array to string conversion error
- ForEach Loop iterates only once when inserting product variations
- Create/populate Custom Posts ACF fields from external JSON file
- Publishing failed. The response is not a valid JSON response
- How to display “META” array in register_taxonomy
- Populating Custom Fields from live JSON
- WordPress API only returning HTML
- Convert Custom Post Data to Javascript Array for Autocomplete
- Appointment booking system in WordPress
- retrieving external api data and updating existing custom post
- Not getting posts of custom post types
- Custom post type pages return 404 page?
- Filter date from post meta when date is in string format
- Properly flush rewrite rules on plugin activation
- Send a conditional email notification when a custom field value changes in Post Type
- Check for a specific taxonomy of a custom post type
- Add custom CSS class to custom post type
- Dynamic bootstrap tabs with post_title doesn’t display the_content
- Custom post type – list posts based on meta_key and display them divided by CPT taxonomy category
- Custom taxonomy page returns 404
- portfolio custom type tags support
- Saving fields in a drop-down in WordPress
- Why does wp_update_post causes white screen?
- Targeting custom post type via functions.php doesn’t work
- WordPress Custom Post Type – Rewrite Query
- Custom post type suddenly stoped working after WordPress 5 update
- Custom post type to lead to single post type instead of shortcode modal
- Filter posts of custom post type by meta key in (List All Section)
- is_main_query() never called on WP 4.4
- Change post type depending on shortcode
- Redirect User From Registration Page To CPT (profile page) with custom url
- Set Default Option Value as Blank for Meta Box
- Query Posts, order by meta value
- Admin: Get all user for Custom Role
- List of a specific Custom Post Type in Custom Template
- Custom post type meta box empty after save
- How to add a class to meta boxes (to customize them in CSS)?
- custom post types missing ADD NEW
- Custom post type menu button color
- display custom portfolio tags
- adding page types in menu
- wp3 custom post types rss
- Drop down list with posts within the “add new” page
- Custom taxonomy not saving correctly
- How to have multiple archive pages?
- Custom post type permalink structure to include the taxonomy
- Custom Post Type Rewrite Throws Headers Sent Errors
- How can I sort the order of multiple custom field values in a custom post type?
- Extending post by email
- Trying to create a custom post type, post type box doesn’t show up?
- How to add comments to my custom post type but hide it from default WordPress Comments section?
- I want to rewrite the URL of a specific post with a specific custom field to easily analyze in Google Analytics
- Custom taxonomy does not display in custom post loop
- Create if else for post types in WP_Query ‘post__in’ values
- CPT email notification including only new value custom fields
- Return multiples taxonomies with wp_get_object_terms
- Button per line in Custom Post Types
- Custom post type rewrite slug translate?
- Change display of product price on product show page only
- How to add CSS class field in Custom Taxonomy?
- CPTUI rewrite disable when no post in CPTUI has been found
- Save_post acf data not updating category of post type
- Looping to organize and display custom posts by category using PHP and WordPress
- Dupplication of Custom Post Type while adding attachment
- My post loop needs to have 8 different post templates
- Add new custom post type screen (admin area) results into 404
- Custom Post Type Pagination – not displaying posts
- Posts show up under “published” but not “all”
- Values show up in custom home page but not in custom post pages
- Permanent Custom Post Type
- How save custom meta type posts multicheck grouped by taxonomy (with CMB2) [closed]
- Single Page of Custom Post Type Not Showing the Content Of post
- Organising custom taxonomies and custom post types
- “Trash”, “Draft” and count not showing for custom post type in admin panel
- Change wordpress url permalink structure to show authors posts
- Multiple loops for custom post type to spread data across rows
- Generate slug and meta data if meta field is empty
- Parent to another Custom Post Type – Template files not being recognized
- Why is a custom post type’s URL “/?cposts=name-of-the-post” but default post’s URL is “/?p=ID”?
- Redirect Custom Post Type after user submits update
- Display all post types together
- Custom Post Type Tags Showing Under Regular Post Tags
- Taxonomy and Rewrite Structure
- Pagination for a Custom Taxonomy
- Trying to create hierarchy between 3-4 custom post types
- How do I sort post listing by child post count?
- 404 for children in hierarchical custom post type
- Searching for a single custom post type, buddypress
- Problem retrieving custom field for a custom post type
- Only One Post of Custom Post Type Appearing on Template Page
- Remove custom meta boxes from custom post type
- Admin panel search doesn’t work for a specific custom post type