Can’t extend some core classes

You can extend it, but the class definition and any code that uses it, can’t run outside of the admin area. Wrap your class in this conditional: if ( is_admin() ) { … } If you are trying to use this on the frontend or other non-Admin areas, do not do that. Generally, classes WordPress … Read more

Open Post Thumbnail in New Child Theme File in WordPress

As mentioned in the comments, neither single-thumbnail.php or single-ad.php will work in a simple manner. Sure a complex solution/workaround could be written but it’s totally unnecessary. The template hierarchy in WordPress doesn’t work that way. Whatever follows single- in a single-XXXXX.php file is used to denote the content type/post type. So the single-ad.php would only … Read more

Create shortcodes within foreach loop (using array)

Solved issue of dynamic function name by using $shortcode var as function name foreach ($shortcodes as $shortcode) { add_shortcode($shortcode, function ($atts) use ($shortcode) { $filepath = str_replace(‘_’, ‘-‘, $shortcode); ob_start(); require_once(get_stylesheet_directory() . ‘/template-parts/’ . $filepath . ‘.php’); return ob_get_clean(); }); }

Use object in template part

As of WordPress 5.5 you can pass variables to template parts by passing them in an array to the third argument of get_template_part(): foreach ($categories as $category) { get_template_part( ‘temp-parts/loop/blcnr_loop’, null, [ ‘category’ => $category ] ); } These variables will populate an $args variable accessible from the the template: echo $args[‘category’]->name;

Randomise upload filenames (or another solution to hide the original image URL from theft?)

Where am I going wrong? Actually, your code is just fine. Except that I would simply use wp_generate_password() to generate the random string. 🙂 WordPress will still think that the scaled version is called painting-scaled.jpg , etc. Resulting in broken images. Yes, that’s correct. Images are stored as posts of the attachment type in the … Read more

How to update wp-config file in Docker

The Solution that finally worked was to turn down the containers using docker-compose down command. I was not detaching the containers, but I still need to turn them down. Once I did so, I then run the command docker volume ls to list all the volume and delete the one with WordPress data in it … Read more

Custom query to filter posts that have current post as a taxonomy [closed]

I made it through! I’ll share how I did in case some other person lacking the php knowledge like me lands in the same spot. add_action(‘elementor_pro/posts/query/projects_designs_query’, function($query) { $post_id = get_the_ID(); $meta_query[] = [ ‘post_type’ => ‘designs’, ‘taxonomy’ => ‘projects’, ‘value’ => $post_id, ‘compare’ => ‘in’, ]; $query->set( ‘meta_query’, $meta_query ); } ); What this … Read more

how can i show only the parents in owl-carousel?

According to the documentation, you would have to use post_parent => 0 So your code would look like this: <div class=”owl-carousel owl-theme”> <?php $c = 0; $q2 = new WP_Query( array( ‘post_type’ => array( ‘post’, ‘book’ ), ‘post_status’ => ‘publish’, ‘post_parent’ => 0, //add this here ‘orderby’ => ‘modified’, ‘order’ => ‘desc’ ) ); while … Read more