Software Engineering in WordPress, PHP, and Backend Development

Category: Tips (Page 7 of 10)

Various articles covering anything from how to programmatically achieve a certain task to useful ways that I’ve found to manage my time.

How To Get a Page’s Permalink By Slug

If you’re used to working with The Loop, then you’re all too familiar with the_permalink. Simply put, it’s how to get the link to the post currently being rendered in the browser.

But if you’re working on anything more advanced than using the typical Loop, then you may be looking to get the permalink for a post by other means – perhaps by a page slug or by a page’s title.

I’ve had to do this in some recent work, as well, so here’s what I do when I need to get permalink by slug:

Continue reading

Resolving wp_redirect and the “Headers Already Sent” message

I’ve been working on building a web application in WordPress on which I’m implementing a set of rewrite rules to introduce RESTful routing into the application.

Once the application is done, I hope to provide a significantly more in-depth post on how I built it, but in the mean time I figured I’d cover how I’m handling certain challenges that I’ve faced in development.

In this case, I needed to fire a call to wp_redirect after a certain event happened, but kept getting the PHP error:

Cannot modify header information - headers already sent by (output started ... )

Here’s how I ended up resolving the wp_redirect headers already sent message.

Continue reading

How To Check If a User Has a Gravatar in WordPress

If you're experienced with programmatically creating pages, you may wish to skip down to the code.

I’ve been working on a project where the requirements simply stated this:

  • If the user has a gravatar, display it
  • Otherwise, give the user the ability to upload a profile image from their computer

The WordPress API offers the get_avatar function for easily retrieving a users gravatar image, but there’s currently no API function that allows us to check if a user has a gravatar.

Continue reading

How To Prevent a Page From Being Deleted in WordPress

If you're experienced with programmatically creating pages, you may wish to skip down to the code.

I’m currently working on two applications that I’m building on top of WordPress (of which I hope to share once they’re complete).

Both projects have views – basically pages with templates – that need to be created when the application is installed and the pages aren’t meant to be deleted.

Though I’ve covered how to programmatically create a post in WordPress, I thought I’d share a quick example of how you can programmatically prevent a page from being deleted in WordPress, too.

Continue reading

How To Add Custom User Meta During Registration

I’m currently working on an application that requires users to register before logging into the site. The application is based on WordPress, but the registration process is using a custom template and requires some extra information.

As an example, I thought I’d share how I’m programmatically creating a user during the registration process, adding extra information to the user’s profile, and then displaying it in the user management dashboard.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑