How to use wordpress function wp_enqueue_script() in php?

I am wondering if that is the right way to use wp_enqueue_script() function in php. Do I need to place wp_enqueue_script() somewhere else ? Not really, here’s what the official docs say in the notes: https://developer.wordpress.org/reference/functions/wp_enqueue_script/ The function should be called using the wp_enqueue_scripts action hook if you want to call it on the front-end … Read more

WordPress REST API register_rest_route give a 500 error

Revised answer To other readers, another issue was the OP used the wrong route. So make sure to make the API request to the correct route, which is a combination of the first two parameters for register_rest_route() (namespace + route base). So with register_rest_route( ‘uheme/v1’, ‘/menu’ ), the route is uheme/v1/menu. Additionally: With permalinks enabled, … Read more

PHP Notice: Undefined offset: -1 – Navigation Previous/Next

It depends on number of things how you want to design, if this is the first post, does it still have previous class? Some design create loops, first post previous will go to the last post like a loop, some design does not display the previous button if it is the first one. the design … Read more

Login redirect. Check user meta and redirect accordingly

woocommerce_login_redirect is similar to login_redirect and it has a users parameter. That means you don’t have to use get_current_user_id() (which was returning 0 when I tested it). Instead, replace get_current_user_id() with $user->ID;. For example: function redirect_login_to_tos($redirect, $user) { $user_id = $user->ID; $checkout_tos2 = get_user_meta($user_id, ‘checkout_tos2’, true); $checkout_tos3 = get_user_meta($user_id, ‘checkout_tos3’, true); if($checkout_tos2 != ‘agreed’ || … Read more

Connecting to another server database from the wordpress plugin

I have the similar thoughts as Himad on the solution, let me elaborate. Basically you need the following: Code an script that connects to your database directly. This is an independent script outside of the WordPress plugin. Host the script on your server. The script will take requests for data and provide response with the … Read more

How to unlink all posts from tracking same amount of views

Use this in the loop: getPostViews(get_the_ID()); instead of: bac_PostViews(get_the_ID()); So your loop should be like this: <?php $catquery = new WP_Query(array( ‘meta_key’ => ‘post_views_count’, ‘orderby’ => ‘meta_value_num’, ‘posts_per_page’ => 5, ‘cat’ => ’52’, )); ?> <ol class=”topheadlines”> <?php while($catquery->have_posts()) : $catquery->the_post(); ?> <!– display view count –> <?php if(function_exists(‘getPostViews’)) { echo getPostViews(get_the_ID()); }?> <div class=”row”> … Read more

PHP-warning in post-template.php and no loading content on pages

The problem was that the loop related code had been removed from the template file by a mistake without me knowing. I had to add this back in: <?php if (have_posts()): while (have_posts()) : the_post(); ?> and <?php else: ?> <h2><?php _e( ‘Sorry, nothing to display.’, ‘html5blank’ ); ?></h2> <?php endif; ?>

How set a custom URL for a new theme file in WP?

You cannot directly create index111.php go to mysite.com/index111. Because the WordPress loading principal is like the following explanation. You could do similar things with custom templates but not exactly the index111.php. Also, it is assumed that you use permalinks too. WordPress loading method Because WordPress is running a query based system. That’s means, basically it … Read more