Title: My first shorecode
Last modified: August 31, 2016

---

# My first shorecode

 *  [Hamlet_PL](https://wordpress.org/support/users/hamlet_pl/)
 * (@hamlet_pl)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/my-first-shorecode/)
 * Welcome,
    I try add my own shortcod to function.php in Hueman theme. Function
   doesn’t show any error but I no see any `<a href="...">`. Below i paste my code.
   Where I make a error?
 *     ```
       // ShowPrivateFile
       function ShowPrivateFile() {
       	ob_start();
       	$output='';
       	if ( is_page( 'login' ) ) {
       		$output = 'Pliki dostępne tylko po zalogowaniu:'.
                       '<a href="aaa.pl">abcd</a></br>'.
       		'<a href="aaa.pl">Faktura Klamki.JPG</a></br>'.
       		'<a href="aaa.pl">Faktura Wkladki Klucze.JPG</a></br>';
       	}
       	return $output;
       }
       add_shortcode("pokaz_prywatne_pliki", "ShowPrivateFile");
       ```
   
 * regards

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/my-first-shorecode/#post-6980816)
 * why are you using the `ob_start();` ?
 * [http://php.net/manual/en/function.ob-start.php](http://php.net/manual/en/function.ob-start.php)
 *  Thread Starter [Hamlet_PL](https://wordpress.org/support/users/hamlet_pl/)
 * (@hamlet_pl)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/my-first-shorecode/#post-6980907)
 * I found somewhere in the web simple code to make own shortcode. There was ob_start().
   Now I know that I needn’t do_start() but when after delete this element funstion
   still not show my links. What am I doing wrong?
 * I found one error. My page with shorecode is download not login.
 *     ```
       function ShowPrivateFile() {
       	$output='';
       	$allowed_roles = array('subskrybent2', 'subskrybent3', 'administrator');
       	if( array_intersect($allowed_roles, $user->roles ) ) {
       		$output = 'Pliki dostępne tylko po zalogowaniu:'.'<a href="https:">Protokół_z_zebrania_2015_11_15.doc</a></br>'.
       		'<a href="https:">KARTA_INDYWIDUALNEGO_GŁOSOWANIA.doc</a></br>'.
       		'<a href="https">Faktura Klamki.JPG</a></br>'.
       		'<a href="https">Faktura Wkladki Klucze.JPG</a></br>';
       	}
       	return $output;
       }
       add_shortcode("pokaz_prywatne_pliki", "ShowPrivateFile");
       ```
   
 * Still not working..
 *  Thread Starter [Hamlet_PL](https://wordpress.org/support/users/hamlet_pl/)
 * (@hamlet_pl)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/my-first-shorecode/#post-6980916)
 * I foreget
    `$user = wp_get_current_user();`
 * now is working
 * maybe for someone it’s helpful
 * regards
 *  [Alex Clemente](https://wordpress.org/support/users/netcentersv/)
 * (@netcentersv)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/my-first-shorecode/#post-6981098)
 * hi did you solve this?
 *  Thread Starter [Hamlet_PL](https://wordpress.org/support/users/hamlet_pl/)
 * (@hamlet_pl)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/my-first-shorecode/#post-6981154)
 * yes,
    u need paste this: $user = wp_get_current_user(); below output or func 
   declaration and before code:
 *     ```
       $allowed_roles = array('subskrybent2', 'subskrybent3', 'administrator');
       	if( array_intersect($allowed_roles, $user->roles ) )
       ```
   
 * like this:
 *     ```
       function ShowPrivateFile() {
       	$output='';
               $user = wp_get_current_user();
       	$allowed_roles = array('subskrybent2', 'subskrybent3', 'administrator');
       	if( array_intersect($allowed_roles, $user->roles ) ) {
       		$output = 'Pliki dostępne tylko po zalogowaniu:'.'<a href="https:">Protokół_z_zebrania_2015_11_15.doc</a></br>'.
       		'<a href="https:">KARTA_INDYWIDUALNEGO_GŁOSOWANIA.doc</a></br>'.
       		'<a href="https">Faktura Klamki.JPG</a></br>'.
       		'<a href="https">Faktura Wkladki Klucze.JPG</a></br>';
       	}
       	return $output;
       }
       add_shortcode("pokaz_prywatne_pliki", "ShowPrivateFile");
       ```
   
 * it should be work. Sorry but i not every day on computer now. I hope that help
   u
    best regard
 *  [Mr Case](https://wordpress.org/support/users/mr-case/)
 * (@mr-case)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/my-first-shorecode/#post-6981167)
 * when i use `ob_start();` i always finish with `return ob_get_clean();`
 *  Thread Starter [Hamlet_PL](https://wordpress.org/support/users/hamlet_pl/)
 * (@hamlet_pl)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/my-first-shorecode/#post-6981171)
 * thanks 🙂

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘My first shorecode’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 7 replies
 * 4 participants
 * Last reply from: [Hamlet_PL](https://wordpress.org/support/users/hamlet_pl/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/my-first-shorecode/#post-6981171)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
