WordPress.org

Ready to get started?Download WordPress

Forums

jquery masonry plugin - neewbie troubles (2 posts)

  1. alimacca
    Member
    Posted 3 years ago #

    Hello I am new to this world so please be gentle...

    I have a bit of background in coding and designing static websites so I know my way around a little but have moved over to the lightside and getting into WP.

    I have a problem getting Masonry plugin to work. I have followed a tutorial but I can't get it to work.

    I have this in my head.php

    <?php wp_enqueue_script("jquery"); ?>
    
    <?php
    	/* We add some JavaScript to pages with the comment form
    	 * to support sites with threaded comments (when in use).
    	 */
    	if ( is_singular() && get_option( 'thread_comments' ) )
    		wp_enqueue_script( 'comment-reply' );
    
    	/* Always have wp_head() just before the closing </head>
    	 * tag of your theme, or you will break many plugins, which
    	 * generally use this hook to add elements to <head> such
    	 * as styles, scripts, and meta tags.
    	 */
    	wp_head();
    ?>
    
    <script language="javascript" type="text/javascript" src="<?php bloginfo('template_url'); ?>http://distinctsignal.co.uk/js/jquery.masonry.min.js"></script>
    
    <script type="text/javascript">
    jQuery(document).ready(function($){
      $('#linky').masonry({ singleMode: true });
    })
    </script>
    
    </head>

    I have a #linky with further <div>'s inside but it just seems to be laying the divs out in a vertical fashion.

    Could it be something to do with the file structure? My 'js' file is in beside the wp-admin etc folders.

    Any help would be fantastic!!

  2. blitz999
    Member
    Posted 2 years ago #

    Hi there,

    I can't help with the plugin itself, but I can see the js file is probably on the wrong place and you your code will be also looking in the wrong place.

    It is probably a good idea to put the masonry js files in your theme folder (wp-content/themes/mytheme, and not in the wp-admin folder (because this folder can get affected in a WordPress update).

    The wp-content folder is a safer place for children to play!

    Also, your call for the script is a bit wonky:

    <script language="javascript" type="text/javascript" src="<?php bloginfo('template_url'); ?>http://distinctsignal.co.uk/js/jquery.masonry.min.js"></script>

    If you put the jquery.masonry.min.js file into your theme folder (in a folder called js), then to find it, the call would be:

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

Topic Closed

This topic has been closed to new replies.

About this Topic