Articles of underscore

Getting custom post type author and date published

In underscores I can get my custom post type just fine with pre get posts along regular blog posts. However the date published and author does not display. How can I modify my template tag (themeslug_posted_on) to show them as well? My pre get posts filter: add_filter( ‘pre_get_posts’, ‘get_my_cpt’ ); function get_my_cpt( $query ) { […]

How to use underscore.js in WordPress Admin

I am trying to use underscore in my WordPress Admin. This is what I have done: I enqueue a script in the very end of the page, like so: function load_admin_scripts() { wp_enqueue_script( “my-admin”, get_template_directory_uri() . “/assets/scripts/admin.js”, array(‘jquery’, ‘wp-util’), null, true ); } add_action(‘admin_enqueue_scripts’, ‘load_admin_scripts’); …then in the script file, I am at the moment […]

How to Dequeue All WordPress Assets

I want to dequeue all styles and scripts that are loaded on the front-end (EG. not the admin panel) by default. I found this function, but am not sure how to utilize it to accomplish my goal. I’m seeing a ton of assets that I don’t need on the front end, loaded by WP core: […]

Customizer Ajax

This is the JavaScript code used in the underscores theme to preview any change of the setting value without reloading the previewer: // Site title and description. wp.customize( ‘blogname’, function( value ) { value.bind( function( to ) { $( ‘.site-title a’ ).text( to ); } ); } ); Instead of using this (from the code […]

Remove H1 / title / Underscore – without CSS

I have tried searching, and tried a few options, but I’m not able to remove the H1 / title / Underscore for specific pages. I don’t want use CSS. I would like to remove it via functions.php or in content.php. I’m not good in PHP, so the Codex didn’t help me too much. I need […]

What type of template are WP media-modal's templates?

I was looking at the WordPress templates (html that’s written to the page instead of awkwardly adding strings in JS). There are a lot of templates like this in a post editor for example: <script type=”text/html” id=”tmpl-uploader-status-error”> <span class=”upload-error-filename”>{{{ data.filename }}}</span> <span class=”upload-error-message”>{{ data.message }}</span> </script> Now, I know these can be referenced with‘uploader-status-error’)( […]

WP Customizer JS Template not saving color field

I’m trying to create a custom typography control, I’m having problem saving the value of the color, please take a look at my code: <?php class Customizer_Typo_Control_Typography extends WP_Customize_Control { /** * The type of customize control being rendered. */ public $type = ‘typography’; /** * Array */ public $l10n = array(); /** * Set […]

Open media frame and select an attachment

I’m using the following piece of code to open a media frame when clicking a link with a data-attachment_id attribute. This attribute holds the id of an attachment that I want to select when the frame opens: jQuery(document).ready(function($){ $( ‘#gallery_images_container’ ).on( ‘click’, ‘a.edit’, function( event ) { var $el = $( this ); var selected […]

Can I add custom attributes while adding inline scripts?

I need to inject some underscore templates into admin screen without modifying the core. The templates look like this: <script type=”text/template” id=”template-123″> <div class=”section intro”> {{{ data.section.intro }}} </div> <div class=”section content”> {{{ data.section.content }}} </div> … </script> All templates depend on certain script handle, so I thought about using wp_add_inline_script() but it doesn’t allow […]

Using Underscore Templates in WordPress

I’ve noticed that since WP 3.5 that we now have the Backbone.js and Underscore.js libraries included. The new Media Modal uses Underscore templates and I was wondering how would I be able to insert them, especially in the admin side of things.Is there a correct way to insert these?