0

I have been given this code that I want to adapt and use to change a link in a template.php file, I have not been able to adapt it to work so would love any help that can be given.

<script type="text/javascript">
jQuery(document).ready(function($) {
    if ( $(document).width() < 1500 ) {
        $('.change-link > a').each( function(){
            newlink = 'Enter New URL';
            $(this).attr('href',newlink);
        });
    }
});
</script>

Will it work in a template.php and be able to choose between this link:

<?php include( TEMPLATEPATH . '/includes/projects.php'); ?>

and this link depending on the browser size?

<?php include( TEMPLATEPATH . '/includes/projects.php'); ?>

Or will it require more code in other pages of my WordPress theme?

1
  • 3
    Please read inside javascript how to properly use the Dependency API, wp_register/enqueue_style/script() functions and about stuff like get_template_directory() and similars in Codex.
    – kaiser
    Commented Sep 6, 2013 at 17:26

1 Answer 1

0

First, the two "includes" you gave are going to the same file, so I'm not sure what two files you're trying to judge against. Secondly, the jquery code is ran AFTER the page is processed, so the php includes will not be available to your jquery object.

2
  • Thanks Chris, the 2 files will end up being different titles, you didn't say if this is possible or not? Commented Sep 7, 2013 at 13:17
  • technically, you could use jQuery to perform an AJAX call to that template file, but if you are using Wordpress variables (like $post) then those wouldn't be available to you. Commented Sep 9, 2013 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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