In a plugin, How to update a json file using ajax

Here is your main problem: chemin = plugin_dir_url( __FILE__ ) . “inc/json/notes.json”; There are 5 critical mistakes in the code: file_get_contents requires a file path, but you’re asking for a URL by using plugin_dir_url, not all servers support remote URLs in file_get_contents for security reasons, and if they do, this would be a big performance … Read more

WordPress hide post from custom post-type on a single page

Instead of using the pre_get_posts hook simply modify your WP_Query to fetch posts with certain conditions. $loop = new WP_Query( array( ‘post_type’ => ‘projects’, ‘orderby’ => ‘rand’, ‘posts_per_page’ => 1, ‘meta_query’ => array( array( ‘key’ => ‘your_field_name’, ‘value’ => ‘the_value’ ), ), ) ); This, right from the beginning only fetches the posts that matches … Read more

Replace only the first CSS class

Not sure if a typo but in your question you say “replace the “thumb-w” CSS class with “thumb-w1” but in your code you have: $html = str_replace( ‘thumb-w’, ‘thumb-w 1’, $html); Should your code instead remove the space and be: str_replace( ‘thumb-w’, ‘thumb-w1’, $html);