how to enqueque code in a php file from functions.php

If that is the sum of the code for that file then the only place near the bottom is that do_action— do_action( ‘shiroi_after_post_body_content’ );— which looks to be what you want. function test_new_action() { echo ‘Howdy’; } add_action(‘shiroi_after_post_body_content’,’test_new_action’); Depending upon how this file is included there might be other hooks. You can’t add code to … Read more

Writing editor content to a file

You should hook save_post instead of publish_post. publish_post only runs when a post is initially published and won’t catch subsequent saves. Additionally, the publish_post hook passes parameters to your function and those should be used to retrieve info about the post being published rather get_the_content(), which only works when you’re inside the loop. I think … Read more

How to register a menu based on a ACF condition

Ok, so the problem was that I was adding the variable outside the function. After some cleanup, code looks like this and it works! function roots_setup() { // Variables $header_type = get_field(‘header_type’,’options’); if (($header_type)==’brand-centered’) { register_nav_menus(array( ‘brand_centered_left’ => __(‘Brand Centered Navigation (Left)’, ‘roots’) )); register_nav_menus(array( ‘brand_centered_right’ => __(‘Brand Centered Navigation (Right)’, ‘roots’) )); } else … Read more

wp_nav_menu work in functions.php but not in the theme

I had a pre_get_posts. What I missed was this: && $wp_query->is_main_query() This prevents the pre_get_posts to run on the menu query. Full code add_action(“pre_get_posts”, “custom_front_page”); function custom_front_page( $wp_query ){ if( is_admin() ) { return; } if( is_front_page() && $wp_query->is_main_query() ) { $wp_query->set(‘post_type’, ‘produkt’); $wp_query->set(‘page_id’, ”); $wp_query->is_page = 0; $wp_query->is_singular = 0; $wp_query->is_post_type_archive = 1; $wp_query->is_archive … Read more