Forum Replies Created

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter Tony

    (@tonyzg)

    Ok I found a solution. The only way to remove jQuery core and migrate scripts from website’s frontend is to use wp_print_scripts hook. It’s dirty but I had no choice.

    if (!is_admin()) {
    	function de_script() {
    	   wp_dequeue_script( 'jquery' );
    	   wp_deregister_script( 'jquery' );
    	   wp_register_script('jquery', "//ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js", false, null);
    	   wp_enqueue_script('jquery');
    	}
    	add_action('wp_print_scripts', 'de_script', 100 );
    }

    I see where the problem is. You did not add enqueue custom.js script to functions.php file. Instead you added it to header.php or some other file.

    That said, make sure enqueue custom.js script is added to functions.php file that can be found at your theme’s folder.

    Also since your comments template is different than default one, you should change your code in custom.js file to this:

    // Position “browse image” in comments above the “post comment” button
    jQuery(function ($) {
    $(‘#comment’).after($(‘#comment-image-wrapper’));
    });

    Everything else seems good to me.

    Saluti 🙂

    Please post your website url here so I can take a look at the source code. What is your WP version?

    There is probably some jQuery issue on the website. You can see JS errors in FF Firebug console if any, so that can help you with debuging.

    Hi andrianiannalisa,

    Here is how to do that:
    1. Create custom.js file (if your theme does not have one already) and put this code in it:

    // Position "browse image" in comments above the "post comment" button
    jQuery(function ($) {
    	$('p.form-allowed-tags').after($('#comment-image-wrapper'));
    });

    2. Upload custom.js file to your theme’s js folder (usually it is wwwroot/wp-content/themes/[your-theme]/js/)

    3. Enqueue custom.js file to your theme. Here is a code that you need to paste to your functions.php theme file:

    /**
     * enqueue custom.js script
     */
    function custom_script() {
    	wp_enqueue_script( 'custom', get_template_directory_uri() . '/js/custom.js', array(), '1.0.0', true );
    }
    
    add_action( 'wp_enqueue_scripts', 'custom_script' );

    See here for reference: http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    That’s it!

    Ok guys, I came up with a jquery fix. It is nice and simple solution:

    // Position "browse image" in comments above the "post comment" button
    jQuery(function ($) {
    	$('p.form-allowed-tags').after($('#comment-image-wrapper'));
    });

    Include this code in your custom js script and voila! You can also add this css to your css file:

    #comment-image-wrapper {margin: 0 0 20px;}

    Thread Starter Tony

    (@tonyzg)

    I’m using couple of plugins (no updates for these plugins) that cannot work with jQuery versions higher than 1.6.0. (Also I don’t plan to update WP to newer versions until I find replacements for those old plugins that are using old jQuery library.) But this is now urgent I have to be able to use old version of jQuery for front end, just as I did until upgrading to 3.7.1.

    Thread Starter Tony

    (@tonyzg)

    @esmi: As far as I know, the only way to register your own jQuery library is to first deregister existing one. (At least this was practiced in earlier versions of WordPress.)

    @andrew: First of all, I updated from 3.6 to 3.7.1. On versions 3.6 I was loading jQuery 1.6.0 from Google – It was working fine. When I updated to WP 3.7.1, all of a sudden, WordPress started loading it’s own jQuery v1.10.2:

    <script type='text/javascript' src='http://mysite.com/wp-includes/js/jquery/jquery.js'></script>
    <script type='text/javascript' src='http://mysite.com/wp-includes/js/jquery/jquery-migrate.min.js'></script>

    And there is no way to modify this. Does this make sense?

    Thread Starter Tony

    (@tonyzg)

    Aha I got it now! 🙂 Thank you for additional explanation.

    I think this is fine solution if you do not have too many categories and if number of categories won’t raise by the time.
    I have continents, states and cities, and in addition to that I have 20 topics.

    I also need to be able to filter posts via two dropdowns (region,topic) that should always be present no matter what region on topic user browses.

    So I guess the only easy way to make this work would be using WP built in categories & url rewrite.

    This is a core idea: https://spruce.it/noise/two-category-dropdown-search-filter-in-wordpress/

    I created URL rewrites that cover all case scenarios for url structure (permalinks) and created one page template that handles querystring params. As far as I can tell, this is the only one elegant solution for my case.

    Here is a sample of my URL rewrite:

    function my_rewrite_rules( $wp_rewrite )
    {
    	$wp_rewrite->rules = array (
    	'region/([^/]+)/topic/([^/]+)/?$'  =>  'index.php?pagename=filter&regioncat=$matches[1]&topic=$matches[2]'
    	) + $wp_rewrite->rules;
    
           // and so on ... there is a total of 7 rules
    }
    add_action( 'generate_rewrite_rules', 'my_rewrite_rules' );

    Keesiemeijer thanks once again! I found your posts very useful.

    Thread Starter Tony

    (@tonyzg)

    Thank you so much keesiemeijer!

    Think I got it!

    So just to confirm I’m understanding it right.
    I should:
    1. Leave categories as they are now (regions only!)
    2. Register a Custom Taxonomy “Topic” and then create terms within that taxonomy (Weather, Economy, Tourism…)

    Correct?

    In that case my URLs would look like this: mysite.com/europe/uk/ (by using Yoast SEO plugin, “category” is removed from URLs)

    One thing I’m not sure though is will WP automatically filter posts by “wheather” term if I supply for instance these URLs: mysite.com/europe/uk/wheather/ or even this link: mysite.com/wheather/

    Or perhaps I neeed to rewrite URLs?

    Thread Starter Tony

    (@tonyzg)

    Glad it helped. I was pulling my hair for a while too!
    Cheers!

    Thread Starter Tony

    (@tonyzg)

    YAY! That worked! Thank you Chandan so much!!!

    I accutaly needed to get all categories for a specifiec post, delimited by spaces, so here it is:

    $terms = get_the_terms($post->ID, 'your_taxonomy_here' );
    if ($terms && ! is_wp_error($terms)) :
    	$term_slugs_arr = array();
    	foreach ($terms as $term) {
    	    $term_slugs_arr[] = $term->slug;
    	}
    	$terms_slug_str = join( " ", $term_slugs_arr);
    endif;
    echo $terms_slug_str;
    Thread Starter Tony

    (@tonyzg)

    Nope, returns nothing!

    Thread Starter Tony

    (@tonyzg)

    WOW took me forever to find a solution:

    Yeah, I was right! Other rules apply for custom taxonomies (categories). If you want to display only posts from current category
    you would need to filter it by a slug, NOT category ID:

    $term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var( ‘taxonomy’ ) );
    //print_r($term);
    $loop = new WP_Query( array( ‘post_type’ => ‘product’, ‘catalog’ => $term->slug));

    Thread Starter Tony

    (@tonyzg)

    Thanks Zex but it did not work.

    I have also tried:

    $loop = new WP_Query('cat=50&post_type=product');

    cat=50 is category ID that exists, but if set like in the code above, no posts are returned whatsoever!

    Wondering if other rules applies for custom taxonomies?

    I’ll be darn! Deleting the empty line spaces really did a trick!
    Thx ghettocottage I was pulling my hair for a hour at least!

    Cheers!

Viewing 15 replies - 1 through 15 (of 16 total)