Add a plugin before main container

it looks like you’re using shortcode to execute your plugin. so instead of just echo ‘[plugin id=”1″]’; use this: echo do_shortcode(‘[plugin id=”1″]’); put this in the php file where you want it to load. For example, right above the <div id=”content”> this can be in whatever file you wish to execute the shortcode

Debugging with functions.php

You can use var_dump() instead of print_r() – you get the type and the value of the variable and it will also work when your variable holds FALSE or NULL. print_r( false ); # doesn’t output anything var_dump( false ); # output: bool(false) print_r( NULL ); # doesn’t output anything var_dump( NULL ); # output: … Read more

Pass parameters to function through an action

add_action() and add_filter() take 4 params: string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1. So, the function you are hooking to takes more than 1 param, then just pass the number of params it accepts as the 4th param to add_action(). In your case, add_action (‘my_action’, ‘my_function’, 10, 2) ;

Is It wrong to use oop approach on functions.php?

As described in the Child Themes entry in the codex: TIP FOR THEME DEVELOPERS. The fact that a child theme’s functions.php is loaded first means that you can make the user functions of your theme pluggable —that is, replaceable by a child theme— by declaring them conditionally. if ( ! function_exists( ‘theme_special_nav’ ) ) { … Read more

How to insert a text in all pages and posts before or after specific places?

You can add to before or after the content as well in a similar fashion. I use this code: function rt_before_after($content) { $beforecontent=”This goes before the content.”; $aftercontent=”And this will come after.”; $fullcontent = $beforecontent . $content . $aftercontent; return $fullcontent; } add_filter(‘the_content’, ‘rt_before_after’); You could use it similarly with the_title,. The reko_hook() you have … Read more

Include a php file from functions.php only to homepage

You can use is_home() or is_front_page() to check the current page. $sage_includes = [ ‘lib/assets.php’, // Scripts and stylesheets ‘lib/theme_options.php’, // Theme Options ‘lib/setup.php’, // Theme setup ‘lib/titles.php’, // Page titles ‘lib/wrapper.php’, // Theme wrapper class ‘lib/shortcodes.php’ // Old Theme Shortcodes ]; if(is_home() || is_front_page()){ $sage_includes[] = ‘lib/home_shortcodes.php’; // Homeapage Shortcodes }

How to call a function on particular page like ‘contact-us’ from function.php of child theme

The problem is that you’re trying to use is_page(), a conditional function intended only to run adjacent to the query, too early. Try running your code inside a callback that 1) only fires on the front-end, 2) fires after the page has partially loaded. For instance, wp_head. function prefix_run_on_contact_us() { if( is_page(‘contact-us’)) { echo “hello … Read more