I would create a custom field containing the function to be called, for example called ‘function_to_call’.
In the templatefile add the code
$function_to_call = get_post_meta( get_the_ID(), 'function_to_call', true );
if ( $function_to_call != "" ) {
echo '
jQuery(document).ready(function($){
' . $function_to_call . '()
});
';
}
Doing this only outputs the function if you set one in the Custom Fields. You could also make a list of available Functions to avoid Javascript errors.
Related Posts:
- Redirect to another page using contact form 7? [closed]
- Best collection of code for your 'functions.php' file [closed]
- force enqueue script to be first in order of prominence
- Remote upload file to server B
- WooCommerce create new product and add to cart on form submit
- Post source link plugin – small modification
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- Check javascript file Proper way in functions.php
- WordPress Plugin development Call to undefined function jQuery()
- How do I use WordPress PHP functions in my Javascript code?
- What’s the point of using WordPress’s built in admin-ajax.php?
- How to create popup same as wordpress popup feature
- How to Replace Words with Hypertext Link But Ignore Previously Existed Links?
- jQuery Plugin to use WordPress functions in AJAX request
- Debugging Technique Question re: functions.php
- Add get_option to jquery
- Override the filter from plugin in child theme
- Pass a php string to a javascript variable
- Problem in loading javascript in footer
- Shortcode button dosent work for all posts. Work for first post only
- Get IDs of Images from Gallery Block in InnerBlocks of a Custom Gutenberg Block
- Bootstrap Drop Down menu is not working
- Best approach to fetch data from wp options to js file or php file
- Edit Yoast SEO breadcrumbs output [closed]
- Can someone please tell me what is wrong with my plugin?
- wordpress site | All-in-one-cufon IE Issue
- Change upload folder for a CPT
- Override Plugin Script Fucnction in WordPress
- Time consuming callbacks in customizer
- Modifying a .js Function for Print [QZ Tray, WooCommerce POS]
- Display encrypted content on my website
- Redux Framework: Page freezes on typing in Editor
- Using window.onload with Ubermenu
- GeoMashup plugin: how to customize cluster markers / icons? [closed]
- “Conflict” with jQuery (or its plugins)?
- a weird attribute on every html tag
- wordpress add_action() issue in ajax call
- Plugin Development – Functions or Hooks?
- Localizing methods for jQuery append prepend wrap parent
- JQuery prepend a function
- Which plugin can do horizontal scrolling of RSS feeds in WordPress [closed]
- I changed .live() to .on() but change is not reflected on the server
- get specific value of a array | PHP
- How to get specific string/value from an array? php [closed]
- Overriding an Array in a Plugin’s Class/Function from functions.php
- Why does my jQuery plugin show up as text in WordPress?
- JQuery needs to be defined in , but Gravity Forms is defining it in the
- how to change wp-admin url using function file
- Disable submit button order
- same user role or copy the user role to be same as the other role
- Load CSS files in header of Bones theme?
- JS Plugin not executing the js correctly. Trying to make all internal links scroll smoothly
- Javascript from Easy-Fancybox place into footer
- sliding/fading header plugin or approach suggestion
- Jquery POST Ajax Return null data in wordpress
- implement custom roles in custom plugin
- Why do I need to reload the page for WordPress to see the new custom field added with jQuery
- Overriding inline !important CSS with Javscript code snippet with media query
- Get the link title attribute and send it google analytics as custom label via google tag manager using beehive pro for WordPress
- Post source link plugin – small modification
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- How to add specific script to WordPress webpage that will working with user input and databases
- Cannot pass value variable to WP AJAX functions
- How to properly enqueue jQuery knob on WordPress without conflict?
- Ajax Call not Working in Plugin
- How to get a specific string from a url
- Does anybody know how to insert a complete jquery plugin into a wordpress elementor-page?
- Adding discount functionality to the cart
- JS working when used normally but not in wordpress
- Precheck fields when I add a new post
- How can I add a custom Javascript snippet to display my feedback in footer?
- front end editor creation for Restropress plug in – displaying information from a WP admin area, on a different URL
- Website always load twice on start
- working code, not working – Plugin Dev
- Add external javascript to post template
- How to solve Blocked a frame with origin from accessing a cross origin frame error in wordpress?
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- Disqus comments count taking long to update
- Place content inside the Post Loop
- show-hide based on select option jquery wordpress
- Javascript in plugin not working
- Conditional required fields for WordPress Contact Form 7
- Plugin program: JQuery not working in this plugin
- Possible jquery / library conflict in plugin usage
- Ajax, jQuery and WordPress
- Why won’t the Comprehensive Google Map Plugin load?
- get_option include in my adsense
- How do I output user_registered time in my correct timezone?
- Ajax in Plugins: returns the whole page
- Element works, but not on wordpress site [duplicate]
- Load css classes after using ajax calls
- FacetWP: Plugin breaks button/modal functionality inside searchable content area
- TypeErrors with Yoast, jQuery in conflict?
- Javascript as Jquery Function Call?
- WordPress: code structure
- Count div with class (.length) only shows 0 [closed]
- Adding a script & php to functions.php
- How to Add Extra Text In WordPress Title Before Post Publish
- How to disable plugin capability : “create new category”
- Product customizing quiz – quiz adding products to the cart