Skip to content

Instantly share code, notes, and snippets.

@slopesweb
slopesweb / slug.php
Created May 6, 2022 19:15
Tirar acentos, caracteres especiais e espaços de titulos e frases para torna-los slug
<?php
function tirarAcentos($string){
$string = preg_replace(array("/(á|à|ã|â|ä)/","/(Á|À|Ã|Â|Ä)/","/(é|è|ê|ë)/","/(É|È|Ê|Ë)/","/(í|ì|î|ï)/","/(Í|Ì|Î|Ï)/","/(ó|ò|õ|ô|ö)/","/(Ó|Ò|Õ|Ô|Ö)/","/(ú|ù|û|ü)/","/(Ú|Ù|Û|Ü)/","/(ñ)/","/(Ñ)/","/(ç)/","/(Ç)/"),explode(" ","a A e E i I o O u U n N c C"),$string);
$char = array(' & ', 'ª ', ' (', ') ', '(', ')', ' - ', ' / ', ' /', '/ ', '/', ' | ', ' |', '| ', ' | ', '|', '_', '.', ' ');
return strtolower(str_replace($char, '-', $string));
}
@slopesweb
slopesweb / wp-ajax-loadmore.md
Created May 20, 2022 23:05 — forked from aslamdoctor/wp-ajax-loadmore.md
Wordpress - AJAX Load More Steps

Step 1. Load more button

<?php
global $wp_query; // you can remove this line if everything works for you
 
// don't display the button if there are not enough posts
if (  $wp_query->max_num_pages > 1 )
	echo '<div class="misha_loadmore">More posts</div>'; // you can use <a> as well
?>
@slopesweb
slopesweb / load-more.js
Created May 21, 2022 13:07 — forked from bebaps/load-more.js
AJAX load more button using the WP REST API
// This function implements a "Load More" button.
// It assumes that there is already a matching query that has executed on the page, so this AJAX call is just a continuation of that query to grab additional posts.
// There are no animations added here. For a smoother experience, it is a good idea to add animations to the button (ex. a loading icon during the request), or making the new posts animate in (ex, using Animate.css to fade them into the page)
$(function() {
// Grab the load more button, since I only want to run the code if the button is on the page
var loadMoreButton = $('#load-more');
if (loadMoreButton) {
// Because there are already posts on the page, we need to manually tell this query what page of results to grab so that is doesn't load duplicate posts
var loadPosts = function(page) {
@slopesweb
slopesweb / update.json
Created September 7, 2022 03:07 — forked from kloh-fr/update.json
Update notifier function for a custom WordPress Theme
{
"new_version":"1.0.0",
"url":"http://www.domain.com/theme-name/changelog",
"package":"http://www.domain.com/theme-name/themes.zip"
}
@slopesweb
slopesweb / custom-nav-menus-options.php
Created September 8, 2022 15:29 — forked from JacobDB/custom-nav-menus-options.php
Add any custom option to the WordPress nav menus editor. I primarily use this for mega menus, but it can be used to add basically any additional data to menus.
<?php
// add custom options to the menu editor
if (is_admin() && $pagenow === "nav-menus.php") {
// include this so we can access Walker_Nav_Menu_Edit
require_once ABSPATH . "wp-admin/includes/nav-menu.php";
// Add the WordPress color picker styles & scripts
function new_site_nav_menu_color_picker() {
wp_enqueue_style("wp-color-picker");
wp_enqueue_script("wp-color-picker");
@slopesweb
slopesweb / AdminMenusImprover.php
Created September 8, 2022 15:37 — forked from iksent/AdminMenusImprover.php
Add new fields to nav_menu_item posts in the WordPress menu editor.
<?php
require_once plugin_dir_path( __FILE__ ) . '/CustomWalkerNavMenuEdit.php';
class AdminMenusImprover {
/**
* Class instance.
*
* @var AdminTaxonomiesImprover instance
*/
@slopesweb
slopesweb / get-first-category.php
Created September 12, 2022 12:14 — forked from hslaszlo/get-first-category.php
Get first category name or id from wordpress post
<?php
// in the loop
$category = get_the_category();
$currentcat = $category[0]->cat_ID;
$currentcatname = $category[0]->cat_name;
$currentcatslug = $category[0]->slug;
// outside the loop
global $post;
$categories = get_the_category($post->ID);
@slopesweb
slopesweb / tag-cloud-based-on-category-via-shortcode.php
Created September 13, 2022 12:21 — forked from Garconis/tag-cloud-based-on-category-via-shortcode.php
WordPress | Tag cloud for categories via shortcode
<?php
function tag_cloud_shortcode($atts) {
// first make sure we are within a category
if (is_category()) {
// get info of current category
$category = get_category( get_query_var( 'cat' ) );
// get current category ID
@slopesweb
slopesweb / rest-api-loop.php
Created November 21, 2022 23:07 — forked from bebaps/rest-api-loop.php
Standard loop of posts using the WP REST API
<?php
// Standard API query arguments
$args = array(
'orderby' => 'title',
'per_page' => 3
);
// Put into the `add_query_arg();` to build a URL for use
// Just an alternative to manually typing the query string
$url = add_query_arg( $args, rest_url('wp/v2/posts') );
@slopesweb
slopesweb / load-posts.js
Created November 21, 2022 23:08 — forked from bebaps/load-posts.js
Load posts into a page using the WP REST API
// This function uses AJAX to run a query.
// It assumes that there are no posts on the page, and they will be loaded by the user on demand.
// // There are no animations added here. For a smoother experience, it is a good idea to add animations to the button (ex. a loading icon during the request), or making the new posts animate in (ex, using Animate.css to fade them into the page)
$(function() {
// Grab the load button, since I only want to run the code if the button is on the page
var ajaxButton = $('#ajax-button');
if (ajaxButton) {
// The AJAX request
var getPosts = function() {