Site logo

Archived topic

Should I use Child Theme or Code Snippets?

12 replies · Started by Art on July 24, 2022

Viewing posts 1–13 of 13

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.

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.

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));
		} 
?>

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

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

Hope this clarifies.

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

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.

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 ?

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. :-)

Glad we could be of help!

This archived topic is closed to new replies.