Support » Plugin: teachPress » Image Shortcode in Post

  • Is there a way to display an image by shortcode in an automatically generated post from a publication? So to integrate the picture automatically in the contribution template?

    greetings
    Guenni

    [tpsingle [key]]<!--more-->
    
    [tpabstract]
    
    *Picture Here*
    
    [tplinks]

    WordPress 4.8.1
    teachPress 6.1.0

    • This topic was modified 3 months, 1 week ago by  guennionline.
Viewing 1 replies (of 1 total)
  • Plugin Author winkm89

    (@winkm89)

    Hi,

    The following code should add an [tppubimage] shortcode. You can add the code to the functions.php of your theme or create a new plugin with it:

    
    /** 
     * Shortcode for displaying the image of a single publication
     * 
     * possible values of $atts:
     *      id (INT)        id of a publication
     *      key (STRING)    bibtex key of a publication 
     * 
     * If neither is given, the publication of the most recent [tpsingle] will be reused
     * 
     * @param array $atts
     * @return string
    */ 
    function tp_pubimage_shortcode ($atts) {
        global $tp_single_publication;
        $param = shortcode_atts(array(
           'id' => 0,
           'key' => '',
        ), $atts);
    
        $publication = tp_shortcodes::set_publication($param, $tp_single_publication);
    
        if ( isset($publication['abstract']) ) {
            return '<img src="' . tp_html::prepare_text($publication['image_url']) . '" alt=""/>';
        }
        return;
    }
    
    add_shortcode('tppubimage', 'tp_pubimage_shortcode');
    
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.