Advertisement
Guest User

Untitled

a guest
Nov 20th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.87 KB | None | 0 0
  1. <?php
  2. /**
  3. * Twenty Sixteen functions and definitions
  4. *
  5. * Set up the theme and provides some helper functions, which are used in the
  6. * theme as custom template tags. Others are attached to action and filter
  7. * hooks in WordPress to change core functionality.
  8. *
  9. * When using a child theme you can override certain functions (those wrapped
  10. * in a function_exists() call) by defining them first in your child theme's
  11. * functions.php file. The child theme's functions.php file is included before
  12. * the parent theme's file, so the child theme functions would be used.
  13. *
  14. * @link https://codex.wordpress.org/Theme_Development
  15. * @link https://codex.wordpress.org/Child_Themes
  16. *
  17. * Functions that are not pluggable (not wrapped in function_exists()) are
  18. * instead attached to a filter or action hook.
  19. *
  20. * For more information on hooks, actions, and filters,
  21. * {@link https://codex.wordpress.org/Plugin_API}
  22. *
  23. * @package WordPress
  24. * @subpackage Twenty_Sixteen
  25. * @since Twenty Sixteen 1.0
  26. */
  27.  
  28. /**
  29. * Twenty Sixteen only works in WordPress 4.4 or later.
  30. */
  31. if ( version_compare( $GLOBALS['wp_version'], '4.4-alpha', '<' ) ) {
  32. require get_template_directory() . '/inc/back-compat.php';
  33. }
  34.  
  35. if ( ! function_exists( 'twentysixteen_setup' ) ) :
  36. /**
  37. * Sets up theme defaults and registers support for various WordPress features.
  38. *
  39. * Note that this function is hooked into the after_setup_theme hook, which
  40. * runs before the init hook. The init hook is too late for some features, such
  41. * as indicating support for post thumbnails.
  42. *
  43. * Create your own twentysixteen_setup() function to override in a child theme.
  44. *
  45. * @since Twenty Sixteen 1.0
  46. */
  47. function twentysixteen_setup() {
  48. /*
  49. * Make theme available for translation.
  50. * Translations can be filed in the /languages/ directory.
  51. * If you're building a theme based on Twenty Sixteen, use a find and replace
  52. * to change 'twentysixteen' to the name of your theme in all the template files
  53. */
  54. load_theme_textdomain( 'twentysixteen', get_template_directory() . '/languages' );
  55.  
  56. // Add default posts and comments RSS feed links to head.
  57. add_theme_support( 'automatic-feed-links' );
  58.  
  59. /*
  60. * Let WordPress manage the document title.
  61. * By adding theme support, we declare that this theme does not use a
  62. * hard-coded <title> tag in the document head, and expect WordPress to
  63. * provide it for us.
  64. */
  65. add_theme_support( 'title-tag' );
  66.  
  67. /*
  68. * Enable support for custom logo.
  69. *
  70. * @since Twenty Sixteen 1.2
  71. */
  72. add_theme_support( 'custom-logo', array(
  73. 'height' => 240,
  74. 'width' => 240,
  75. 'flex-height' => true,
  76. ) );
  77.  
  78. /*
  79. * Enable support for Post Thumbnails on posts and pages.
  80. *
  81. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  82. */
  83. /* add_theme_support( 'post-thumbnails' );
  84. set_post_thumbnail_size( 1200, 9999, true );*/
  85. if ( function_exists( 'add_theme_support' ) ) {
  86. add_theme_support( 'post-thumbnails' );
  87. set_post_thumbnail_size( 1200, 9999 ); // default Post Thumbnail dimensions
  88. }
  89.  
  90. if ( function_exists( 'add_image_size' ) ) {
  91. add_image_size( 'first-thumb', 799, 490, true ); //300 pixels wide (and unlimited height)
  92. add_image_size( 'other-thumb', 384, 267, true ); //(cropped)
  93. }
  94.  
  95.  
  96. // This theme uses wp_nav_menu() in two locations.
  97. register_nav_menus( array(
  98. 'primary' => __( 'Primary Menu', 'twentysixteen' ),
  99. 'social' => __( 'Social Links Menu', 'twentysixteen' ),
  100. ) );
  101.  
  102. /*
  103. * Switch default core markup for search form, comment form, and comments
  104. * to output valid HTML5.
  105. */
  106. add_theme_support( 'html5', array(
  107. 'search-form',
  108. 'comment-form',
  109. 'comment-list',
  110. 'gallery',
  111. 'caption',
  112. ) );
  113.  
  114. /*
  115. * Enable support for Post Formats.
  116. *
  117. * See: https://codex.wordpress.org/Post_Formats
  118. */
  119. add_theme_support( 'post-formats', array(
  120. 'aside',
  121. 'image',
  122. 'video',
  123. 'quote',
  124. 'link',
  125. 'gallery',
  126. 'status',
  127. 'audio',
  128. 'chat',
  129. ) );
  130.  
  131. /*
  132. * This theme styles the visual editor to resemble the theme style,
  133. * specifically font, colors, icons, and column width.
  134. */
  135. add_editor_style( array( 'css/editor-style.css', twentysixteen_fonts_url() ) );
  136.  
  137. // Indicate widget sidebars can use selective refresh in the Customizer.
  138. add_theme_support( 'customize-selective-refresh-widgets' );
  139. }
  140. endif; // twentysixteen_setup
  141. add_action( 'after_setup_theme', 'twentysixteen_setup' );
  142.  
  143. /**
  144. * Sets the content width in pixels, based on the theme's design and stylesheet.
  145. *
  146. * Priority 0 to make it available to lower priority callbacks.
  147. *
  148. * @global int $content_width
  149. *
  150. * @since Twenty Sixteen 1.0
  151. */
  152. function twentysixteen_content_width() {
  153. $GLOBALS['content_width'] = apply_filters( 'twentysixteen_content_width', 840 );
  154. }
  155. add_action( 'after_setup_theme', 'twentysixteen_content_width', 0 );
  156.  
  157. /**
  158. * Registers a widget area.
  159. *
  160. * @link https://developer.wordpress.org/reference/functions/register_sidebar/
  161. *
  162. * @since Twenty Sixteen 1.0
  163. */
  164. function twentysixteen_widgets_init() {
  165. register_sidebar( array(
  166. 'name' => __( 'Sidebar', 'twentysixteen' ),
  167. 'id' => 'sidebar-1',
  168. 'description' => __( 'Add widgets here to appear in your sidebar.', 'twentysixteen' ),
  169. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  170. 'after_widget' => '</section>',
  171. 'before_title' => '<h2 class="widget-title">',
  172. 'after_title' => '</h2>',
  173. ) );
  174.  
  175. register_sidebar( array(
  176. 'name' => __( 'Content Bottom 1', 'twentysixteen' ),
  177. 'id' => 'sidebar-2',
  178. 'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
  179. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  180. 'after_widget' => '</section>',
  181. 'before_title' => '<h2 class="widget-title">',
  182. 'after_title' => '</h2>',
  183. ) );
  184.  
  185. register_sidebar( array(
  186. 'name' => __( 'Content Bottom 2', 'twentysixteen' ),
  187. 'id' => 'sidebar-3',
  188. 'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
  189. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  190. 'after_widget' => '</section>',
  191. 'before_title' => '<h2 class="widget-title">',
  192. 'after_title' => '</h2>',
  193. ) );
  194. }
  195. add_action( 'widgets_init', 'twentysixteen_widgets_init' );
  196.  
  197. if ( ! function_exists( 'twentysixteen_fonts_url' ) ) :
  198. /**
  199. * Register Google fonts for Twenty Sixteen.
  200. *
  201. * Create your own twentysixteen_fonts_url() function to override in a child theme.
  202. *
  203. * @since Twenty Sixteen 1.0
  204. *
  205. * @return string Google fonts URL for the theme.
  206. */
  207. function twentysixteen_fonts_url() {
  208. $fonts_url = '';
  209. $fonts = array();
  210. $subsets = 'latin,latin-ext';
  211.  
  212. /* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */
  213. if ( 'off' !== _x( 'on', 'Merriweather font: on or off', 'twentysixteen' ) ) {
  214. $fonts[] = 'Merriweather:400,700,900,400italic,700italic,900italic';
  215. }
  216.  
  217. /* translators: If there are characters in your language that are not supported by Montserrat, translate this to 'off'. Do not translate into your own language. */
  218. if ( 'off' !== _x( 'on', 'Montserrat font: on or off', 'twentysixteen' ) ) {
  219. $fonts[] = 'Montserrat:400,700';
  220. }
  221.  
  222. /* translators: If there are characters in your language that are not supported by Inconsolata, translate this to 'off'. Do not translate into your own language. */
  223. if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentysixteen' ) ) {
  224. $fonts[] = 'Inconsolata:400';
  225. }
  226.  
  227. if ( $fonts ) {
  228. $fonts_url = add_query_arg( array(
  229. 'family' => urlencode( implode( '|', $fonts ) ),
  230. 'subset' => urlencode( $subsets ),
  231. ), 'https://fonts.googleapis.com/css' );
  232. }
  233.  
  234. return $fonts_url;
  235. }
  236. endif;
  237.  
  238. /**
  239. * Handles JavaScript detection.
  240. *
  241. * Adds a `js` class to the root `<html>` element when JavaScript is detected.
  242. *
  243. * @since Twenty Sixteen 1.0
  244. */
  245. function twentysixteen_javascript_detection() {
  246. echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
  247. }
  248. add_action( 'wp_head', 'twentysixteen_javascript_detection', 0 );
  249.  
  250. /**
  251. * Enqueues scripts and styles.
  252. *
  253. * @since Twenty Sixteen 1.0
  254. */
  255. function twentysixteen_scripts() {
  256. // Add custom fonts, used in the main stylesheet.
  257. wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), null );
  258.  
  259. // Add Genericons, used in the main stylesheet.
  260. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );
  261.  
  262. // Theme stylesheet.
  263. wp_enqueue_style( 'twentysixteen-style', get_stylesheet_uri() );
  264.  
  265. // Load the Internet Explorer specific stylesheet.
  266. wp_enqueue_style( 'twentysixteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentysixteen-style' ), '20160412' );
  267. wp_style_add_data( 'twentysixteen-ie', 'conditional', 'lt IE 10' );
  268.  
  269. // Load the Internet Explorer 8 specific stylesheet.
  270. wp_enqueue_style( 'twentysixteen-ie8', get_template_directory_uri() . '/css/ie8.css', array( 'twentysixteen-style' ), '20160412' );
  271. wp_style_add_data( 'twentysixteen-ie8', 'conditional', 'lt IE 9' );
  272.  
  273. // Load the Internet Explorer 7 specific stylesheet.
  274. wp_enqueue_style( 'twentysixteen-ie7', get_template_directory_uri() . '/css/ie7.css', array( 'twentysixteen-style' ), '20160412' );
  275. wp_style_add_data( 'twentysixteen-ie7', 'conditional', 'lt IE 8' );
  276.  
  277. // Load the html5 shiv.
  278. wp_enqueue_script( 'twentysixteen-html5', get_template_directory_uri() . '/js/html5.js', array(), '3.7.3' );
  279. wp_script_add_data( 'twentysixteen-html5', 'conditional', 'lt IE 9' );
  280.  
  281. wp_enqueue_script( 'twentysixteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20160412', true );
  282.  
  283. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  284. wp_enqueue_script( 'comment-reply' );
  285. }
  286.  
  287. if ( is_singular() && wp_attachment_is_image() ) {
  288. wp_enqueue_script( 'twentysixteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20160412' );
  289. }
  290.  
  291. wp_enqueue_script( 'twentysixteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20160412', true );
  292.  
  293. wp_localize_script( 'twentysixteen-script', 'screenReaderText', array(
  294. 'expand' => __( 'expand child menu', 'twentysixteen' ),
  295. 'collapse' => __( 'collapse child menu', 'twentysixteen' ),
  296. ) );
  297. }
  298. add_action( 'wp_enqueue_scripts', 'twentysixteen_scripts' );
  299.  
  300. /**
  301. * Adds custom classes to the array of body classes.
  302. *
  303. * @since Twenty Sixteen 1.0
  304. *
  305. * @param array $classes Classes for the body element.
  306. * @return array (Maybe) filtered body classes.
  307. */
  308. function twentysixteen_body_classes( $classes ) {
  309. // Adds a class of custom-background-image to sites with a custom background image.
  310. if ( get_background_image() ) {
  311. $classes[] = 'custom-background-image';
  312. }
  313.  
  314. // Adds a class of group-blog to sites with more than 1 published author.
  315. if ( is_multi_author() ) {
  316. $classes[] = 'group-blog';
  317. }
  318.  
  319. // Adds a class of no-sidebar to sites without active sidebar.
  320. if ( ! is_active_sidebar( 'sidebar-1' ) ) {
  321. $classes[] = 'no-sidebar';
  322. }
  323.  
  324. // Adds a class of hfeed to non-singular pages.
  325. if ( ! is_singular() ) {
  326. $classes[] = 'hfeed';
  327. }
  328.  
  329. return $classes;
  330. }
  331. add_filter( 'body_class', 'twentysixteen_body_classes' );
  332.  
  333. /**
  334. * Converts a HEX value to RGB.
  335. *
  336. * @since Twenty Sixteen 1.0
  337. *
  338. * @param string $color The original color, in 3- or 6-digit hexadecimal form.
  339. * @return array Array containing RGB (red, green, and blue) values for the given
  340. * HEX code, empty array otherwise.
  341. */
  342. function twentysixteen_hex2rgb( $color ) {
  343. $color = trim( $color, '#' );
  344.  
  345. if ( strlen( $color ) === 3 ) {
  346. $r = hexdec( substr( $color, 0, 1 ).substr( $color, 0, 1 ) );
  347. $g = hexdec( substr( $color, 1, 1 ).substr( $color, 1, 1 ) );
  348. $b = hexdec( substr( $color, 2, 1 ).substr( $color, 2, 1 ) );
  349. } else if ( strlen( $color ) === 6 ) {
  350. $r = hexdec( substr( $color, 0, 2 ) );
  351. $g = hexdec( substr( $color, 2, 2 ) );
  352. $b = hexdec( substr( $color, 4, 2 ) );
  353. } else {
  354. return array();
  355. }
  356.  
  357. return array( 'red' => $r, 'green' => $g, 'blue' => $b );
  358. }
  359.  
  360. /**
  361. * Custom template tags for this theme.
  362. */
  363. require get_template_directory() . '/inc/template-tags.php';
  364.  
  365. /**
  366. * Customizer additions.
  367. */
  368. require get_template_directory() . '/inc/customizer.php';
  369.  
  370. /**
  371. * Add custom image sizes attribute to enhance responsive image functionality
  372. * for content images
  373. *
  374. * @since Twenty Sixteen 1.0
  375. *
  376. * @param string $sizes A source size value for use in a 'sizes' attribute.
  377. * @param array $size Image size. Accepts an array of width and height
  378. * values in pixels (in that order).
  379. * @return string A source size value for use in a content image 'sizes' attribute.
  380. */
  381. function twentysixteen_content_image_sizes_attr( $sizes, $size ) {
  382. $width = $size[0];
  383.  
  384. 840 <= $width && $sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px';
  385.  
  386. if ( 'page' === get_post_type() ) {
  387. 840 > $width && $sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
  388. } else {
  389. 840 > $width && 600 <= $width && $sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px';
  390. 600 > $width && $sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
  391. }
  392.  
  393. return $sizes;
  394. }
  395. add_filter( 'wp_calculate_image_sizes', 'twentysixteen_content_image_sizes_attr', 10 , 2 );
  396.  
  397. /**
  398. * Add custom image sizes attribute to enhance responsive image functionality
  399. * for post thumbnails
  400. *
  401. * @since Twenty Sixteen 1.0
  402. *
  403. * @param array $attr Attributes for the image markup.
  404. * @param int $attachment Image attachment ID.
  405. * @param array $size Registered image size or flat array of height and width dimensions.
  406. * @return string A source size value for use in a post thumbnail 'sizes' attribute.
  407. */
  408. function twentysixteen_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
  409. if ( 'post-thumbnail' === $size ) {
  410. is_active_sidebar( 'sidebar-1' ) && $attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 60vw, (max-width: 1362px) 62vw, 840px';
  411. ! is_active_sidebar( 'sidebar-1' ) && $attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 88vw, 1200px';
  412. }
  413. return $attr;
  414. }
  415. add_filter( 'wp_get_attachment_image_attributes', 'twentysixteen_post_thumbnail_sizes_attr', 10 , 3 );
  416.  
  417. /**
  418. * Modifies tag cloud widget arguments to have all tags in the widget same font size.
  419. *
  420. * @since Twenty Sixteen 1.1
  421. *
  422. * @param array $args Arguments for tag cloud widget.
  423. * @return array A new modified arguments.
  424. */
  425. function twentysixteen_widget_tag_cloud_args( $args ) {
  426. $args['largest'] = 1;
  427. $args['smallest'] = 1;
  428. $args['unit'] = 'em';
  429. return $args;
  430. }
  431. add_filter( 'widget_tag_cloud_args', 'twentysixteen_widget_tag_cloud_args' );
  432.  
  433. /* Codice per impostare come termina l'excerpt by Roberto Iacono di robertoiacono.it
  434. function ri_new_excerpt_more($more) {
  435. global $post;
  436. return ' ...<a href="'. get_permalink($post->ID) . '"><br/><br/>READ MORE</a>';
  437. }
  438. add_filter('excerpt_more', 'ri_new_excerpt_more');*/
  439.  
  440.  
  441. // Add span class to widget headlines
  442. add_filter( 'widget_title', 'metro_widget_title' );
  443. function metro_widget_title( $title ){
  444. if( $title )
  445. return sprintf('<span class="widget-headline">%s</span>', $title );
  446. }
  447.  
  448. // enqueue font awesome
  449. add_action( 'wp_enqueue_scripts', 'prefix_enqueue_awesome' );
  450. function prefix_enqueue_awesome() {
  451. wp_enqueue_style( 'prefix-font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css', array(), '4.1.0' );
  452. }
  453. // funzione per aggiungere scripts al tema
  454. function add_theme_scripts() {
  455. wp_enqueue_script('custom_script',get_template_directory_uri() . '/js/sticky.js', array('jquery'));
  456. }
  457. add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );
  458.  
  459.  
  460.  
  461. register_sidebar( array(
  462. 'name' => 'Footer Sidebar 1',
  463. 'id' => 'footer-sidebar-1',
  464. 'description' => 'Questo widget apparirà nel footer 1',
  465. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  466. 'after_widget' => '</section>',
  467. 'before_title' => '<h2 class="widget-title">',
  468. 'after_title' => '</h2>',
  469. ) );
  470. register_sidebar( array(
  471. 'name' => 'Footer Sidebar 2',
  472. 'id' => 'footer-sidebar-2',
  473. 'description' => 'Questa widget apparirà nel footer 2',
  474. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  475. 'after_widget' => '</section>',
  476. 'before_title' => '<h2 class="widget-title">',
  477. 'after_title' => '</h2>',
  478. ) );
  479. register_sidebar( array(
  480. 'name' => 'Footer Sidebar 3',
  481. 'id' => 'footer-sidebar-3',
  482. 'description' => 'Questo widget apparirà nel footer 3',
  483. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  484. 'after_widget' => '</section>',
  485. 'before_title' => '<h2 class="widget-title">',
  486. 'after_title' => '</h2>',
  487. ) );
  488.  
  489.  
  490. function ri_php_text($text) {
  491. if (strpos($text, '<' . '?') !== false) { ob_start(); eval('?' . '>' . $text);
  492. $text = ob_get_contents();
  493. ob_end_clean();
  494. }
  495. return $text;
  496. }
  497. add_filter('widget_text', 'ri_php_text', 99);
  498.  
  499.  
  500. /* Codice per modificare la lunghezza dell'excerpt by Roberto Iacono di robertoiacono.it
  501. function my_excerpt_length($length) {
  502. return 60;
  503. }
  504. add_filter('excerpt_length', 'my_excerpt_length');*/
  505.  
  506.  
  507.  
  508. //Formattazione nell' excerpt
  509.  
  510. function wpse_allowedtags() {
  511. // Add custom tags to this string
  512. return '<script>,<style>,<br>,<pre>,<em>,<i>,<ul>,<ol>,<li>,<a>,<p>,<img>,<video>,<audio>';
  513. }
  514.  
  515. if ( ! function_exists( 'wpse_custom_wp_trim_excerpt' ) ) :
  516.  
  517. function wpse_custom_wp_trim_excerpt($wpse_excerpt) {
  518. global $post;
  519. $raw_excerpt = $wpse_excerpt;
  520. if ( '' == $wpse_excerpt ) {
  521.  
  522. $wpse_excerpt = get_the_content('');
  523. $wpse_excerpt = strip_shortcodes( $wpse_excerpt );
  524. $wpse_excerpt = apply_filters('the_content', $wpse_excerpt);
  525. $wpse_excerpt = str_replace(']]>', ']]>', $wpse_excerpt);
  526. $wpse_excerpt = strip_tags($wpse_excerpt, wpse_allowedtags()); /*IF you need to allow just certain tags. Delete if all tags are allowed */
  527.  
  528. //Set the excerpt word count and only break after sentence is complete.
  529. $excerpt_word_count = 300;
  530. $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count);
  531. $tokens = array();
  532. $excerptOutput = '';
  533. $count = 0;
  534.  
  535. // Divide the string into tokens; HTML tags, or words, followed by any whitespace
  536. preg_match_all('/(<[^>]+>|[^<>\s]+)\s*/u', $wpse_excerpt, $tokens);
  537.  
  538. foreach ($tokens[0] as $token) {
  539.  
  540. $excerptOutput .= $token;
  541.  
  542. $excerptOutputWithoutTags = strip_tags(trim($excerptOutput));
  543.  
  544. if (strlen($excerptOutputWithoutTags) >= $excerpt_word_count){
  545. break;
  546. }
  547. }
  548.  
  549. $wpse_excerpt = trim(force_balance_tags($excerptOutput));
  550.  
  551. $excerpt_end = '... <br/><br/> <a style="font-family: Merriweather, Georgia, serif; font-size: 0.75rem; text-transform: uppercase;" href="'. esc_url( get_permalink() ) . '">' . '' . sprintf(__( 'Read more: %s ', 'wpse' ), get_the_title()) . '</a>';
  552. $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end);
  553.  
  554. $pos = strrpos($wpse_excerpt, '</');
  555. if ($pos !== false)
  556. // Inside last HTML tag
  557. $wpse_excerpt = substr_replace($wpse_excerpt, $excerpt_end, $pos, 0); /* Add read more next to last word */
  558. //else
  559. // After the content
  560. //$wpse_excerpt .= $excerpt_end; /*Add read more in new paragraph */
  561.  
  562. return $wpse_excerpt;
  563.  
  564. }
  565. return apply_filters('wpse_custom_wp_trim_excerpt', $wpse_excerpt, $raw_excerpt);
  566. }
  567.  
  568. endif;
  569.  
  570. remove_filter('get_the_excerpt', 'wp_trim_excerpt');
  571. add_filter('get_the_excerpt', 'wpse_custom_wp_trim_excerpt');
  572.  
  573.  
  574.  
  575. function insert_image_src_rel_in_head() {
  576. global $post;
  577. if ( !is_singular()) //se non si tratta di un post o di una pagina
  578. return;
  579. if(!has_post_thumbnail( $post->ID )) { //articolo privo di featured image, utilizza quindi la default scelta
  580. $default_image="http://VOSTROURL/IMMAGINEDEFAULT.jpg"; //Modifica URL e nome immagine con quelli del tuo blog
  581. echo '<meta property="og:image" content="' . $default_image . '"/>';
  582. } else {
  583. $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'first-thumb' );
  584. echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
  585. }
  586. echo "";
  587. }
  588. add_action( 'wp_head', 'insert_image_src_rel_in_head', 5 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement