How to: Conditionally Enqueue JS and Stylesheets, for Custom Post Type (Single and Archive Templates)

Try using is_post_type_archive() and is_singular(): // … if ( is_post_type_archive( ‘my-post-type’ ) || is_singular( ‘my-post-type’ ) ) { // your enqueue code goes here } // … These functions will check to see if you’re on, respectively, an archive page for the post type my-post-type or a single my-post-type post. (Change the my-post-type to what … Read more

Most commented posts by time period (last 12h, last 24h and etc)

So if you want to get the posts that were commented within the last xx hours, e.g. 12 hours, then try one of the following: Note though, I’m selecting only published posts (post_status=”publish”) and of the post type (post_type=”post”). And just replace the value of $hours with your preferred number of hours. Using TIMESTAMPDIFF(). $hours … Read more

Referencing Images in javascript to display on wordpress page

The problem is that you are trying to use PHP inside a javascript file. PHP only works inside .php files. If you want to pass information to your javascript file from PHP, use wp_localize_script to store it in a variable, e.g. in a PHP file: $values = array( ‘foo’ => ‘bar’, ); wp_localize_script( ‘yourscripthandle’, ‘objectname’, … Read more

WordPress query undefined offset in loop

There might be other causes to the issue in question, but one issue I noticed in your code is that because you are looping through a custom WP_Query instance, i.e. $loop, then you need to use $loop->the_post() instead of just the_post(): while ( $loop->have_posts() ) { $loop->the_post(); the_title(); } And you could see that I … Read more

Fixing Deprecated: get_the_author_lastname

Note: I’m not simply giving you the full fixed code, but the line in which you need to make the changes is the one with the <span class=”Z3988″ …>. So yes, both get_the_author_firstname() and get_the_author_lastname() have been deprecated and as said in the error, you should instead be using get_the_author_meta(). And in the coinsify_the_content() function, … Read more

Large WordPress CRON job

I can’t schedule (I don’t know how I should do it) separately CRON jobs because I had a few situations when some function was run before I have necessary data The key to doing this is scheduling the first job to run daily at the required time, and have that event create all of the … Read more

Redirect first comment (Thanks for comment) with show Autor name and beginning of the comment

You should be able to do something like this: add_filter( ‘comment_post_redirect’, ‘custom_comments_redirect’, 10, 2 ); function custom_comments_redirect( $location, $comment ) { $comment_id = $comment->comment_ID; $custom_url=”https://example.com/thank-you/?comment=” . $comment_id; return $custom_url; } And on the “Thank you” page, you can get the comment info like this: // Make sure you sanitize the GET input $comment_id = (int) … Read more

How to edit HTML of my website on WordPress? [closed]

The HTML of a WordPress page is a mix of many sources. Parts of it come from plugins, other parts from the main template, others from the database, others from the core. They can also come from widgets, template options, and so on. Unfortunately, WordPress pages are not on specific files that you can open … Read more

Custom shortcode for displaying user based on a role parameter

First, you’ll have to get shortcode parameter(s). Change function’s declaration to: function display_user_roles( $atts ) { Your shortcode will be either [hw_display_users] or [hw_display_users role=”roletopass”]. The first (no parameter) will use role specified in $args array. Second will replace $args->role with parameter passed. Add if ( !empty( $atts[‘role’] ) ) $args[‘role’] = $atts[‘role’]; before $users … Read more