Display a post by ID attribute with shortcode

Try $HTML instead of $html Linux based systems are case-sensitive … function post_banner_shortcode($atts) { $atts = shortcode_atts( array( ‘id’ => ” ), $atts ); $post_id = $atts[‘id’]; $HTML = ‘<div class=”postbanner”>’; $HTML .= ‘<div class=”pb-thumb”>’ . get_the_post_thumbnail($post_id, ‘medium’) . ‘</div>’; $HTML .= ‘<div class=”pb-ttl-txt”>’; $HTML .= ‘<h4>’ . get_the_title($post_id) . ‘</h4>’; $HTML .= ‘<p>’ . … Read more

Templating of a specific post ID

You have to follow this file name structure: single-{post-type}-{slug}.php If you have a post names “Hello World” and the slug of post is hello-world then the template name will be single-post-hello-world.php Update: There is no default way to use id in template name. But you might try this snipped: <?php add_filter( ‘single_template’, ‘load_post_template_by_id’ ); function … Read more

Limit Gutenberg blocks available to users to choose from

In the functions.php file I added add_filter( ‘allowed_block_types_all’, ‘func_allowed_block_types’ ); function func_allowed_block_types( $allowed_blocks ) { return array( ‘core/embed’ ); } Then in my plugin I added this JS to the javascript file to enable only the embed blocks I wanted (Twitter, youTube and Vimeo) wp.domReady( function() { const allowedEmbedBlocks = [ ‘twitter’,’youtube’, ‘vimeo’ ]; wp.blocks.getBlockType( … Read more

Exclude posts w/ specific post_meta on Rest API endpoint

Caveat From the REST API docs: Changing or removing data from core REST API endpoint responses can break plugins or WordPress core behavior, and should be avoided wherever possible. That said, there’s a rest_post_query filter (well, rest_{$this->post_type}_query) that will let you modify the WP_Query that’s grabbing your posts, so you should be able to add … Read more

Server-side sorting of posts

The display of posts is controlled by WordPress Loop. It has a lot of possible arguments, but they are rarely exposed in URL (especially if using pretty permalinks). But it is possible to make use of arguments by manually adding them to URL. For sorting see Orderby Parameters. Your example would be something like: domain.com/?orderby=date … Read more

WordPress blog post cloned and stolen?

Yes, they can. There is nothing strange or technically complex about that. And before you ask – no, it’s pretty much unrealistic to protect public web page from being copied. My process to deal with such goes roughly like this: Contact blog owner and point out that your posts are not meant to be copied … Read more

How to pull blogposts using shortcodes

paste this code in your theme’s functions.php file function custom_query_shortcode($atts) { // EXAMPLE USAGE: // [loop_shortcode the_query=”showposts=100&post_type=page&post_parent=453″] // Defaults extract(shortcode_atts(array( “the_query” => ” ), $atts)); // de-funkify query $the_query = preg_replace(‘~&#x0*([0-9a-f]+);~ei’, ‘chr(hexdec(“\\1″))’, $the_query); $the_query = preg_replace(‘~&#0*([0-9]+);~e’, ‘chr(\\1)’, $the_query); // query is made query_posts($the_query); // Reset and setup variables $output=””; $temp_title=””; $temp_link = ”; $temp_ex = … Read more