WordPress For Dummies

Doesn’t each one of us dream of creating his/her own website? portfolio? blog? whatever? I have always wanted to do so, and always was TOO lazy to create my backend and database and structure … etc. So, I thought of using WordPress and use it as a CMS to my content and blogs, well,, it went well, but of course I ran into problems and issues and struggles, and i kept searching to solve my issues, and of course used ChatGPT to solve other issues and queries. So, here, I’m giving it to you in a nutshell and how to get up and running quickly, so it will be a WordPress for dummies guide πŸ’©

Installation

Assuming you already have a an up and running server, of course you can use this link to download the source code and install it there, or, you can use the free online one on wordpress.com

  • The benefit of the first option is that you will of course tie it to your own domain and have something like this https://josepham.me
    • Yes, it’s written in WordPress … surprise? 😎
  • The benefit of the second option which is wordpress.com is that you don’t need a server and it’s easy to install in one click, but you will have a free domain something like whatever.wordpress.com

How to install it on your server? well there’re a lot of ways:

Now for WordPress For Dummies essentials

Source Code Access

Of, so, we are developers, right? well maybe IDK πŸ˜‚ but anyways most of us are. (If you are not a developer, just go to wordpress.com and create your website there and your job here is done πŸ˜‚ unless you wanna know what we are talking about and you are interested to find out more)

So, yes, Hi Developers 😎. We need to access and edit our code and break things right?

How will we do that? well if you are on your linux server and already did the installation, you already have the source code and you can play with it there, but if you used wordpress.com then you will have to download and install a plugin called Advanced File Manager – WordPress plugin | WordPress.org which will allow you to access your code as if it’s a FTP or something, and you start playing from there.

Blank Template

Ok so, once we start exploring the code, we will have like 3 initial templates, if you try to explore them, you will find that they are filled with pages and files and code, we don’t need all that, right? we want something simple in order to enhance and customize it with our own way.

We can download this simple template called BlankSlate, how?

  • Download it from the download button
  • Move the zip file to public_html/wp-content/themes/blankslate
  • Go to Appearance Themes in your dashboard, and you should find it
  • Activate it

You will find your website looks like this now:

blank slate theme

Now we have something simple to play around with.

Classes

Ok, so as some of us may know, the main building block of wordpress is Posts as it was initially a blogging site. But what if we wanna build something other than a blog? Maybe a Cars website, and we want a Cars table.

We can create something called Custom Post Type, we can use this plugin to create it:

Custom Post Type UI – WordPress plugin | WordPress.org

And, if we want to create custom fields to it, let’s say, a Car has a Motor Power in CC, so we need a field CC, and maybe a field Color, and maybe a Brand, we need to create something called a Custom Field, and tie it with our Custom Post Type (Car), using a plugin called Advanced Custom Fields:

Advanced Custom Fields (ACF) – WordPress plugin | WordPress.org

Post Type Pages

Ok, so let’s say we have the Cars class, we need to list our cars in a page, right?

and then we will have to go to each single car page, right?

So, we need two pages to do so:

  • whatever.com/cars
  • whatever.com/cars/123 // car id

By default, WordPress will use the Post list and Single pages to do so, but if we want to make something custom to our new Custom Post Type (Car), we will need to create two files under our blank slate theme files.

single-car.php

archive-car.php

And make sure that it have to follow that naming convention otherwise it won’t work.

Then WordPress will start using those pages when you go to the Single or List pages of your newly created Custom Post Type.

APIs

Last but not least, APIs !!

We are here to get and post data right? so, How will we do that?

You will find a folder called plugins under: public_html/wp-content/plugins

Create a new folder and name it anything under plugins, let’s say my-plugin, then create a php file under it called anything, it will act as the main entry to the plugin, let’s say: main.php

paste that comment at the top of the page

<?php
/**
 * Plugin Name: My Plugin
 * Description: What do I do?
 * Version: 1.0.0
 * Author: Your Name
 * License: GPL2 or later
 */

and then we start writing our APIs, here’s an example of w GET and POST request for a plugin

<?php
/*
Plugin Name: My Custom Plugin
Description: A custom plugin that handles GET and POST requests.
Version: 1.0
*/

// Register the endpoint for handling GET requests
add_action('init', 'my_custom_plugin_add_endpoint');
function my_custom_plugin_add_endpoint() {
  add_rewrite_endpoint('my-endpoint', EP_ROOT);
}

// Handle GET requests
add_action('template_redirect', 'my_custom_plugin_handle_get_request');
function my_custom_plugin_handle_get_request() {
  if (get_query_var('my-endpoint')) {
    // Handle the GET request here
    $query_params = $_GET;
    // Do something with the query params
    exit();
  }
}

// Handle POST requests
add_action('rest_api_init', 'my_custom_plugin_handle_post_request');
function my_custom_plugin_handle_post_request() {
  register_rest_route('my-custom-plugin/v1', '/my-endpoint', array(
    'methods' => 'POST',
    'callback' => 'my_custom_plugin_process_post_request',
    'permission_callback' => function () {
      return current_user_can('edit_posts');
    }
  ));
}

function my_custom_plugin_process_post_request($request) {
  // Post data will be in here $_POST
  $body_params = $request->get_params();
  // Do something with the body params
  return array('success' => true);
}

Pages

And now, finally, if we want to create a custom page in WordPress.

Head to the source code in your theme and create a new file and name it anything, let’s say, about-us-page.php and paste the below comment

<?php /* Template Name: My New Page */ ?>

And then, head to Pages in your dashboard and create a new page, give it any title, and on the right, you shall find, Page Template, select the page name that your just created and wrote in the comment, in our case: My New Page, and that’s it ! your php page will load and anything you type in there will happen 😎

Conclusion

So, WordPress is so powerful and can make magnificent things, take this as your entry point and feel free to ask me anything further and start creating great stuff ! .. and that was WordPress for Dummies 😊

Here’s a potato as well.

potato