Shortcodes and a list of IDs?

explode will be your best option. WordPress has a few built in functions to handle arrays of function arguments (wp_parse_args and shortcode_atts for example), but nothing relating to splitting a string and iterating the result. It’s not entierly clear to me what you are trying to achieve, but let’s say you were trying to get … Read more

Add htmlentities and/or shortcode into data-attributes

the_field echoes the output while htmlentities() expects the value to be returned. Try get_field instead: data-img=”<?php echo htmlentities(get_field(‘portfolio_galleries’)); ?>” UPDATE: Instead of adding this huge chunk of html for the slider to the data-attribute just add it after your image: <img src=”https://wordpress.stackexchange.com/questions/93587/<?php echo $large_image ?>” data-title=”<?php echo get_the_title(); ?>” data-description=”<?php the_content();?>” alt=”<?php echo get_the_title(); // … Read more

Shortcode for a link and thumbnail

You are assigning the attachment URL to your $url variable: $url = wp_get_attachment_url( get_post_thumbnail_id( $id ) ); then passing that same variable back to wp_get_attachment_url: return ‘<img src=”‘ . wp_get_attachment_url( $url ) . ‘”/><a href=”‘ . get_permalink( $id ) . ‘”>’ . get_the_title( $id ) . ‘</a>’; You should simply output it instead: return ‘<img … Read more

detect when shortcode ran for the last time

Not sure about the last time, but you can hijack every shortcode and either call wp_localize_script() here or register an action for wp_footer that runs earlier than the footer script handler. Let’s say, this is the original: add_shortcode( ‘foo’, ‘original_function’ ); Now you can overwrite it with: add_shortcode( ‘foo’, ‘new_function’ ); function new_function( $atts, $content=””, … Read more

unwanted P tags in shortcode, delay wpautop not working

The simple solution is to not give wpautop anything to chew on. function contact_us() { $str = “<p>Here’s the low down on what to do</p>”; $str .= ‘<link rel=”stylesheet” type=”text/css” href=”http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css”/>’; $str .= ‘<link rel=”stylesheet” href=”http://studiocloud.com/css/validationEngine.jquery.css” type=”text/css”/>’; // etc $return $str; } Your generated code won’t be formatted, but there is no reason it should … Read more

Add category attribute to custom shortcode

add_shortcode( ‘faq’, ‘wpse105856_shortcode_callback’ ); function wpse105856_shortcode_callback( $atts ) { extract( shortcode_atts( array( ‘category’ => ” ), $atts ) ); $args = array( ‘numberposts’ => -1, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘post_type’ => ‘faq’ )); if ( ! empty( $category ) ) { $args[‘category_name’] = $category; } $posts = get_posts( $args ); $faq = ‘<div … Read more

Creating a shortcode in a plugin that includes JS

Hook function name should be same. You are using “tweets” function name as a parameter for the add_shortcode() function but actual function name in your code is “tweet_code” so it should be “tweets” as shown in the following code. <?php add_shortcode( ‘tweet’, ‘tweets’ ); function tweets( $atts ) { $tweet_text = <<<‘EOD’ <!– Tweet JS. … Read more