Kategorier
ACF Wordpress

Vis Yoast metabox under ACF felter på edit screen

Placeres i functions.php

// Move Yoast to bottom
function yoastToBottom() {
	return 'low';
}
add_filter( 'wpseo_metabox_prio', 'yoastToBottom');
Kategorier
localdev PHP Tools Wordpress

Lando lamp opsætning

Docker desktop skal være installeret og startet.

Config filen placeres i roden af projektet. Webroot: web, er til bedrock setup.

Tilføj dev domæne i hosts filen på 127.0.0.1 (sudo nano /etc/hosts)

Kør lando start i terminalen

// .lando.yml
name: projektnavn
recipe: lamp
config:
  webroot: web
  php: '5.6'
  database: mysql
proxy:
  appserver:
    - domain.local (for https use domain.lndo.site)

Docs: https://docs.devwithlando.io/tutorials/lamp.html

Kategorier
PHP Timber Twig Wordpress

Tilføj custom filter til Timber/Twig

Nedenstående eksempel tilføjer et filter som kan bruges i twig templaten sådan:

{{ field.name | truncate_title }}

add_filter('get_twig', 'add_to_twig');

function add_to_twig($twig)
{
    $twig->addFilter('truncate_title', new Twig_Filter_Function('truncate_title'));
    return $twig;
}

function truncate_title($content)
{
    $content = Timber\TextHelper::trim_characters($content, 45);
    return $content;
}
Kategorier
Wordpress

WordPress dashboard standard menu items position

The default menu items has the following positions:

  • 2 Dashboard
  • 4 Separator
  • 5 Posts
  • 10 Media
  • 15 Links
  • 20 Pages
  • 25 Comments
  • 59 Separator
  • 60 Appearance
  • 65 Plugins
  • 70 Users
  • 75 Tools
  • 80 Settings
  • 99 Separator
Kategorier
Gutenberg ReactJS Wordpress

Gutenberg custom hero block tutorial

Tekst tutorial i to dele.

BEMÆRK!! InspectorControls og ColorPalette skal importeres fra wp.editor, fremfor wp.blocks

Part 1:

WordPress Gutenberg Blocks Example: Creating a Hero Image Block with Inspector Controls, Color Palette, and Media Upload (Part 1)

Part 2:

WordPress Gutenberg Blocks Example: Creating a Hero Image Block with Inspector Controls, Color Palette, and Media Upload (Part 2)

Kategorier
htaccess Wordpress

WordPress: Vis billeder fra live server

Bruges for at vise billeder fra live server på lokalt setup.

# BEGIN Clever hack to show production images on dev site

# Force image styles that have local files that exist to be generated.
RewriteCond %{REQUEST_URI} ^/app/uploads/.*$
RewriteCond %{DOCUMENT_ROOT}/app/uploads/%1 -f
RewriteRule ^(.*)$ $1 [QSA,L]
# Otherwise, send anything else that's in the files directory to the production server.
RewriteCond %{REQUEST_URI} ^/app/uploads/.*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://yourdomain.com/$1 [QSA,L]

# END Clever hack to show production images on dev site
Kategorier
CMS Ionic Wordpress Wordpress plugins

WordPress REST API

WordPress REST API plugin V2

WordPress REST API (Version 2)

Kategorier
CMS PHP Wordpress Wordpress plugins

Tilføj custom post type til søgning i WordPress

<?php function my_remove_default_et_pb_custom_search() { 
remove_action( 'pre_get_posts', 'et_pb_custom_search' ); 
add_action( 'pre_get_posts', 'my_et_pb_custom_search' ); 
} 
add_action( 'wp_loaded', 'my_remove_default_et_pb_custom_search' ); 

function my_et_pb_custom_search( $query = false ) { if ( is_admin() || ! is_a( $query, 'WP_Query' ) || ! $query->is_search ) {
		return;
	}
	if ( isset( $_GET['et_pb_searchform_submit'] ) ) {
		$postTypes = array();
		if ( ! isset($_GET['et_pb_include_posts'] ) && ! isset( $_GET['et_pb_include_pages'] ) ) $postTypes = array( 'post' );
		if ( isset( $_GET['et_pb_include_pages'] ) ) $postTypes = array( 'page' );
		if ( isset( $_GET['et_pb_include_posts'] ) ) $postTypes[] = 'post';
		
		/* BEGIN Add custom post types */
		$postTypes[] = 'product';
		/* END Add custom post types */
		
		$query->set( 'post_type', $postTypes );
		if ( ! empty( $_GET['et_pb_search_cat'] ) ) {
			$categories_array = explode( ',', $_GET['et_pb_search_cat'] );
			$query->set( 'category__not_in', $categories_array );
		}
		if ( isset( $_GET['et-posts-count'] ) ) {
			$query->set( 'posts_per_page', (int) $_GET['et-posts-count'] );
		}
	}
}
Kategorier
CMS PHP Wordpress Wordpress plugins

Inkluder ekstern fil i theme functions eller plugin fil

<span class="pl-k">require_once</span> ( plugin_dir_path(<span class="pl-c1">__FILE__</span>) <span class="pl-k">.</span> <span class="pl-s"><span class="pl-pds">'</span>wp-job-cpt.php<span class="pl-pds">'</span></span> );
Kategorier
CMS PHP Wordpress

Vis alle tilgængelige terms i custom taxonomy

Dette viser alle tilgængelige taxonomy terms og ikke kun de valgte. (Alle dem som er i brug på en post). Er der mere end 1, adskilles de med en skråstreg.

<?php 
    $terms = get_terms("custom_taxonomy_navn");
    $count = count($terms);
    $i = 0; 
    if ( $count > 0 ){
        foreach ( $terms as $term ) {
            if ( $i == 0) {
                echo $term->name;
            } else {
            echo " / " . $term->name;
            }
            $i++;
            }
} 
?>