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
- How to add a post page from a button without reloading
- How to get only child terms from a custom taxonomy of current post type?
- Custom WP_Query doesn’t display all posts
- Add custom CSS class to custom post type
- How can I use archive-{post_type}.php theme template?
- Remove custom permalink structure from custom post type without modifying register_post_type() directly
- How to add current custom taxonomy slug to body class
- Dynamic bootstrap tabs with post_title doesn’t display the_content
- Running a song lyrics site on WordPress
- Change Slug of a Custom Post Type
- Custom post type – list posts based on meta_key and display them divided by CPT taxonomy category
- Get $post->ID from a URL
- Redirect to archive is single post has a certain term assigned to it?
- Using page slug in wp_query
- Custom Post Type with Custom Taxonomy as Category
- How to display CPT archives?
- WP_Query() with custom post type and taxonomy — get all terms?
- Displaying a div from an assigned meta_value when on a page
- Save and user submitted data from a form and display them in the wp backend
- Why isn’t a list of posts from my custom post type displaying in this widget?
- Excerpt function for any content
- Change “empty trash” button text?
- Assign category a default post type
- Custom query – get_the_terms not work
- WPDB for post count on post
- Specify a particular page to list all custom types
- Programmatically change post visibility on save_post action return a 500
- Query & the_content() is showing in the header
- Custom meta Title for custom post type archive from page
- post_parent in custom post type
- Meta data (Tags and Categories) for Custom Posts not showing.
- Front end access to a SQL data repository – recommended way?
- Custom Meta fields Update hook?
- How to display custom field value on page?
- Displaying custom post types in front end
- Navigate posts with different post type that are in the same categories
- Custom taxonomy (categories) on custom post type return no results
- Page listing Custom Posts
- post_per_page ignored in WP_Query
- the_title not working
- Display different information of a custom post type
- Custom taxonomy wp_query woes.
- WordPress app page not found error for posts with hyphen in permalink
- Where is the sticky post option?
- get_the_tag_list() returns bad links
- Add term list as class
- Filter second dropdown (tax) based on first dropdown (cpt)
- Dump custom post type database
- uploading problem of wordpress theme
- Excluding a Custom Post Type with a specific tag using pre_get_posts
- Custom Post Type Link added to menu won’t show in frontend
- show all custom posts types in home page
- List of users that clicked a ‘Join’ button at single post
- Taxonomy archive 404ing (not term archive)
- Pagination doesn’t function properly for archive of a custom post type set as the front page
- Variable not working in WP_Query
- WP_query – Filter by tax_query and meta_query using multiple select
- Display an authors post on a single page only when they are logged in
- How to group navigation items in the admin panel
- Hide meta box for everything BUT a certain custom post type
- Include php on a specific page template
- Create Array from custom post type to display a slider
- what custom post type this archive belongs to?
- Setting Post Title via Meta Data returns Auto-draft
- Tags not working in my custom post type
- Custom post-type metabox position
- wp_trash_post action hook with custom post type
- Not sure why this template for custom post type posts isn’t displaying anything. What’s missing?
- What’s an efficient way to change the post status of many posts at once?
- Use Pages for Custom Post Type
- Return the name of the post type
- I can’t access custom taxonomy page listing
- Is it possible to load a different sidebar in single.php based on a meta_query filter?
- How to have permalink like domain.com/term/postname?
- List Posts By Custom Taxonomy
- Can variables be used to rewrite a Custom Post Type permalink? [duplicate]
- Creating two loops based on different logic
- How to Echo Metadata Value in Currency Format
- Issue on Working with Metabox – Checkbox to enable Sale Items
- Filter posts by tax (dropdown) and meta value
- How do I amend form data before it is saved for a custom post type
- Archive-posttype.php isn’t loaded
- List of all entries of custom-post-type: Add year-parameter?