- This topic has 12 replies, 3 voices, and was last updated 3 years, 9 months ago by
David.
-
AuthorPosts
-
July 24, 2022 at 6:32 pm #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.
July 24, 2022 at 6:44 pm #2292513Fernando 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.
July 24, 2022 at 6:51 pm #2292515Art
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)); } ?>July 24, 2022 at 6:58 pm #2292517Fernando 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.
July 24, 2022 at 7:28 pm #2292524Art
Thanks so much Fernando, I will give that a try.
July 24, 2022 at 7:45 pm #2292528Art
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/
July 24, 2022 at 7:56 pm #2292532Fernando Customer Support
Check your
wp-configfile in your FTP, and removedefine( ‘DISALLOW_FILE_EDIT’, TRUE );if there is one.Hope this clarifies.
July 24, 2022 at 9:25 pm #2292565Art
It’s already commented out with #. Shouldn’t that be the same as removing?
July 24, 2022 at 9:32 pm #2292567Fernando 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/
July 25, 2022 at 6:37 am #2292945Art
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 anddefine( ‘DISALLOW_FILE_EDIT’, TRUE );is commented out, but still the same problem. I am checking the results in a Private window in FireFox.July 25, 2022 at 7:01 am #2292968David
StaffCustomer SupportHi 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 ?
July 25, 2022 at 7:32 am #2292993Art
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. 🙂
July 25, 2022 at 8:06 am #2293177David
StaffCustomer SupportGlad we could be of help!
-
AuthorPosts
- You must be logged in to reply to this topic.