Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * JNEWS || START CUSTOMIZATION
- *
- * Add video icon to meta for video format
- * We use DOMDocument to safely manipulate the HTML output of the meta, and add a video icon if the post format is video.
- * This way we don't have to override the entire meta rendering function, and we can keep compatibility with future updates of the theme.
- * We hook into the filters for the meta output of the modules, and modify the output if
- * the post format is video.
- * The code will look for the element with class "jeg_post_meta" and append a new div with class "jeg_meta_video" and a video camera icon inside it.
- * You can customize the HTML inside the fragment to change the icon or add more information.
- * Note: This code assumes that the meta output contains an element with class "jeg_post_meta". If the theme changes the structure of the meta output, this code may need to be updated accordingly.
- */
- add_filter( 'jnews_module_post_meta_1', 'custom_meta_for_video_format', 10, 3 );
- add_filter( 'jnews_module_post_meta_2', 'custom_meta_for_video_format', 10, 3 );
- add_filter( 'jnews_module_post_meta_3', 'custom_meta_for_video_format', 10, 3 );
- /**
- * Add custom meta for video format
- *
- * @param $output
- * @param $post
- * @param $instance
- *
- * @return string
- */
- function custom_meta_for_video_format( $output, $post, $instance ) {
- if ( has_post_format( 'video', $post->ID ) ) {
- libxml_use_internal_errors( true );
- $doc = new DOMDocument();
- // Load as HTML fragment without adding <html>/<body>
- $doc->loadHTML( '<?xml encoding="utf-8" ?>' . $output, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
- $xpath = new DOMXPath( $doc );
- // find first element with class "jeg_post_meta"
- $nodes = $xpath->query( "//*[contains(concat(' ', normalize-space(@class), ' '), ' jeg_post_meta ')]" );
- if ( $nodes->length ) {
- $meta = $nodes->item( 0 );
- // create a fragment for arbitrary HTML (safe insertion)
- $fragment = $doc->createDocumentFragment();
- // change the HTML below to whatever element you want to insert
- $fragment->appendXML( '<div class="jeg_meta_video"><i class="fa fa-video-camera"></i></div>' );
- $meta->appendChild( $fragment );
- }
- // export modified HTML (will return the fragment/document)
- $output = $doc->saveHTML();
- libxml_clear_errors();
- }
- return $output;
- }
- /**
- * JNEWS || END CUSTOMIZATION
- */
Advertisement
Add Comment
Please, Sign In to add comment