Skip to content

Instantly share code, notes, and snippets.

@brentini
brentini / functions.php
Last active March 23, 2018 21:30 — forked from ofernandolopes/functions.php
WordPress - Redirect a page using a filter #wordpress
//Redirect a page using a filter
add_filter('get_the_permalink','my_permalink_redirect');
function my_permalink_redirect($permalink) {
global $post;
if ($post->ID == your_post_id_here) { //Page ID you want to redirect
$permalink = 'http://new-url.com/pagename'; //Redirect destination page
}
return $permalink;
}
@brentini
brentini / wordpress-hooks.php
Last active March 23, 2018 21:30 — forked from 5A5K1A/wordpress-hooks.php
WordPress Generic Object #wordpress
<?php
/**
* Registers all ShortCode_* methods
*/
static public function Register_ShortCodes() {
// part of string to search for
$keyword = 'ShortCode_';
// loop all class methods
foreach( get_class_methods(__CLASS__) as $method ) {
@brentini
brentini / lets-encrypt-index.php
Last active March 23, 2018 21:31 — forked from iambriansreed/lets-encrypt-index.php
Add this to the beginning of your index.php file. Useful when adding SSL to Wordpress applications. #wordpress
$request = 'code_in_the_url';
$response = 'code_returned';
if ( $_SERVER['REQUEST_URI'] === ( '/.well-known/acme-challenge/' . $request ) ) {
echo $request . '.' . $response;
exit;
}
@brentini
brentini / slider.php
Last active March 23, 2018 21:44
Slider wordpress+bootstrap #wordpress
<!--Carrossel-->
<div class="row">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<?php wp_reset_query(); ?>
<?php query_posts('category_name=slider&posts_per_page=5'); ?>
<?php $cont = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<div class="item <?php if($cont == 0): echo"active"; ?><?php endif; ?>">
@brentini
brentini / functions.php
Last active March 23, 2018 21:43 — forked from marcosnakamine/functions.php
WordPress - Custom post with custom permalink (slug) #wordpress
<?php
add_action( 'init', 'register_new_post_type' );
function register_new_post_type(){
$args = array(
'label' => 'Post title',
'show_ui' => true,
'public' => true,
'hierarchical' => true,
'has_archive' => true,
'supports' => array( 'title' ),
@brentini
brentini / page-home.php
Last active March 23, 2018 21:44 — forked from ScarletPonytail/page-home.php
Wordpress - Add posts 'Loop' of a certain category to theme file #wordpress
<?php query_posts('cat=7'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="col-md-4">
<h3><?php the_title(); ?></h3>
<?php the_excerpt(__('(more…)')); ?>
<a class="btn btn-default" href="<?php the_permalink() ?>" role="button">Read More</a>
</div>
<?php endwhile; endif; ?>
@brentini
brentini / custom-image-size.php
Last active March 23, 2018 21:43
Wordpress - set custom image size in Media Library #wordpress
/* Custom image sizes to Media Library */
function wp_70048_remove_image_sizes( $sizes ) {
unset( $sizes['thumbnail'] );
unset( $sizes['medium'] );
unset( $sizes['large'] );
unset( $sizes['full'] );
return $sizes;
}
@brentini
brentini / functions.php
Last active March 23, 2018 21:43 — forked from taninbkk/functions.php
Wordpress Child Theme Overriding Parent #wordpress
// Credit @rmulugeta https://wordpress.org/support/users/rmulugeta/
// from https://wordpress.org/support/topic/child-theme-not-overriding-parent-stylecss/
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array('parent-style')
);
@brentini
brentini / wordpress-get-blog-posts-page-url.php
Last active March 23, 2018 21:44 — forked from coffeepostal/wordpress-get-blog-posts-page-url.php
WordPress: Get Blog Posts Page URL in WordPress #wordpress
<?php
/**
* Get blog posts page URL.
*
* @return string The blog posts page URL.
*/
function km_get_blog_posts_page_url() {
// If front page is set to display a static page, get the URL of the posts page.
@brentini
brentini / domain_agnostic_wordpress.php
Last active March 23, 2018 21:43 — forked from ranchodeluxemedia/domain_agnostic_wordpress.php
Domain agnostic wordpress setup #wordpress
<?php
define('WP_HOME', "http://{$_SERVER['HTTP_HOST']}/");
define('WP_SITEURL', "http://{$_SERVER['HTTP_HOST']}/");