Skip to content

Instantly share code, notes, and snippets.

View krystyna93's full-sized avatar
🏠
Working from home

krystyna krystyna93

🏠
Working from home
  • Victoria, Australia
View GitHub Profile
@krystyna93
krystyna93 / app.js
Created June 10, 2023 08:20
webpack sample
import './scss/style.scss';
// Example jQuery usage:
$(document).ready(() => {
$('h1').css('color', 'red');
});
@krystyna93
krystyna93 / package.json
Created June 10, 2023 08:35
webpack sample
{
"name": "fictional-university-theme",
"version": "1.0.0",
"description": "A fictional university WordPress theme.",
"main": "index.js",
"scripts": {
"dev": "webpack serve --config webpack.config.js --env.mode=development",
"build": "webpack --config webpack.config.js --env.mode=production"
},
"author": "",
@krystyna93
krystyna93 / recent-posts-widget.php
Last active June 10, 2023 13:13
Recent Posts Widget w/ajax Refresh
<?php
class Recent_Posts_Widget extends WP_Widget {
/**
* Register widget with WordPress.
*/
function __construct() {
parent::__construct(
'recent_posts_widget', // Base ID
__( 'Recent Posts Widget', 'text_domain' ), // Name
@krystyna93
krystyna93 / date-widget.php
Last active June 10, 2023 13:11
Custom WordPress Simple Date Widget
<?php
class Custom_Page_Title_Widget extends WP_Widget {
/**
* Register widget with WordPress.
*/
public function __construct() {
parent::__construct(
'custom_page_title_widget', // Base ID
@krystyna93
krystyna93 / date-format-option-widget.php
Last active June 10, 2023 12:53
Custom WordPress Widget Plugin Example: Display the Current Day, Month, and Year, w/Dropdown Option To Select Date Format
<?php
/*
Plugin Name: Date Widget
Description: A widget that displays the current date.
Version: 1.0
Author: Your Name Here
*/
// Register the widget
add_action( 'widgets_init', 'register_date_widget' );
@krystyna93
krystyna93 / birdTree-widget.php
Last active June 10, 2023 12:55
Custom WordPress Widget Example: Greetings message w/strip_tags() and isset()
<?php
class birdtree_greeting_widget extends WP_Widget {
// Set up the widget name, description, etc.
public function __construct() {
$widget_options = array(
'classname' => 'birdtree_greeting_widget',
'description' => 'Displays a greeting message from BirdTree'
);
@krystyna93
krystyna93 / functions.php
Last active June 10, 2023 12:56
Customize WordPress Dashboard Editor Table Columns Example: Add Column Header and Featured Image w/size
<?php
/* To modify the columns in a WordPress dashboard table, you can use the manage_{$post_type}_posts_columns filter.
This filter allows you to add or remove columns from the post type's edit screen.
Here is an example of how to use this filter to modify the columns in the Posts table:
*/
Modify wordpress dashboard table column headings with image columns and featured image example
function custom_posts_table_columns($columns) {
// Remove the Author column
unset($columns['author']);
@krystyna93
krystyna93 / functions.php
Last active June 10, 2023 13:08
wordpress customizer selective refresh what is it/how to use it
<?php
/* Selective refresh is a feature in the WordPress Customizer that allows you to update a specific section of a page without having
to reload the entire page. It works by using JavaScript to dynamically update only the content that has changed, rather than reloading
the entire page.
This is especially useful for live previewing changes to your website's appearance or content, as it allows you to see how your
changes will look in real-time without disrupting the user experience.
For example, if you make a change to the site title in the Customizer, instead of reloading the entire page, only the site title
element would be updated. This makes for a smoother and more efficient editing experience.
@krystyna93
krystyna93 / functions.php
Last active June 10, 2023 13:45
Custom Featured Image Metabox: Text Field for Image From URL
<?php
/*
The purpose of this field is to allow you to enter a custom URL for an image, which can be used as the featured image for your
WordPress post or page. This could be useful if you have an image that you want to use as the featured image, but it is not hosted
on your own website and therefore cannot be easily uploaded through the WordPress media library.
By adding this custom field, you can enter the URL of the external image and then use it as the featured image for your post or page,
just as you would with a standard image uploaded through the WordPress media library.
*/
@krystyna93
krystyna93 / functions.php
Created June 10, 2023 14:03
Custom WordPress Query: CPT Related Tax Terms
<?php
// Validate and sanitize the ID of the current post
$portfolio_id = ( isset( $_GET['post'] ) && ctype_digit( $_GET['post'] ) ) ? $_GET['post'] : '';
$portfolio_id = filter_var( $portfolio_id, FILTER_SANITIZE_NUMBER_INT );
// Verify the nonce before processing the form submission
if ( isset( $_POST['submit_related_portfolio'] ) && wp_verify_nonce( $_POST['related_portfolio_nonce'], 'related_portfolio' ) ) {
// Sanitize the input data