WordPress.org

Ready to get started?Download WordPress

Forums

Easy Recipe
[resolved] Code from Easy Recipe on every page (11 posts)

  1. elmok
    Member
    Posted 1 year ago #

    Hello,

    I've a problem with Easy Recipe (i'm using the last version -2.2.8-).

    I have code from the Easy Recipe plugin on every page of my website (even where there is no recipe). I don't understand why.

    Nothing is visible by "humans", but if you check in the source code, there is the code of easy recipe at the bottom of the page.

    You can check on my website here or here

    Of course, I don't want this code on the pages where there is no recipe, it's not really good for the optimization of my website. And because the code contains <h3>, it's not good at all for ranking and SEO reasons.

    If you know the issue let me know :)
    (and if I manage to find it by myself i'll post it here)

    Thx !

    http://wordpress.org/extend/plugins/easyrecipe/

  2. Jayce53
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    The next version of EasyRecipe (due out soon) does a better job figuring out when to include the EasyRecipe code. It will always output some code (the CSS specifically) because there's no efficient way of knowing at the time in the page generation cycle that the CSS needs to be output, if a page contains a recipe. However the javascript code will be supressed when there's no recipe.

  3. elmok
    Member
    Posted 1 year ago #

    Okay, thx !

    I'm waiting for the new version :)

  4. Sjourney
    Member
    Posted 1 year ago #

    Jayce,
    There is a manual way to deregister a plugin via functions.php
    If one knows where there will not be a recipe posted for sure they can specify it in a conditional statement if (!is_page() || !is_search()) {}

    for example the Contact Form 7 plugin really only makes sense on ones 'Contact' page:

    /* ------[Only import Contact Form 7 files on contact page]------ */
            /* http://fredrikmalmgren.com/only-include-contact-form-7-javascript-and-css-when-needed/
            ================================================================== */
            add_action( 'wp_print_scripts', 'deregister_cf7_javascript', 100 );
            function deregister_cf7_javascript() {
                if ( !is_page(contact) ) {
                    wp_deregister_script( 'contact-form-7' );
                }
            }   
    
            /* Remove Contact Form 7 CSS from every page except Contact
            ================================================================== */
            add_action( 'wp_print_styles', 'deregister_cf7_styles', 100 );
            function deregister_cf7_styles() {
                if ( !is_page(contact) ) {
                    wp_deregister_style( 'contact-form-7' );
                }
            }
  5. Sjourney
    Member
    Posted 1 year ago #

    Not sure this is totally Kosher. Please use at your own risk.

    So easyrecipe enqueues the following

    Scripts:
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_script('jquery');
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_script('jquery-ui');
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_script('easyrecipe-options', "$this->easyrecipeURL/easyrecipe-options.js", array (), $this->version);
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_script('easyrecipeadmin', "$this->easyrecipeURL/easyrecipe-admin.js", array ('jquery-ui-dialog'), $this->version, true);
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_script('easyrecipediag', "$this->easyrecipeURL/easyrecipe-diagnostics.js", array (), $this->version, true);
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_script('easyrecipe', "$this->easyrecipeURL/easyrecipe.js", array ('jquery'), $this->version);
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_script('jquery');
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_script('jquery-ui');
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_script('json2');
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_script('easyrecipeformat', "$this->easyrecipeURL/easyrecipe-format.js", array ('jquery-ui'), $this->version);
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_script("easyrecipeadmin", "$this->easyrecipeURL/easyrecipe-admin01.js");
    
    and the following Styles:
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_style("easyrecipe-jquery", "$this->easyrecipeURL/jQueryCSS/jquery.css", array (), $this->version);
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_style("easyrecipe-admin", "$this->easyrecipeURL/easyrecipe-admin.css", array (), $this->version);
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_style("easyrecipe-diagnostics", "$this->easyrecipeURL/easyrecipe-diagnostics.css", array (), $this->version);
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_style("easyrecipe", "$this->easyrecipeURL/easyrecipe.css", array (), $this->version);
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_style("easyrecipe-jquery", "$this->easyrecipeURL/jQueryCSS/jquery.css", array (), $this->version);
    ../easyrecipe/class-easyrecipe.php:        wp_enqueue_style("easyrecipeformat", "$this->easyrecipeURL/easyrecipe-format.css", array (), $this->version);

    So one could do something like:

    /*  Remove EasyRecipe javascript from non-recipe content
            ================================================================== */
            add_action( 'wp_print_scripts', 'deregister_easyrecipe_javascript', 100 );
            function deregister_easyrecipe_javascript() {
                if ( is_page || is_search()  ) {
                   // Not sure how to tell easyrecipe not to load jquery, jquery-ui, and json
                    wp_deregister_script( 'easyrecipe-options' );
                    wp_deregister_script( 'easyrecipeadmin' );
                    wp_deregister_script( 'easyrecipediag' );
                    wp_deregister_script( 'easyrecipe' );
                    wp_deregister_script( 'easyrecipeformat' );
                }
            }   
    
            /* Remove EasyRecipe CSS from non-recipe content
            ================================================================== */
            add_action( 'wp_print_styles', 'deregister_easyrecipe_styles', 100 );
            function deregister_easyrecipe_styles() {
                if ( is_page || is_search()  ) {
                    wp_deregister_style( 'easyrecipe-jquery' );
                    wp_deregister_style( 'easyrecipe-admin' );
                    wp_deregister_style( 'easyrecipe-diagnostics' );
                    wp_deregister_style( 'easyrecipe' );
                    wp_deregister_style( 'easyrecipeformat' );
                }
            }
  6. elmok
    Member
    Posted 1 year ago #

    Thx !

    I'm going to check it out :)

  7. Jayce53
    Member
    Plugin Author

    Posted 1 year ago #

    The place to do this is at the end of thePosts() in class-easyrecipe.php (immediately before the return)

    if (count($this->easyrecipes) == 0) {
    ... dequeue code here ...
    }

    The next update of EasyRecipe will dequeue its css and js if there's no recipes on a page.

  8. elmok
    Member
    Posted 1 year ago #

    Thank i'm going to look at that this week, but my problem is not really about JS and CSS. My main problem is that even on pages where there is no recipe I've many <h3> from this plugin in my source code (like here line 264).

    I'm going to try finding a solution with your code

    if (count($this->easyrecipes) == 0) {
    ... dequeue code here ...
    }

    And thx a lot for your time and answers !

  9. Sjourney
    Member
    Posted 1 year ago #

    @elmok, Not sure I see your issue.
    In your source there is no line 264 in the html of http://www.lemondedukonjac.fr/konjac-dukan/

    AFAICT, there is no easy recipe markup or selectors in your source either. Am I missing something?

  10. elmok
    Member
    Posted 1 year ago #

    :D

    I think that I just found the solution, I tried to look at the source code with an other web browser (that I never use) and there is no easy recipe markup in the source code.

    So, It's probably because of my cache...

    Thank you for your answer, because of you I found what was wrong (with me...).

    Thx again, and long life to Easy Recipe !

  11. Jayce53
    Member
    Plugin Author

    Posted 1 year ago #

    Glad you got it fixed!

    The next version (due out soon - honest!) is much better at queueing up its scripts and styles - it should only queue stuff when it's needed.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic