Articles of shortcode

Custom shortcodes not working using __s theme

I’m trying to register a new shortcode on my custom theme. In functions.php I have created a basic test function as follows function get_second_image($atts) { echo ‘test’; } And registered it right underneath add_shortcode( ‘case_study_second_image_sc’, ‘get_second_image’ ); Using the WYSIWYG editor I insert the shortcode [case_study_second_image_sc] but it just displays as the raw code on […]

Add attribute to caption shortcode from custom attachment field

I want to add class to caption shortcode, pulled from custom attachment field. I add the field via: function add_img_class( $form_fields, $post ) { $form_fields[‘img_class_field’] = array( ‘label’ => __( ‘Image class’, ‘text-domain’ ), ‘input’ => ‘text’, ‘value’ => get_post_meta( $post->ID, ‘img_class_field’, true ) ); return $form_fields; } add_filter( ‘attachment_fields_to_edit’, ‘add_img_class’, 10, 2 ); function […]

Counting number of posts in a category and its sub categories and displaying result using shortcode

I am trying to create a shortcode to display the posts count in a category. I have successfully done this using this code: // Add Shortcode to show posts count inside a category function add_count_of_posts_in_category() { $term = get_term( 7, ‘category’ ); $count = $term->count; echo $count; } add_shortcode( ‘show-posts-count’, ‘add_count_of_posts_in_category’ ); However, this means […]

Shortcode parsed incorrectly because of heredoc

I have a post with something like this: [code] $foo = <<<EOT …. EOT; [/code] It gets converted to this by do_shortcodes_in_html_tags(): [code] $foo = <<<EOT …. EOT; [/code&#q3; Therefore, the shortcode doesn’t run. Is there a way to make this shortcode work correctly?

shortcode javascript not working on custom template file inside theme folder

I’m using WordPress social login plugin shortcode [wordpress_social_login]. I want to put it in custom template file inside theme directory. example: <?php /* Template Name: Social Login Page */ echo do_shortcode(‘[wordpress_social_login]’); so I create a blank page using this template, the rendering is ok but the button href become javascript:void(0); and it won’t redirect. i […]

UberMenu list current user's posts as menu items

I’m attempting to turn users‘ posts into menu items, without luck. Here’s what I have so far, but not working. I would like to use the Advanced custom content by adding a shortcode. add_shortcode( ‘current-posts’ , ‘ss_get_current_posts’ ); function ss_get_current_posts(){ global $current_user; get_currentuserinfo(); $author_query = array(‘posts_per_page’ => ‘-1′,’author’ => $current_user->ID); $author_posts = new WP_Query($author_query); while […]

Get an image's alt text in a shortcode using the image URL

I am creating a shortcode which looks like this: [hpLocationSquare locationimage=”…wp-content/uploads/2017/04/Enfielddetails.jpg” /] The locationimage attribute is the URL to an image in the media library. In my functions.php I have the following code: function hplocationsfn($atts, $content = null){ extract(shortcode_atts(array( ‘locationimage’=>” ), $atts)); return ‘<div class=”locationSquare”> <a href=”‘.esc_attr($locationlink).'”> <img src=”‘.esc_attr($locationimage).'” /> </a> </div><!– locationSquare –>’; } […]

Shortcodes not resolved in AJAX call response

I have a simple function, which returns the content of a page with the given pageID: function get_page_content(){ $id = $_REQUEST[‘id’]; $page_data = get_page($id); echo apply_filters(‘the_content’, $page_data->post_content); //echo do_shortcode($page_data -> post_content); wp_die(); } add_action( ‘wp_ajax_nopriv_get_page_content’, ‘get_page_content’ ); add_action( ‘wp_ajax_get_page_content’, ‘get_page_content’ ); But after an Update of WP and some Plugins the returned content still containes […]

Category attribute not working in custom shortcode

I have the following function written, the issue is when I set the category in my shortcode it ignores it and shows all posts from the custom post type. So it only sort of works. /*————————————————————– ## Resources Shortcode ————————————————————–*/ function resources_query( $atts ) { extract(shortcode_atts(array( ‘category’ => ”, ‘per_page’ => -1, ‘orderby’ => ‘date’, […]

Shortcode displays always first. Once again

OK, I’ve had a problem with echoes in my last shortcodem, but everything works fine now. But I have another one: function myWidget_shortcode( $atts ) { extract( shortcode_atts( array( ‘title’ => ‘My Widget’, ‘value’ => ‘5’, ), $atts ) ); return the_widget(myWidget,’title=’.$title.’&value=’.$value); } add_shortcode(‘myWidget’, ‘myWidget_shortcode’); Can you tell me wy this shortcode always displays first […]