Return Functions

Hi there,

here some help for those, who like me, like some static visuals :yum:

The return functions can be found in multiple spots in Cwicly, but their purpose is the same.

I will demonstrate here a simple example by using a heading block.

  1. Adding a return_function via the Dynamic Inserter:

  1. Adding the function in your preferred code or snippet editor:

// my custom return_function calls

function my_unique_function_name(){
	$myAwesomeVariable = 'Some Awesome Text To Display!!!';
	return $myAwesomeVariable;
}
  1. Watching the result unfold:

grafik

  1. Getting creative:

// my custom return_function calls

function my_unique_function_name($postID){
	// or do something with the id
	$myAwesomeVariable = '|| Some Awesome Text To Display!!! for the Post ID: ' . $postID . ' || ';
	return $myAwesomeVariable;
}

Step by Step Tutorial
  1. Going in the backend and opening 3 pages.
  • A page where we want to use the return_function, in this case the sample page of WP RED and the view of the page so we can see whats happening BLUE.
  • The third page is your preferred code/snippet editor. This is not necessary, but it is usually easier and safer than the Wordpress file editor, which you can find under Tools β†’ Theme File Editor β†’ (right side) functions.php BLUE.

    grafik
  1. Maybe clean up the navigator a little and created a heading. Now, by selecting the heading block you get the menue where you should be able to select the Dynamic Inserter option RED and then scroll down in the list to the Return Function BLUE.
  • If you don’t see the Dynamic Inserter option RED, check if you have any Dynamic Values green selected and remove them BLUE! Now you should be able to see the Dynamic Inserter option.
    grafik
  1. To add your function to the return_function, select the return= RED, that popped up and add your unique function name ending with the brackets no semicolon is needed. I used my_unique_function_name() BLUE for my function.
  • Note that you can type the function directly behind the return= RED, but you should watch that your function is still selected (greyed out), otherwise it will not be called GREEN and is displayed as string!
    grafik
  1. Ok, now lets switch the page to the functions.php in the Theme File Editor, scroll to the bottom and make us some room to work RED and add a comment BLUE so we know that we were here.
  • Note the rownumber is not important!
  1. Lets add our function ** RED**, a new variable that we would like to return, in this case a string BLUE and return the value back from where it was requested GREEN.
// my custom return_function calls

function my_unique_function_name(){
	$myAwesomeVariable = 'Some Awesome Text To Display!!!';
	return $myAwesomeVariable;
}

grafik

  1. Update the file:
    grafik

  2. Check out our result by viseting the frontend of the sample page, which displays our $myAwesomeVariable:
    grafik

Hope this helps :smiling_face:

Cheers

3 Likes