I am working on a side project for my website to make the footer more easily editable in the Wordpress theme customizer, and use a dynamic copyright date, something I had in my previous version, but I wanted the values to be more easily editable.
I have created all of this and it works fine, but when I try to add in the dynamic date, it falls over as when I do this, I am trying to have a within a .
I have looked around quite a bit for an answer to this, but not knowing what to call it doesn't help.
I decided asking my question directly is probably the best thing to do.
So, inside a php script, I have all the values I need which work fine, and a at the bottom which uses jQuery to append HTML code to a certain area (after the #footer-info area).
I need to be able to use the small amount of code posted below in the area indicated, but have no idea how to do this as it is technically inside a jQuery string.
This is the main area which I need:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#footer-info").text(' ');
jQuery('<p id="footer-info"><?php if( !empty($footer_one)) : ?><?php echo $footer_one; ?><?php endif; ?> <a href="<?php if( !empty($footer_link_one)) : ?><?php echo $footer_link_one; ?><?php endif; ?>"><?php if( !empty($footer_two)) : ?><?php echo $footer_two; ?><?php endif; ?></a> | © Copyright <?php if( !empty($footer_three)) : ?><?php echo $footer_three; ?><?php endif; ?>**DYNAMIC DATE**<a href="<?php if( !empty($footer_link_two)) : ?><?php echo $footer_link_two; ?><?php endif; ?>"> <?php if( !empty($footer_three)) : ?><?php echo $footer_three; ?><?php endif; ?></a>. All Rights Reserved.</p>').insertAfter("#footer-info");
});
</script>
The dynamic date code:
<script>new Date().getFullYear()><?php if( !empty($footer_three)) : ?><?php echo $footer_three; ?><?php endif; ?>&&document.write(" - "+new Date().getFullYear());</script>
I need a way to put the code above inside the area marked DYNAMIC DATE in the first code segment (just past half-way through scrolling).
Is this possible, or am I doing this all wrong?
Here is the whole php file if you need it:
<?php
// ====================== Footer Editor ======================
function ds_footer_links_editor($wp_customize) {
$wp_customize->add_panel( 'footer_links_option', array(
'priority' => 30,
'capability' => 'edit_theme_options',
'title' => __('Edit Footer Links', footer_links_title),
'description' => __('Customize the login of your website.', footer_links_title),
));
$wp_customize->add_section('ds_footer_links_section', array(
'priority' => 5,
'title' => __('Footer Links Editor', footer_links_title),
'panel' => 'footer_links_option',
));
// Before Link One
$wp_customize->add_setting('ds_footer_links_before_link_one', array(
'default' => 'Designed By',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_footer_links_before_link_one', array(
'label' => __('Text Before First Link', footer_links_title),
'section' => 'ds_footer_links_section',
'type' => 'option',
'priority' => 5,
'settings' => 'ds_footer_links_before_link_one'
));
// Link One
$wp_customize->add_setting('ds_footer_links_link_one', array(
'default' => 'Kyle Briggs',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_footer_links_link_one', array(
'label' => __('First Link Text', footer_links_title),
'section' => 'ds_footer_links_section',
'type' => 'option',
'priority' => 10,
'settings' => 'ds_footer_links_link_one'
));
// Link One URL
$wp_customize->add_setting('ds_footer_link_one_url', array(
'default' => 'http://kylebriggs.co.uk/',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_footer_link_one_url', array(
'label' => __('First Link URL', footer_links_title),
'section' => 'ds_footer_links_section',
'type' => 'option',
'priority' => 15,
'settings' => 'ds_footer_link_one_url'
));
// Company Name
$wp_customize->add_setting('ds_footer_links_company_name', array(
'default' => 'Kyle Briggs',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_footer_links_company_name', array(
'label' => __('Text Before First Link', footer_links_title),
'section' => 'ds_footer_links_section',
'type' => 'option',
'priority' => 5,
'settings' => 'ds_footer_links_company_name'
));
//Company URL
$wp_customize->add_setting('ds_footer_link_company_url', array(
'default' => 'http://kylebriggs.co.uk/',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_footer_link_company_url', array(
'label' => __('First Link URL', footer_links_title),
'section' => 'ds_footer_links_section',
'type' => 'option',
'priority' => 15,
'settings' => 'ds_footer_link_company_url'
));
//Start copyright year
$wp_customize->add_setting('ds_footer_link_start_year', array(
'default' => '2015',
'type' => 'option',
'capability' => 'edit_theme_options',
));
$wp_customize->add_control('ds_footer_link_start_year', array(
'label' => __('First Link URL', footer_links_title),
'section' => 'ds_footer_links_section',
'type' => 'option',
'priority' => 15,
'settings' => 'ds_footer_link_start_year'
));
}
add_action('customize_register', 'ds_footer_links_editor');
function ds_new_bottom_footer() {
$footer_one = get_option('ds_footer_links_before_link_one','Designed By');
$footer_two = get_option('ds_footer_links_link_one','Kyle Briggs');
$footer_link_one = get_option('ds_footer_link_one_url','http://kylebriggs.co.uk/');
$footer_three = get_option('ds_footer_links_company_name','Kyle Briggs');
$footer_link_two = get_option('ds_footer_link_company_url','http://kylebriggs.co.uk/');
$footer_four = get_option('ds_footer_link_start_year','2015');
?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#footer-info").text(' ');
jQuery('<p id="footer-info"><?php if( !empty($footer_one)) : ?><?php echo $footer_one; ?><?php endif; ?> <a href="<?php if( !empty($footer_link_one)) : ?><?php echo $footer_link_one; ?><?php endif; ?>"><?php if( !empty($footer_two)) : ?><?php echo $footer_two; ?><?php endif; ?></a> | © Copyright <?php if( !empty($footer_three)) : ?><?php echo $footer_three; ?><?php endif; ?><script>new Date().getFullYear()><?php if( !empty($footer_four)) : ?><?php echo $footer_four; ?><?php endif; ?>&&document.write(" - "+new Date().getFullYear());</script> <a href="<?php if( !empty($footer_link_two)) : ?><?php echo $footer_link_two; ?><?php endif; ?>"> <?php if( !empty($footer_three)) : ?><?php echo $footer_three; ?><?php endif; ?></a>. All Rights Reserved.</p>').insertAfter("#footer-info");
});
</script>
<?php
}
add_action( 'wp_head', 'ds_new_bottom_footer' );
?>