Recently I had to create an endpoint for users to view a dynamically-generated PDF on a site. I wanted to have a nice-looking URL for users. I found it difficult to wrap my head around the process of adding a rewrite rule in WordPress but I finally figured it out. WordPress offers a function, add_rewrite_rule,… Continue reading Creating a Rewrite Rule in WordPress
Category: PHP
Passing PHP Variables to JavaScript in WordPress
One thing that I found difficult to understand when starting out with WordPress development was how to use PHP variables in my JavaScript. I’m not sure why I found it so confusing. There are a lot of good examples out there but I thought I would break down how use PHP variables in your JavaScript… Continue reading Passing PHP Variables to JavaScript in WordPress
Inserting JavaScript with a Shortcode
Have you ever needed to insert a piece of JavaScript into a single post or page? Maybe there is an external contact form from a vendor that you’ve been given a snippet of JavaScript to include? There are a number of ways to do this. You could put a conditional in your template file and… Continue reading Inserting JavaScript with a Shortcode
Adding Post Type and Slug to the Body Classes
When I first started working with WordPress, in order to style things on a particular page, I often would use the page or post’s ID to target the styles for that page. After all, out-of-the-box, WordPress gives you a class on the body tag containing the post type and the ID like postid-455 or page-id-525.… Continue reading Adding Post Type and Slug to the Body Classes
Simple WordPress PlugIn to Replace Excerpt With Full Post
I recently posted my lame joke video mashing together The Andy Griffith with Star Wars. In posting it, the excerpt for the post was showing on my site’s homepage and one had to click through to watch the video. There was nothing much to the text of the post – the only thing of note… Continue reading Simple WordPress PlugIn to Replace Excerpt With Full Post
Dynamically Overriding a Page’s Template
It is easy to override the template for a post or page in WordPress in a few ways. For example, the naming of page template files can be used to override a single page’s template: page-{id}.php page-{slug}.php Or, a page template can be chosen in the Page Attributes section when editing a page: This works great… Continue reading Dynamically Overriding a Page’s Template
Hiding the categories of a post when it is “uncategorized”
If you’ve ever had some posts on your WordPress blog, you will have noticed that the “Uncategorized” category is displayed with a link to an archive of uncategorized posts. The easiest way to solve this, of course, is to categorize every blog post. But, if you don’t want to for some reason, you can use… Continue reading Hiding the categories of a post when it is “uncategorized”
Hiding the WordPress admin bar on certain pages
There may be times when you would like to hide the WordPress admin bar on certain pages. Maybe the admin bar interferes with the design, for example. This can be especially true for things like pages opening up in a lightbox. Fortunately, it is not too difficult to hide the admin bar on certain pages… Continue reading Hiding the WordPress admin bar on certain pages
Using MailCatcher for local mail testing
When developing web applications on your local machine, you will often want to test e-mails. For the longest time, I would use an environmental switch in PHP depending on the domain (for example, I would set different values if the domain was stirrell.second-cup-of-coffee or www.second-cup-of-coffee.com) and include values for email addresses. I had my local… Continue reading Using MailCatcher for local mail testing
Passing PHP variables to JavaScript
I was recently working on a project in CodeIgniter and I was setting numeric variables with constants for things like locations (1 = Maine, 2 = New Hampshire, etc.). This all worked fine but when it came to doing some JavaScript AJAX work I didn’t have access to these constants. One of the advantages to… Continue reading Passing PHP variables to JavaScript