Pages should have priority when using add_rewrite_rule

If I understand you correctly, you could try to replace: add_rewrite_rule( ‘^prefix-(.*)’, ‘foo/bar/index.php?page=$matces[1]’, ‘top’ ); with add_rewrite_rule( ‘^prefix-(.*)’, ‘foo/bar/index.php?page=$matces[1]’, ‘bottom’ ); From the Codex: ‘top‘ will take precedence over WordPress’s existing rules, where ‘bottom‘ will check all other rules match first. Default: “bottom“

Insert width & height attributes to all images displayed on each page

Tested and confirmed that this works: add_filter( ‘the_content’, ‘add_image_dimensions’ ); function add_image_dimensions( $content ) { preg_match_all( ‘/<img[^>]+>/i’, $content, $images); if (count($images) < 1) return $content; foreach ($images[0] as $image) { preg_match_all( ‘/(alt|title|src|width|class|id|height)=(“[^”]*”)/i’, $image, $img ); if ( !in_array( ‘src’, $img[1] ) ) continue; if ( !in_array( ‘width’, $img[1] ) || !in_array( ‘height’, $img[1] ) ) … Read more

Disabling post images for not logged in users

You can use PHP strip_tags and hook to the_content filter by checking if user is logged in. add this to your functions.php file add_filter( ‘the_content’, ‘wpse_remove_img’ ); function wpse_remove_img( $content ){ if( ! is_user_logged_in() ){ // You need to specify which tag you want to keep here it’s p, a, h2,span, div. // Adjust accordingly … Read more

Why functions.php file is called 8 time for just one page load?

Add a plugin like Kint Debugger + Debug Bar and add the following code to your functions.php. global $wp; ob_start(‘kint_debug_ob’); d($wp); ob_end_flush(); When you check the Debug Bar you should see the backtrace which will tell you which order functions were fired in. Loading 8 times is quite high for a single request. There is … Read more

Need to get specific data from array

You should be able to rewrite what you have about and also use get_permalink as @Benoti stated while omitting the $split array. get_permalink accepts either the Post ID or a post object. global $rental; $images = get_children( array( ‘post_parent’ => $rental_id, ‘post_status’ => ‘inherit’, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘order’ => ‘ASC’, ‘orderby’ => … Read more

Get posts using WP_Query

It’s quite some time since I worked with WordPress, but it seems to me that: You’re executing the query twice. First when you pass $args to the constructor during instantiation. Second when you call query(). With this, you’re essentially overwriting the first query (the one that contains the orderby=rand). The documentation of WP_Query mentions that … Read more