Funciones wordpress

Toolset: Shortcode para visualizar la fecha de modificación de un post

add_shortcode('wpv-post-modified', 'wpv_post_modified_shortcode');
function wpv_post_modified_shortcode($atts) {
if (empty($atts['format'])) {
$atts['format'] = get_option('date_format');
}
return get_the_modified_date($atts['format']);
}
[wpv-post-modified format="d-m-Y"]

https://toolset.com/forums/topic/adding-a-shortcode-for-the-last-modified-date/

Toolset: Shortcode para visualizar la fecha de modificación de un post Leer más »

Woocommerce: Aplicando impuestos / IVA solo en la página de producto de WooCommerce

function edit_price_display($price, $instance) {
    global $product;

    if(is_singular('product')) {
        $price = $product->price;
        $price_incl_tax = $price + round($price * ( 21 / 100 ), 2);
        $price_incl_tax = number_format($price_incl_tax, 2, ",", ".");
        $price = number_format($price, 2, ",", ".");
        $display_price = '<span class="price">';
        $display_price .= '<span class="amount">€ ' . $price_incl_tax .'<small class="woocommerce-price-suffix"> incl BTW</small></span>';
        $display_price .= '<br>';
        $display_price .= '<span class="amount">€ ' . $price .'<small class="woocommerce-price-suffix"> excl BTW</small></span>';
        $display_price .= '</span>';
        echo $display_price;
    } else {
        echo $price;	
    }
}
add_filter('woocommerce_get_price_html', 'edit_price_display', 10, 2);

Visto en tomjesch

Woocommerce: Aplicando impuestos / IVA solo en la página de producto de WooCommerce Leer más »

WordPress: Inhabilitar mostrar entradas y medios de otros usuarios

add_action('pre_get_posts', 'query_set_only_author' );
function query_set_only_author( $wp_query ) {
 global $current_user;
 if( is_admin() && !current_user_can('edit_others_posts') ) {
    $wp_query->set( 'author', $current_user->ID );
    add_filter('views_edit-post', 'fix_post_counts');
    add_filter('views_upload', 'fix_media_counts');
 }
}

Visto en Collectiveray

WordPress: Inhabilitar mostrar entradas y medios de otros usuarios Leer más »

WordPress: Bloquear wp-admin a no administradores

/**
 * Hide admin bar for non-admins
 */
function js_hide_admin_bar( $show ) {
	if ( ! current_user_can( 'administrator' ) ) {
		return false;
	}

	return $show;
}
add_filter( 'show_admin_bar', 'js_hide_admin_bar' );

/**
 * Block wp-admin access for non-admins
 */
function ace_block_wp_admin() {
	if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
		wp_safe_redirect( home_url() );
		exit;
	}
}
add_action( 'admin_init', 'ace_block_wp_admin' );

WordPress: Bloquear wp-admin a no administradores Leer más »

Primera letra de cada custom post type

[wpv-layout-start]
    [wpv-items-found]
    <a href="[current_url]">All</a>
    <!-- wpv-loop-start -->
        <wpv-loop>
            <a href="?wpvalphabet=[wpv-taxonomy-title]">[wpv-taxonomy-title]</a>
        </wpv-loop>
    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found]
        <strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
    [/wpv-no-items-found]
[wpv-layout-end]
add_shortcode( 'current_url', function(){
    
    $request = $_SERVER['HTTP_HOST'].strtok($_SERVER["REQUEST_URI"],'?');
    $protocol = 'http://';
    
    if ( isset($_SERVER['HTTPS']) ) {
        $protocol = 'https://';
    }
    
    return $protocol . $request;
} );
wpv-layout-start]
[wpv-view name="alphabet-terms"]
[wpv-items-found]
<!-- wpv-loop-start -->
        <wpv-loop>
            <h3>[wpv-post-link]</h3>
        </wpv-loop>
    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found]
        <strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
    [/wpv-no-items-found]
[wpv-layout-end]
add_filter('wpv_filter_query', 'func_filter_by_title', 10, 2);
function func_filter_by_title($query, $setting) {
  
global $wpdb;
      
if($setting['view_id'] == 9999) {
          
        if(isset($_GET['wpvalphabet']) and $_GET['wpvalphabet']!='' ){
              
              
            $first_char = $_GET['wpvalphabet'];
            $postids = $wpdb->get_col($wpdb->prepare("SELECT      ID
                                                        FROM        $wpdb->posts
                                                        WHERE       SUBSTR($wpdb->posts.post_title,1,1) = %s
                                                        AND post_type = '".$query['post_type'][0]."'
                                                        AND post_status = 'publish'
                                                        ORDER BY    $wpdb->posts.post_title",$first_char)); 
                                                          
                  $query['post__in'] = $postids;
                  }
  }
return 

https://toolset.com/forums/topic/show-hidden-links/#post-1612419

Primera letra de cada custom post type Leer más »

Función para obtener y utilizar la url del tema en un shortcode

Shortcode para ahorrarnos poner ruta absoluta a la hora d eir a buscar recursos al directorio del tema. La imagen se encontrará dentro del tema utilizado:a función la insertamos dentro de functions.php

function theme_url_shortcode( $attrs = array (), $content = '' ) {
    $theme = ( is_child_theme() ? get_stylesheet_directory_uri() : get_template_directory_uri() );
    return $theme;  
}
add_shortcode('theme', 'theme_url_shortcode' );

Ejemplo de uso

<img src="[theme]/images/image-name.jpg" width="250" height="250" alt="This is an image" />

Visto en TheWebTaylor

Función para obtener y utilizar la url del tema en un shortcode Leer más »

Scroll al inicio

We are using cookies on our website

Please confirm, if you accept our tracking cookies. You can also decline the tracking, so you can continue to visit our website without any data sent to third party services.