How to choose the content from a post which is in the right category?

You can use the function in_category to test if a post is in a certain category. It takes one or more categories and the post as input. So you may differentiate your function like this: function title_content($atts, $content = null ) { global $wpdb; $post_id = $wpdb->get_var($wpdb->prepare(“SELECT ID FROM {$wpdb->posts} WHERE post_title = %s”,$content)); $getpost … Read more

Add the_post_thumbnail_url to a shortcode in function.php

I think you’re just printing your function as a string, try concatonating: add_action( ‘woocommerce_product_meta_end’, ‘childReview’ ); function childReview() { global $post; echo do_shortcode(‘[cl-popup size=”l” title=”Click!” btn_label=”Headline” btn_bgcolor=”#006982″ btn_color=”#ffffff” overlay_bgcolor=”rgba(0,105,130,0.75)” title_textcolor=”#006982″ content_textcolor=”#006982″]<img src=”https://wordpress.stackexchange.com/questions/235313/” . wp_get_attachment_url ( get_post_thumbnail_id( $post->ID ) ) . ‘”/> [/cl-popup]’); }

Need 2 separate elements of add_shortcode for presentation

You might want to declare arguments for shortcodes. Here is documentation, and things you need to improve in your code to make it work. Change function show_game_category_images_func() to function show_game_category_images_func($atts) Add following code at the top of your function: $a = shortcode_atts( array( ‘id’ => ‘1’, ), $atts ); Now inside $a[‘id’] is value passed … Read more

wp_localize_script not passing the data

As it stands, your shortcode will be executed after wp_enqueue_scripts — when the post content is output. That’s why the data isn’t available to your scripts during wp_enqueue_scripts for wp_localize_script. wp_enqueue_script( string $handle, string $src = false, array $deps = array(), string|bool|null $ver = false, bool $in_footer = false ) You would; A) Need to … Read more

Shortcode to return single custom post based on post taxonomy

From your supplied info, it’s not all very clear to me. But as far as I’ve understood your problem, here’s my approach. Assuming we have the following shortcode that the user has put inside a normal post’s content and that this shortcode will pull information from your custom post type case_studies: [casestudy study_type=”mountain”] So firstly, … Read more

Theme Convert PHP code to shortcode

This should do it, I used output buffering with ob_start() and ob_get_clean: <?php /** * Breadcrumbs based on theme’s functions * * @author Nabil Kadimi <[email protected]> * @link http://wordpress.stackexchange.com/a/242547/17187 */ add_action( ‘init’, function() { add_shortcode( ‘mycrumbs’, function() { /** * Start capturing output. */ ob_start(); ?> <div class=”x-breadcrumb-wrap”> <div class=”x-container max width”> <?php x_breadcrumbs(); ?> … Read more