Site logo

[Support request] Should I use Child Theme or Code Snippets?

Home Forums Support [Support request] Should I use Child Theme or Code Snippets?

Home Forums Support Should I use Child Theme or Code Snippets?

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #2292509
    Art

    I’m using GeneratePress Premium and trying to figure out how to use the Code Snippets plugin or a child theme. The purpose is to insert the Stars Rating block (from Dev4Press), after a post title, but limited to certain categories. The below code will work in a child theme, with my old theme, but not as a snippet in Code Snippets. I’m willing to create another child theme but not sure which file to use (content-single.php?) or where to place the snippet.

    <?php
    if (in_category(array(25, 3, 161, 132, 41, 136, 26, 177, 133, 176, 243, 85, 134))) {
    gdrts_posts_render_rating(array(‘echo’ => true));
    }
    ?>

    I’m not much of a coder so I’m sure I’m missing the obvious. Any help is much appreciated.

    Thank you.

    #2292513
    Fernando
    Customer Support

    Hi Art,

    I’m not sure how this function gdrts_posts_render_rating exactly works.

    Maybe to have a little context, may we know where specifically you are adding this code in your Child Theme in your old theme?

    I’ll check if there’s something missing for it to work in Code Snippets so that you wouldn’t need a Child theme.

    Hope to hear from you soon.

    #2292515
    Art

    Thank you for your reply. Here is how it looks on the live site, right under the title.

    https://musiclibraryreport.com/1-to/1-revolution-music/

    In the content-post.php (without posting all the code) it sits here:

    
    <?php
    		the_title( '<h1 class="entry-title">', '</h1>' );
    		?>
    				<?php 
    		if (in_category(array(25, 3, 161, 132, 41, 136, 26, 177, 133, 176, 243, 85, 134))) {
        		gdrts_posts_render_rating(array('echo' => true));
    		} 
    ?>
    #2292517
    Fernando
    Customer Support

    I see. Thank you.

    If that’s the case, you don’t need a child theme or code snippets for that.

    You can add the code through a Hook Element: https://docs.generatepress.com/article/hooks-element-overview/

    Enable “Execute PHP” and hook it to somewhere like generate_after_entry_title.

    Reference to some available hooks: https://docs.generatepress.com/article/hooks-visual-guide/

    Kindly let us know how it goes.

    #2292524
    Art

    Thanks so much Fernando, I will give that a try.

    #2292528
    Art

    I created the hook but I see this message after Execute PHP “Unable to execute PHP as DISALLOW_FILE_EDIT is defined.”. I see this underneath the post title true)); } ?>

    Link here: https://mlrstage.wpengine.com/1-to/1-revolution-music/

    #2292532
    Fernando
    Customer Support

    Check your wp-config file in your FTP, and remove define( ‘DISALLOW_FILE_EDIT’, TRUE ); if there is one.

    Hope this clarifies.

    #2292565
    Art

    It’s already commented out with #. Shouldn’t that be the same as removing?

    #2292567
    Fernando
    Customer Support

    Yes, that should be the same thing.

    Are you using a Security Plugin? Can you check if it’s causing the issue?

    If not, can you try adding this through Code Snippets?: https://docs.generatepress.com/article/generate_hooks_execute_php/

    #2292945
    Art

    The only plugins that I think could be a problem are Stop Spammers and Stop User Enumeration. I deactivated both of those created the snippet add_filter( 'generate_hooks_execute_php', '__return_true' ); in the Code Snippets plugin and define( ‘DISALLOW_FILE_EDIT’, TRUE ); is commented out, but still the same problem. I am checking the results in a Private window in FireFox.

    #2292968
    David
    Staff
    Customer Support

    Hi there,

    if you just add this:

    add_filter( 'generate_hooks_execute_php', '__return_true' );

    to your Code Snippets.

    When you create a Hook Element – can you now check the Execute PHP button without the warning ?

    #2292993
    Art

    Ahhhh, that did it! The error went away in the hook element and I checked the box to Execute PHP.

    I’ve been building rudimentary web sites since the early 90s but this stuff is new territory for me. I always say I know enough to be dangerous, hah!

    Thanks again to both you and Fernando for exercising my brain cells. 🙂

    #2293177
    David
    Staff
    Customer Support

    Glad we could be of help!

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.