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