Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Need to hook set option into wp_footer() WordPress

  • SOLVED

I know this is an easy one but I'm just scared of action hooks for some reason.

This is what I have
...
<?php echo stripslashes(get_option('dt_footer_scripts')); ?>
<?php wp_footer(); ?>
</body>
</html>

I want to hook the value of dt_footer_scripts into wp_footer() from my functions file.

Answers (1)

2010-12-31

Andrzej answers:

function my_dt_footer_scripts() {
echo stripslashes(get_option('dt_footer_scripts'));
}
add_action('wp_footer', 'my_dt_footer_scripts');


Joe Calithia comments:

Exactly. Quick follow-up question... would it work the same way for these?

<?php if( !dt_options_set() ): include (DT_FUNCTIONS . 'save-message.php' ); endif; ?>

<script>
var ajaxurl='<?php echo admin_url('admin-ajax.php'); ?>';
</script>


Like this...
function my_dt_footer_scripts() {
echo stripslashes(get_option('dt_footer_scripts'));
if( !dt_options_set() ): include (DT_FUNCTIONS . 'save-message.php' ); endif;
var ajaxurl='<?php echo admin_url('admin-ajax.php');
}
add_action('wp_footer', 'my_dt_footer_scripts');


???


Andrzej comments:

yes, but you need to add ?><script><?php ... ?></script><?php


Joe Calithia comments:

So the final code would be?...

function my_dt_footer_scripts() {

echo stripslashes(get_option('dt_footer_scripts'));
if( !dt_options_set() ): include (DT_FUNCTIONS . 'save-message.php' ); endif;
?><script>var ajaxurl='<?php echo admin_url('admin-ajax.php'); ?>';<?php

}

add_action('wp_footer', 'my_dt_footer_scripts');


Andrzej comments:

yes, this should work