• 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)
  • why are you using the ob_start(); ?

    https://php.net/manual/en/function.ob-start.php

    Thread Starter Hamlet_PL

    (@hamlet_pl)

    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

    (@hamlet_pl)

    I foreget
    $user = wp_get_current_user();

    now is working

    maybe for someone it’s helpful

    regards

    hi did you solve this?

    Thread Starter Hamlet_PL

    (@hamlet_pl)

    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

    when i use ob_start(); i always finish with return ob_get_clean();

    Thread Starter Hamlet_PL

    (@hamlet_pl)

    thanks ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘My first shorecode’ is closed to new replies.