ACF not showing

the_field() function shows the value and it doesn’t get/return anything. Like the_title() and other template tags starting with the_. It means that: This line prints the value and $hero variable is empty. $hero = the_field(‘hero_title’); This line prints only <h1> tags. echo ‘<h1>’.$hero.'</h1>’; What you want is: echo ‘<h1>’ . get_field(‘hero_title’) . ‘</h1>’;

enqueue_script with filemtime javascript not working

wp_register_script() function is accepting the 5 parameters. You are passing the 6 parameter. So replace the wp_register_script( ‘lib’, get_template_directory_uri().’/js/lib.js’, array(), filemtime(get_template_directory() . ‘/js/lib.js’), null, ‘all’ ); WITH wp_register_script( ‘lib’, get_template_directory_uri().’/js/lib.js’, array(), filemtime(get_template_directory() . ‘/js/lib.js’), true );

How to use selected WordPress functions?

You may be able to have WordPress push data to the session or to your custom PHP, rather than trying to load WordPress each time you need to query some the user. I’m not sure what other functions you want to call. The alternative is to use the WordPress REST API, take a look at … Read more

How to get Post Type from the functions.php file

You have to create the function and call it when post ID is already set. Otherwise it will be empty. E.g. wp_head meets this requirement, init is too early. function my_selective_wpautop() { global $post; if( is_singular() ) { if( ‘page’ == $post->post_type ) { remove_filter( ‘the_content’, ‘wpautop’ ); } elseif ( ‘post’ == $post->post_type ) … Read more

allow only one post in specific category

After the post save (using save_post hook) you check if the saved post has your “unique” category, and if so remove the category from the other posts, keeping the one you just saved. add_action( ‘save_post’, ‘set_post_unique_category’, 10,3 ); function set_post_unique_category( $post_id, $savedPost, $update ) { // Only set for post_type = post if ( ‘post’ … Read more

Shortcode with PHP issue “Undefined index”

It’s because if the user enters large=”true”, then $atts[‘small’] isn’t defined. The normal solution is to use shortcode_atts() to set default values for the parameters, but you’re not putting the result of shortcode_atts() into $atts, you’re just just extracting it. This means that $small will be defined, but $atts[‘small’] won’t be. The proper way to … Read more

Is there a best practice remediation for PhpStorm’s warning that void function the_post_thumbnail is used?

The solution is simple, don’t echo the result of that function, there is no result to echo. echo the_post_thumbnail(array(155,55)); Is equivalent to something like this: echo ”; the_post_thumbnail(array(155,55)); Functions that begin with the_ in WP don’t return things, they output things. Some of them let you pass a parameter that lets them return instead, but … Read more

file_get_contents – failed to open stream

I agree that this is PHP rather than WP question. To bring it closer to WP I do suggest to take a look at following functionality: HTTP API is highly suggested for making HTTP requests; add_post_meta() and related meta functions to store post-specific information; the_shortlink() function, that is suggested template tag to use for natvie … Read more