php esc_html_e with an html link inside not working

The point of esc_html is to ensure that the end result is plaintext, no HTML tags or scripts etc, just plaintext. The __ part passes it through the localisation API, and the e indicates it will echo on its own. So what you are seeing is expected and normal. Instead, you will need to make … Read more

I have a snippet to redirect all users to a maintenance page. How do I exclude users with admin role?

I would advise againt using anonymous functions for callback (when ever you can) as you can’t use a targeted remove_action on it. What Maythan8 answered will work but it can be done with fewer functions. add_action(‘template_redirect’, ‘bt_maintenance_redirect’); function bt_maintenance_redirect () { if (is_page(4848) || current_user_can(‘administrator’)) return; if (wp_safe_redirect(esc_url(home_url(‘maintenance/’)))) exit; } You used esc_url_raw but this … Read more

Is there a way to create two template for single custom post type page?

I think you need to work on thetemplate_include hook. https://developer.wordpress.org/reference/hooks/template_include At this point you can add a condition and returning the correct template path add_filter( ‘template_include’, ‘redirect_single’ ); function redirect_single( $template ){ if($_POST[‘template’] == ‘gallery’) { $template = path/to/your/template; }elseif($_POST[‘template’] == ‘other’){ $template = path/to/your/template; } return $template; }

set post limit at load more ajax wordpress

Something v basic might look like this var ppp = 9; var loaded = ppp; var maxPosts = 50; postData.append( ‘action’, ‘loadmore’ ); postData.append( ‘paged’, section_posts ); postData.append( ‘posts_per_page’, ppp ); if ( loaded < maxPosts ) { // check if we’re below the max post number const xhr = new XMLHttpRequest(); xhr.open( ‘POST’, ajaxurl … Read more

Can’t retrieve element with WordPress default @fetch_rss();

I suggest you to use fetch_feed() instead. Example: $rss_feed = fetch_feed( ‘https://canpl.ca/feed/rss2/’ ); if ( ! is_wp_error( $rss_feed ) ) { echo ‘<ul>’; foreach ( $rss_feed->get_items( 0, 5 ) as $item ) { $enclosure = $item->get_enclosure(); $enc_url = $enclosure ? $enclosure->get_link() : ‘No enclosure found’; echo ‘<li>’ . $item->get_title() . “<br>Enclosure URL: $enc_url</li>”; } echo … Read more

calling a custom field value inside functions.php

if you’re not planning on adding much html there is no need to use ob_start just return the php: function wpb_description_shortcode( ){ if (get_post_meta(get_the_ID(), ‘song_number’, true)) { return get_post_meta(get_the_ID(), ‘song_number’, true).'<br/>’; } else { return; } } // Register shortcode add_shortcode(‘my_description_number’, ‘wpb_description_shortcode’); I’m not sure what this data is, but it would be a good … Read more

I need to add a filter to prepend the term ‘National – ‘ to the post title if the post is tagged to multiple states

Your “states” appear to be terms in a custom taxonomy. In the code below I’ve assumed the taxonomy’s name is my_state; you’ll need to make sure that’s updated to match the actual taxonomy name. add_filter( ‘the_title’, function( $title, $id ) { // Gets the list of ‘states’ the post belongs to. $states = wp_get_post_terms( $id, … Read more