Skip to content

Instantly share code, notes, and snippets.

View cameronjonesweb's full-sized avatar
👨‍👦

Cameron Jones cameronjonesweb

👨‍👦
View GitHub Profile
@cameronjonesweb
cameronjonesweb / add-post-thumbnail-to-rss.php
Last active July 22, 2018 13:57
Adds the post thumbnail to the WordPress RSS feed
<?php
add_action( 'rss2_item', 'cameronjonesweb_add_post_thumbnail_to_rss' );
function cameronjonesweb_add_post_thumbnail_to_rss() {
if ( has_post_thumbnail() ) {
printf(
"\t" . '<media:content url="%1$s" type="%2$s" />' . "\n",
esc_url( get_the_post_thumbnail_url() ),
esc_attr( get_post_mime_type( get_post_thumbnail_id() ) )
@cameronjonesweb
cameronjonesweb / admin-menu-customizer-link.php
Last active September 28, 2018 13:23
Replaces a settings subpage link with a link to the customizer or external URL
@cameronjonesweb
cameronjonesweb / edd-account-login.php
Created August 8, 2018 03:11
Update Easy Digital Downloads sites to use an account page to login rather than wp-login.php
<?php
add_filter( 'edd_settings_general', 'cameronjonesweb_edd_login_page' );
add_filter( 'login_url', 'cameronjonesweb_use_edd_login_page', 10, 3 );
/**
* Adds an additional page to the EDD pages settings
* Make sure the [edd_profile_editor] or [edd_login] shortcode is on this page.
*
* @param array $settings The array of settings.
<?php
add_action( 'pricing_tables_for_edd_footer_end', 'cameronjonesweb_free_downloads_link_to_modal', 9 );
/**
* Changes the pricing tables link to use the modal if it's a free download
*
* @param array $args User defined data for the pricing table.
*/
function cameronjonesweb_free_downloads_link_to_modal( $args ) {
if ( class_exists( 'EDD_Free_Downloads' ) ) {
@cameronjonesweb
cameronjonesweb / create-index-php.sh
Last active October 7, 2020 23:40
Recursively creates an index.php file in all subfolders that don't include an index.php file
shopt -s globstar
for i in **; do
if [ -d "$i" ]; then
# update this line to include directories to ignore
if [[ "${i##/*}" != *"node_modules"* && "${i##/*}" != *"bower_components"* ]]; then
if [ ! -f "${i##/*}/index.php" ]; then
printf "Creating index file in %s\n" "${i##/*}"
printf "<?php\n// Silence is golden." > ${i##/*}/index.php
fi
fi
@cameronjonesweb
cameronjonesweb / yoast-webmaster-tools-verification.php
Created October 1, 2018 03:52
Adds the Yoast SEO webmaster tools (and other sites) verification codes to all pages including the login page. This is helpful when running a membership site or similar that requires users being logged in to view the site.
<?php
add_action( 'init', 'cameronjonesweb_yoast_front_page_head' );
function cameronjonesweb_yoast_front_page_head() {
if ( class_exists( 'WPSEO_Frontend' ) ) {
add_action( 'wpseo_head', array( WPSEO_Frontend::get_instance(), 'webmaster_tools_authentication' ), 90 );
add_action( 'login_head', array( WPSEO_Frontend::get_instance(), 'webmaster_tools_authentication' ), 90 );
}
}
@cameronjonesweb
cameronjonesweb / add-field-type-to-class.php
Created October 4, 2018 06:17
Adds a class that defines the type of field to the <li> element in Gravity Forms
<?php
add_filter( 'gform_field_css_class', 'cameronjonesweb_add_field_type_to_class', 10, 3 );
/**
* Adds a class that defines the type of field to the li element in Gravity Forms
*
* @param string $css_class The existing CSS classes.
* @param GF_Field $field The field object.
* @param array $form The form object.
* @return string
@cameronjonesweb
cameronjonesweb / remove-current-page-parent.php
Created October 24, 2018 22:43
Removes the `current_page_parent` class from the blog page link when not viewing a blog related page
<?php
/**
* Removes the `current_page_parent` class from the blog page link when not viewing a blog related page
*
* @param array $classes The CSS classes that are applied to the menu item's `<li>` element.
* @param WP_Post $item The current menu item.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $depth Depth of menu item. Used for padding.
*/
function cameronjonesweb_remove_current_page_parent( $classes, $item, $args, $depth ) {
@cameronjonesweb
cameronjonesweb / functions.php
Last active June 26, 2023 19:48
Takes custom classes out of the list item and adds them to the anchor element in WordPress menus. Perfect for font icons
<?php
add_filter( 'nav_menu_link_attributes','cameronjonesweb_move_custom_menu_item_class_to_anchor_element', 10, 4 );
add_filter( 'nav_menu_css_class', 'cameronjonesweb_remove_custom_menu_item_class_from_li_element', 10, 4 );
/**
* Get the custom item menu classes and add them to the anchor element
*
* @link https://cameronjonesweb.com.au/blog/how-to-move-the-custom-menu-item-classes-to-the-anchor-element/
* @param array $atts The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
@cameronjonesweb
cameronjonesweb / class-att-example.php
Created November 14, 2018 01:56
Generate a class attribute from an array of classes and sanitises the classes
<?php
// Example.
$myclasses = [ 'my-class', 'some-other-class', '<script>console.log(hi);</script>' ];
printf(
'<div %1$s>%2$s</div>',
cameronjonesweb_generate_class_attribute( $myclasses ),
'My content'
);