How to escape html generate by a loop
This seems to have done the trick: // Display our list of font options $allowed_html = array( ‘option’ => array( ‘value’ => array(), ‘selected’ => array() ), ); echo wp_kses($fontListStr, $allowed_html);
This seems to have done the trick: // Display our list of font options $allowed_html = array( ‘option’ => array( ‘value’ => array(), ‘selected’ => array() ), ); echo wp_kses($fontListStr, $allowed_html);
The problem is that, you have added extra white space before wp_ajax action. remove space from actions ‘ wp_ajax_my_action’ and ‘ wp_ajax_nopriv_my_action’. because of extra space before ajax request, showing the 400 bad request error. You should use : add_action(‘wp_ajax_my_action’, ‘my_action’); add_action(‘wp_ajax_nopriv_my_action’, ‘my_action’);
Your menu name is not consistent. When you created the menu, you named it ‘header-menu’. But when you rendered it, you tried to render ‘top-menu’. ‘top-menu’ doesn’t exist; it needs to also say ‘header-menu’.
is_single() and is_singular() are not the correct functions to use here. Your comment mentions that this is being added to search.php, but is_single() and is_singular() will always be false on search.php, because those functions are checking if the current page is a single post or page, but search.php is not. It’s is a list of … Read more
<?php get_header() ?> <div class=”container-fluid”> <div class=”row”> <?php $i = 0; while ( have_posts() ) : the_post(); ?> <?php if ($i == 0 || $i % 4 == 0) : ?> <div class=”col-sm-12 blog”> <div class=”row”> <div class=”col-sm-8 p-0″> <?php the_post_thumbnail()?> </div> <div class=”col-sm-4 align-self-center”> <div><h3><?php the_title()?></h3></div> <div><?php the_excerpt()?></div> </div> </div> </div> <?php else: ?> … Read more
WordPress always queries a default set of posts when you view any sort of archive. So if you run your own query as described you’ll end up with 3 database queries instead of 1. You should not develop your template the way you describe. The standard WordPress templates should all use the default query. You’ll … Read more
No, this does not exist unless you fork WordPress, and those modifications will very likely compromise its security and give vey minimal gains to performance. There are projects out there that try to do this, but they’re not used by many, or as well maintained as WordPress Core. WordPress is not built as a core … Read more
You use the document_title_separator filter. So in your case: <?php function theme_prefix_filter_document_title_separator() { return ‘|’; } add_filter( ‘document_title_separator’, ‘theme_prefix_filter_document_title_separator’ ); ?>
Not sure what you’re trying to do, but the problem you’re having with this specific bit of code is that you’re using the wrong function. You want get_the_post_thumbnail() instead. The function the_post_thumbnail() echoes the result of get_the_post_thumbnail(). $args = array( ‘post_type’ => ‘post’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘posts_per_page’ => 1, ‘category’ => ‘2’, … Read more
One problem (there may be more 😉 is that $post->ID is probably out of scope when you call it from the page template. You could change the way the function works to take the post ID as a parameter, like this: function my_related_artickes($postID) { $categories = wp_get_post_categories( $postID ); $ids = array(); foreach( $categories as … Read more