Impossible to call wordpress function inside an include?

I’ve had this problem in past try using include with locate_template: I don’t exactly remember the reason but this code still works: Example: include(locate_template(YOUR_TEMPLATE_PATH)); Here’s a complete demonstration too, using the same idea, if you need more help. For Admin Panel include simply works in admin panel. You might want to modify your code like: … Read more

How to create an onclick event on an image in a post?

Without specifics, in general, the page code that is output is generated by your theme code. So you would need to look into the theme’s template that is used for that page. The template used is determined by the WordPress Theme Heirarchy , details are here: https://developer.wordpress.org/themes/basics/template-hierarchy/ ; take a look at the graphic which … Read more

Call to undefined function get_userdata() in plugin

Solution found: the reason was that the code including those lines were included in plug-in’s main file and were wrapped in the shortcode launch anymore. I had to put things in another file,like for example function load_shortcode( $atts ){ require_once(getPluginPath().(‘my-project.start.php’)); } add_shortcode( ‘my-project’, ‘load_shortcode’ ); and lines had to be in my-project.start.php getPluginPath() is NOT … Read more

php syntax : [ && ] between commands [closed]

I think its actually not allowed or discouraged in WP coding standards. Its is basically saying “If true go ahead”. It’s a short form of this: if ( did_action( ‘init’ ) ) { $scripts->add_inline_script( ‘lodash’, ‘window.lodash = _.noConflict();’ ); } You can also think of this as if it’s inside brackets of an if statement … Read more

How to load parent theme template parts in child theme

From the WordPress documentation on child themes (Referencing or Including Other Files): To reference the parent theme directory, you would use get_template_directory() instead. Therefore, in your child theme, you could include your parent template file like this: <?php include get_template_directory() . ‘/template_parts/layouts/profile/profile-modern.php’; ?>

Load scripts based on post type

If you hook onto a later action such as template_redirect, you should be able to check the query vars to determine if your specific post type is being viewed. add_action( ‘template_redirect’, ‘example_callback’ ); function example_callback() { if( is_single() && get_query_var(‘your-posttype’) ) wp_enqueue_script( .. your args .. ); } Or alternatively like this… add_action( ‘template_redirect’, ‘example_callback’ … Read more