Writing New Styles for a Standard WordPress Media Player

Developers are always striving to create a unique design for their themes so that their solutions interest the maximum possible number of users in the WordPress ecosystem. And since WordPress comes with its widgets, shortcodes and other components, it is important that the theme takes all this into account and is appropriate for its purpose. Most native WordPress components (widgets or shortcodes, for example) do not have their own predefined styles, but some still have styling (for example, an audio player). In this article, we'll take a look at how to customize styles for a standard WordPress media player to fit the theme. WordPress Media Player WordPress Media Player is a wrapper based on MediaElement.js, a powerful, customizable player equipped with HTML5 capabilities. By default in WordPress it looks like this: In this tutorial, we will generate a set of predefined selectors for the player (along with an audio playlist in WordPress) so that it fits better with our theme. We start with the following: First, we will make the player brighter, which will suit most topics. Scripts and Styles First, let's create a my-theme-player.css file to accommodate arbitrary styles of the media player, and connect it accordingly (in theme functions.php): 01 <?php 02 add_action( 'wp_footer', 'ci_theme_footer_scripts' ); 03 04 function ci_theme_footer_scripts() 05 if ( wp_style_is( 'wp-mediaelement', 'enqueued' ) ) 06 wp_enqueue_style( 'my-theme-player', get_template_directory_uri(). '/css/my-theme-player.css', array( 07 'wp-mediaelement', 08 ), '1.0' ); 09 10 The snippet above ensures that our custom stylesheet will be loaded only when MediaElement styles are loaded (i.e. when there is a media player on the page) and always after them (we need our custom styles to load after the standard ones due to cascading). We also need to isolate the styles of our theme, i.e. assign a unique class to the player so that we can nest any selectors. This will limit the space of new styles only to our theme, without disrupting the work of other plugins that are based on the WordPress media player. 01 <?php 02 /** 03 * Add an HTML class to MediaElement.js container elements to aid styling. 04 * 05 * Extends the core _wpmejsSettings object to add a new feature via the 06 * MediaElement.js plugin API. 07 */ 08 add_action( 'wp_print_footer_scripts', 'mytheme_mejs_add_container_class' ); 09 10 function mytheme_mejs_add_container_class() 11 if (! wp_script_is( 'mediaelement', 'done' ) ) 12 return; 13 14 ?> 15 25 <?php 26 In the code, the .mytheme-mejs-container class has been added to the wrapper of the media player. You can change the mytheme prefix to whatever you like best (but then correct it everywhere in styles). Player styling In this guide, we will change the player’s theme to a lighter one, which will suit most projects. 01 /* Player background */ 02 .mytheme-mejs-container.mejs-container, 03 .mytheme-mejs-container .mejs-controls, 04 .mytheme-mejs-container .mejs-embed, 05 .mytheme-mejs-container .mejs-embed body 06 background-color: #efefef; 07 08 09 /* Player controls */ 10 .mytheme-mejs-container .mejs-button > button 11 background-image: url(images/mejs-controls-dark.svg); 12 13 14 .mytheme-mejs-container .mejs-time 15 color: #888888; 16 17 18 /* Progress and audio bars */ 19 20 /* Progress and audio bar background */ 21 .mytheme-mejs-container .mejs-controls .mejs-horizontal-volume-slider .mejs-horizontal-volume-total, 22 .mytheme-mejs-container .mejs-controls .mejs-time-rail .mejs-time-total 23 background-color: #fff; 24 25 26 /* Track progress bar background (amount of track fully loaded) 27 We prefer to style these with the main accent color of our theme */ 28 .mytheme-mejs-container .mejs-controls .mejs-time-rail .mejs-time-loaded 29 background-color: rgba(219, 78, 136, 0.075); 30 31 32 /* Current track progress and active audio volume level bar */ 33 .mytheme-mejs-container .mejs-controls .mejs-horizontal-volume-slider .mejs-horizontal-volume-current, 34 .mytheme-mejs-container .mejs-controls .mejs-time-rail .mejs-time-current 35 background: #db4e88; 36 37 38 /* Reduce height of the progress and Mobile Responsive Arcade Site Script v.1.6.0.1 Crack (https://nulledfree.pw/nulled-php-scripts/mobile-responsive-arcade-site-script-nulled-v-1-6-0-1-free-download/) audio bars */ 39 .mytheme-mejs-container .mejs-time-buffering, 40 .mytheme-mejs-container .mejs-time-current, 41 .mytheme-mejs-container .mejs-time-float, 42 .mytheme-mejs-container .mejs-time-float-corner, 43 .mytheme-mejs-container .mejs-time-float-current, 44 .mytheme-mejs-container .mejs-time-hovered, 45 .mytheme-mejs-container .mejs-time-loaded, 46 .mytheme-mejs-container .mejs-time-marker, 47 .mytheme-mejs-container .mejs-time-total, 48 .mytheme-mejs-container .mejs-horizontal-volume-total, 49 .mytheme-mejs-container .mejs-time-handle-content 50 height: 3px; 51 52 53 .mytheme-mejs-container .mejs-time-handle-content 54 top: -6px; 55 56 57 .mytheme-mejs-container .mejs-time-total 58 margin-top: 8px; 59 60 61 .mytheme-mejs-container .mejs-horizontal-volume-total 62 top: 19px; 63 The styles above will allow you to get such a player: Handsomely.

We changed the background color, text color, as well as the progress bar line. For Crack the buttons, you will need to create a new set of SVG icons with dark icons, WordPress Plugin Nulled since by default they are completely white. You can download the kit from the link. Add Technology IT Solutions & Services Elementor Template Kits Licence Key to the / images directory. As you noticed, there are a lot of nesting in the code. Unfortunately, we cannot do without them, since MediaElement.js is already so stylized, and we need our own container class.

You can optionally use preprocessors such as LESS or Sass. Styling Media Playlists Each time you create a playlist on a page or post and select more than one audio file for it, WordPress will bring the player to you in playlist mode. By default, it looks like this: WordPress wraps playlists in its own container, not related to MediaElement.js, and IP Restriction v.1.2.8.1 Nulled the following styles will help you better visualize them: 01 .wp-playlist-light 02 box-shadow: 3px 3px 0 #e2e2e2; 03 04 05 /* Captions — Track titles / subtitles, time */ 06 .wp-playlist-light .wp-playlist-caption, 07 .wp-playlist-light .wp-playlist-item-length 08 color: #787878; 09 10 11 /* Captions — Current track */ 12 .wp-playlist-light .wp-playlist-current-item .wp-playlist-item-title 13 font-size: 16px; 14 15 16 .wp-playlist-light .wp-playlist-item-album 17 font-style: Multi-Concept Blog / Magazine WordPress Theme Download normal; 18 19 20.

0 комментариев

Автор топика запретил добавлять комментарии