DEV Community


Posted on

Some Basic But Useful WordPress Functions | PHP Tutorial for Beginners

Introducing, my name is Aisyah Gray from Indonesia. I am a blogger who has more than 5 years experience. I have a website about Android smartphones ( ).

The site that I have uses Wordpress. As we all know, WordPress has a theme and plugin system. But sometimes the themes and plugins that we install require modification.

That's why I will write information about PHP code that you can use to modify the theme and wordpress plugins.

In this tutorial for Php Tutorial for Beginners we will show you some basic but important functions of WordPress

1 - $current_category = single_cat_title("", false);
Display current category Title.

2 - $permalink = get_permalink( $id );
Returns the permalink to a post or page for use in PHP.

3 - $cat_id = get_cat_ID( $cat_name ) ;
Retrieve the ID of a category from its name.

4 - $current_user = wp_get_current_user();
Retrieve the current user object.

5 - $current_user_id = get_current_user_id( );
Returns the ID of the current viewer if they are logged in. Returns 0 if the viewer is not logged in.

6 - $title = get_the_title();
Return the cureent post/page title.

7 - $posts = get_posts( array('numberposts' => 6,'orderby' => 'post_date','order' => 'DESC','post_type' => 'post','post_status' => 'publish' ) );
Get the posts from database accroding to the argument passed in it.

8 - get_header()
Add Header page to the file.

9 - bloginfo('home')
Fetch the URL of your home page.

10 - the_content()
Displays the contents of the current post. This template tag must be within the loop.

Hope this php tutorial is useful for you.

Top comments (1)

slametpurwanto profile image
Pakar SEO & Konsultan SEO Cirebon

Thanks for sharing... Really useful