WordPress function naming convention, what "get" and "the" mean in WordPress function names

What "get" and "the" mean in a WordPress function name.


While WordPress has some inconsistencies in how it names things, some of the function names in WordPress can indicate what that function does.

"the" in a function name means that the function will work in "the" post loop. So, for example, "the_title" will output the title of the current post in the loop.

<?php the_title(); // will output the title ?>

"get" in the function name means that the function will return the value instead of outputting it. For example, "get_the_title" will return the title instead of outputting it.

<?php get_the_title(); // will not output the title ?>
<?php echo get_the_title(); //will output the title ?>

This naming convention is helpful to keep in mind when writing WordPress code snippets because it immediately indicates how a function will perform. And it might be a good idea to follow the same convention when naming your functions.

Get WPCodeBox, the most powerful WordPress Code Snippet Manager.

and save hours when customizing WordPress sites.

NWPCodeBox
WPCodeBox is a WordPress Code Snippets Manager that allows you to share your WordPress Code Snippets across your sites.

Free Tools

Product

Legal

Follow us
Copyright © 2024 WPCodeBox SRL