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
- Get terms by taxonomy AND post_type
- New post status for custom post type
- Permalink Structure for Multiple Post Type Archives by Taxonomy
- Allow user to Edit Posts but not Add New?
- WordPress 4.4+ : How to revision CPT + metadata
- How can I filter posts by post_parent in the admin?
- Rewriting ‘rewrite’ slug for custom post type used by plugin
- Using Templates with Custom Post Type UI
- WordPress Custom Post Type Admin Page really slow
- How to setup a Custom Taxonomy Term template
- Creating a gallery of featured images from custom post type
- Remove Custom Post Type menu for non-administrator users.
- Using Query Posts With Multiple Post Types And A Taxonomy
- Retrieve a specific field from taxonomy term through advanced custom fields [closed]
- Custom Taxonomy List links being re-written
- wp_list_categories and custom post types
- Bulk 301 redirect for custom post type
- Associate Taxonomies Across Post Types
- ‘category__and’ for custom taxonomy?
- Custom field default value with counter
- Custom post type hierarchical permalinks not behaving as expected for parent/child pages
- Warning when attempting to edit/add custom post type
- Check if a specific custom field exists?
- How does register_post_type know how and which function to use from the add_action function?
- Fetch ID’s associated with a custom post type when translated with WPML?
- Custom post types archive redirect
- Moving ‘register_post_type’ to seperate file not working
- Get post from custom post type order by two taxonomies
- Custom Taxonomy Archives on Custom Post type Page [duplicate]
- Override a page template from a plugin in a child theme
- Display custom fields from custom posts in RSS feed
- On update or create post redirect to current post position in list
- Versioned Custom Post Type (Not the same as revisions)
- Is it better to use WordPress Custom Post Types or Taxonomies?
- A custom post within a custom post
- custom post type pagination error 404
- TinyMCE style formats for different post types
- Problems with image size on the server WordPress
- How to add multiple images to a custom post type without plugin [closed]
- get_the_title() is returning results from previous loop
- Moving meta boxes in admin
- Post-thumbnail only for specific post-types?
- Add post meta programmatically to attachment
- Get Specific Template Part if Custom Field is Some Value
- Page as Archive page
- 3 random images from custom post type, each in a div with a diffrent class
- get_category_link() for custom post type does not include custom slug rewrite?
- Shortcode leaves no space for other elements?
- Show All Custom Post Types On A Single Archive Page
- Custom Post Types,Permalink and Heirarchy
- Send post changes to set email addresses (not users or subscribers)
- Foreach loop returning more than one item when querying taxonomy
- Permalinks for single-[custom-post-types] not working
- Most viewed post of custom post type
- How to enable parent-child relationships and post attribute admin widget for posts
- Custom post types
- Manually adding or updating CPT automatically sets post_status of future
- Images not load on custom post type sidebar, related posts
- Custom post type page with parameter
- Replace Content of Sidebar on Custom Post Type
- open custom post type in popup window instead of page
- Filling custom post type posts from a rest api
- Show Post Types customized in Template Page
- Conditional editing CPT – using editor’s role and author’s usermeta
- Get category name of custom post type
- Tags being removed upon updates to related posts: ACF/Genesis/WP5.4.1
- Get all of a user’s posts (custom post type) then get cumulative value of a specific meta_key value from those posts
- Pagination for a cpt filtered with a category
- How do I force a CPT to select a shared custom template in Post Attributes?
- Sort loop by custom field from different post type
- How to create groups like that in buddypress?
- Custom meta box data not saving
- Include template if a post is a single product
- Allow viewing the edit screen for a post type, but not make/save/publish/update changes
- Render custom taxonomy query as single template
- Custom meta-box for all custom post types
- General question about Parent and Child Post type relationships
- WordPress Load more posts by ajax not working
- What’s the best way to show custom post types? With page template it’s not perfect!
- Multiple while loops not functioning [closed]
- Listing all custom post types using a specific term on the said term’s template page, in groups
- How to write an if statement which reads: ‘if is this custom post type or a child of it do the following’?
- taxonomies or categories w/custom post
- Post count for particular term