Skip to content

Instantly share code, notes, and snippets.

View shaunpalmer's full-sized avatar

shaun palmer shaunpalmer

View GitHub Profile
@shaunpalmer
shaunpalmer / gist:77fcaba0d744ce1cef25c80c70cc1377
Created August 13, 2021 07:44
Discover index Google large image
<meta name="robots" content="" />
Max image preview large
They can be combined, for example:
<meta name="robots" content="max-snippet:50, max-image-preview:large" />
<?php
function add_custom_header() {
if (is_front_page() || is_home()) {
?>
<header id="custom-header">
<!-- Your custom header content here -->
</header>
<?php
}
<?php
/*
WordPress Path Discovery Utility Class
To use this utility, you would initialize it in your plugin's main file like this:
require_once 'path/to/WP_Asset_Utility.php';
initialize_asset_utility();
*/
class WP_Asset_Utility {
private $base_path;
<?php
/**
* Configuration class to manage settings
*/
class WP_Error_Handler_Config {
private $config;
public function __construct(array $config = []) {
$this->config = array_merge([

In this article I'm going to walk you through process of creating Wordpress plugins. First I'm going to talk about some of the basic concepts in Wordpress plugin development like the actions, hooks, and API's that makes up Wordpress. Then were going to build a plugin where we apply some of the concepts and best practices in developing Wordpress plugins.

###Prerequisites

In order to fully benefit from this tutorial you should have a basic knowledge on PHP. As Wordpress is running on PHP and most of the code that we will be writing will be on PHP. A little bit of knowledge on HTML, CSS and JavaScript is also helpful but not required for this tutorial.

@shaunpalmer
shaunpalmer / How to detect if a WordPress plugin is active.php
Created September 15, 2024 01:17 — forked from mlbd/How to detect if a WordPress plugin is active.php
A function you can use to check if plugin is active/loaded for your plugins/themes
<?php
/**
* Detect if a WordPress plugin is active
* A function you can use to check if plugin is active/loaded for your plugins/themes
* @link //gist.github.com/llgruff/c5666bfeded5de69b1aa424aa80cc14f
*/
// When coding plugins that rely on another one, like Private Content for bbPress or Visual Attributes for WooCommerce, you need to make if the WordPress Plugin is active to initialize your plugin routines or display a notice saying that the required plugin must be activated. In this tutorial we’ll see how to detect whether a certain plugin is active in a couple of ways.
## 1. Check whether a certain class or function or constant exists
@shaunpalmer
shaunpalmer / MyPlugin.php
Created September 15, 2024 02:04 — forked from rheinardkorf/MyPlugin.php
One approach to implement a class autoloader for WordPress plugin development. This file will for the most part be untouched once the structure is in place. The real development starts in the library folder.
<?php
/**
* @package MyPlugin
*/
//Before playing with this file, see the other file in the gist. Read the comments.
if( ! class_exists( 'MyPlugin' ) ) {
class MyPlugin {
@shaunpalmer
shaunpalmer / WordPress-Plugin-Template-Extra-Post-Info.php
Created September 15, 2024 02:08 — forked from rveitch/WordPress-Plugin-Template-Extra-Post-Info.php
A simple plugin starter template to add extra info to posts excerpt previews, after the excerpt-content.
<?php
/*
Plugin name: WordPress Plugin Template - Extra Post Info
Plugin URI: http://veitchdigital.com/
Description: A simple plugin starter template to add extra info to posts excerpt previews, after the excerpt-content.
Author: Ryan Veitch
Author http://veitchdigital.com/
Version: 0.1
*/