wordpress permalinks

我们两清 提交于 2019-12-11 13:50:13

问题


I set my wordpress permalink structure to /%postname%/ but now when I go to a page other than the home page (for example if I went to somelink.com/about) I lose all javascript references.

I think this happens because the links to the js files are no longer right as it is in the imaginary folder "about". This is how the js files are referenced in the header.php file.

        <script type="text/javascript" src="wp-content/themes/default/js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="wp-content/themes/default/js/cufon-yui.js"></script>
    <script type="text/javascript" src="wp-content/themes/default/js/Goudy_Bookletter_1911_400.font.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {      
            Cufon.replace('h1');
            Cufon.replace('h3', {textShadow:'0 1px #fff'});
        });
    </script>

Am I doing something wrong?


回答1:


if you are referencing anything in your template files you can use either

1:

<?php bloginfo('url');?>

or 2:

<?php bloginfo('template_url');?>

which would be coded as:

<script type="text/javascript" src="<?php bloginfo('url');?>/wp-content/themes/default/js/jquery-1.4.2.min.js"</script>

or

<script type="text/javascript" src="<?php bloginfo('template_url');?>/js/jquery-1.4.2.min.js"</script>

1: loaded the main site URL; 2: will return the absolute url to your current themes directory,

(which is better for theme development).




回答2:


I gather you are manually inserting the javascript calls, which is not the best way to handle jQuery inclusion in Wordpress - you should look into wp_enqueue_script, which will keep you from including the jquery libraries more than once if a plugin or theme you are using is also including them.

Also, the ay you have the source written, I believe you are correct - the client is looking for the js files in the relative path under /about. Place a "/" before wp-content to have the client look for them inside wp-content within your root directory (assuming WP is installed at root).



来源:https://stackoverflow.com/questions/2440148/wordpress-permalinks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!