WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a plugin that supports calling custom functions that you've created?


page A -- I want to call function x


page B -- I want to call function y


I don't want to write the calls in the main input because of others editing and might delete them by misstake...

This is my current solution but not optimal in my eyes :)


        /* Always have wp_footer() just before the closing </body>
         * tag of your theme, or you will break many plugins, which
         * generally use this hook to reference JavaScript files.

        $js =  get_post_meta($post->ID, 'javascript', true);
            if ( $js != "" ) {

<script type="text/javascript">
    <?php echo $js; ?>
<?php } ?>

then I added custom field "javascript" on the pages with their custom functions like this.

function_x(some_variable); function_y(some_var); function_foo(bar);
share|improve this question
Do you want to avoid using custom fields as well? – kidakaka Nov 16 '12 at 12:16
@kidakaka yes I would like to but... maybe that's to much to ask for though...! – Philip Nov 16 '12 at 12:58
up vote 1 down vote accepted

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 '
              ' . $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.

share|improve this answer
@fish, yeah I did a solution like that but I don't really like it, see my edit. – Philip Nov 16 '12 at 13:01
but maybe that's the easiest and most effective solution ... – Philip Nov 16 '12 at 13:05
you have to store the values somewhere - so the custom field is your best option. maybe you could create a custom metabox not visible for the editors, containing all the usable functions. – fischi Nov 16 '12 at 13:58
Yeah, as you say, I need to store them somewhere and I think custom fields will do it for now. Thanks! – Philip Nov 16 '12 at 14:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.