Advertisement
Guest User

functions code

a guest
Jan 27th, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 38.86 KB | None | 0 0
  1. <?php
  2. /**
  3.  * ifood-theme functions and definitions
  4.  *
  5.  * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6.  *
  7.  * @package ifood-theme
  8.  */
  9.  
  10. if ( ! function_exists( 'ifood_theme_setup' ) ) :
  11.     /**
  12.      * Sets up theme defaults and registers support for various WordPress features.
  13.      *
  14.      * Note that this function is hooked into the after_setup_theme hook, which
  15.      * runs before the init hook. The init hook is too late for some features, such
  16.      * as indicating support for post thumbnails.
  17.      */
  18.     function ifood_theme_setup() {
  19.         /*
  20.          * Make theme available for translation.
  21.          * Translations can be filed in the /languages/ directory.
  22.          * If you're building a theme based on ifood-theme, use a find and replace
  23.          * to change 'ifood-theme' to the name of your theme in all the template files.
  24.          */
  25.         load_theme_textdomain( 'ifood-theme', get_template_directory() . '/languages' );
  26.  
  27.         // Add default posts and comments RSS feed links to head.
  28.         add_theme_support( 'automatic-feed-links' );
  29.  
  30.         /*
  31.          * Let WordPress manage the document title.
  32.          * By adding theme support, we declare that this theme does not use a
  33.          * hard-coded <title> tag in the document head, and expect WordPress to
  34.          * provide it for us.
  35.          */
  36.         add_theme_support( 'title-tag' );
  37.  
  38.         /*
  39.          * Enable support for Post Thumbnails on posts and pages.
  40.          *
  41.          * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  42.          */
  43.         add_theme_support( 'post-thumbnails' );
  44.  
  45.     add_image_size( 'feature-post-thumbnail', 600, 600, true );// Hard Crop Mode
  46.     add_image_size( 'regular-post-thumbnail', 560, 505, true );// Hard Crop Mode
  47.     add_image_size( 'video-post-thumbnail', 426, 240, true );// Hard Crop Mode
  48.  
  49.         // This theme uses wp_nav_menu() in one location.
  50.         register_nav_menus( array(
  51.             'primary' => esc_html__( 'Primary', 'ifood-theme' ),
  52.       'top' => esc_html__( 'Top', 'ifood-theme' ),
  53.       'footer' => esc_html__( 'Footer', 'ifood-theme' ),
  54.       'responsive' => esc_html__( 'Responsive', 'ifood-theme' ),
  55.             'front' => esc_html__( 'Front', 'ifood-theme' ),
  56.             'indexfirst' => esc_html__( 'Index First', 'ifood-theme' ),
  57.             'indexsecond' => esc_html__( 'Index Second', 'ifood-theme' ),
  58.             'indexthird' => esc_html__( 'Index Third', 'ifood-theme' ),
  59.             'indexfourth' => esc_html__( 'Index Fourth', 'ifood-theme' ),
  60.             'indexfifth' => esc_html__( 'Index Fifth', 'ifood-theme' ),
  61.         ) );
  62.  
  63.         /*
  64.          * Switch default core markup for search form, comment form, and comments
  65.          * to output valid HTML5.
  66.          */
  67.         add_theme_support( 'html5', array(
  68.             'search-form',
  69.             'comment-form',
  70.             'comment-list',
  71.             'gallery',
  72.             'caption',
  73.         ) );
  74.  
  75.         // Set up the WordPress core custom background feature.
  76.         add_theme_support( 'custom-background', apply_filters( 'ifood_theme_custom_background_args', array(
  77.             'default-color' => 'ffffff',
  78.             'default-image' => '',
  79.         ) ) );
  80.  
  81.         // Add theme support for selective refresh for widgets.
  82.         add_theme_support( 'customize-selective-refresh-widgets' );
  83.  
  84.     }
  85. endif;
  86. add_action( 'after_setup_theme', 'ifood_theme_setup' );
  87.  
  88. /**
  89.  * Set the content width in pixels, based on the theme's design and stylesheet.
  90.  *
  91.  * Priority 0 to make it available to lower priority callbacks.
  92.  *
  93.  * @global int $content_width
  94.  */
  95. function ifood_theme_content_width() {
  96.     $GLOBALS['content_width'] = apply_filters( 'ifood_theme_content_width', 640 );
  97. }
  98. add_action( 'after_setup_theme', 'ifood_theme_content_width', 0 );
  99.  
  100. /**
  101.  * Register widget area.
  102.  *
  103.  * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  104.  */
  105.  function ifood_theme_widgets_init() {
  106.    register_sidebar( array(
  107.      'name'          => esc_html__( 'very-top-widget-mobile', 'ifood-theme' ),
  108.      'id'            => 'very-top-widget',
  109.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  110.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  111.      'after_widget'  => '</section>',
  112.      'before_title'  => '<h2 class="widget-title">',
  113.      'after_title'   => '</h2>',
  114.    ) );
  115.      register_sidebar( array(
  116.          'name'          => esc_html__( 'very-top-widget-desktop', 'ifood-theme' ),
  117.          'id'            => 'very-top-widget-desktop',
  118.          'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  119.          'before_widget' => '<section id="%1$s" class="widget %2$s">',
  120.          'after_widget'  => '</section>',
  121.          'before_title'  => '<h2 class="widget-title">',
  122.          'after_title'   => '</h2>',
  123.      ) );
  124.    register_sidebar( array(
  125.      'name'          => esc_html__( 'header-widget-left', 'ifood-theme' ),
  126.      'id'            => 'header-widget-left',
  127.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  128.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  129.      'after_widget'  => '</section>',
  130.      'before_title'  => '<h2 class="widget-title">',
  131.      'after_title'   => '</h2>',
  132.    ) );
  133.    register_sidebar( array(
  134.      'name'          => esc_html__( 'header-widget-right', 'ifood-theme' ),
  135.      'id'            => 'header-widget-right',
  136.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  137.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  138.      'after_widget'  => '</section>',
  139.      'before_title'  => '<h2 class="widget-title">',
  140.      'after_title'   => '</h2>',
  141.    ) );
  142.      register_sidebar( array(
  143.          'name'          => esc_html__( 'header-hero-ad', 'ifood-theme' ),
  144.          'id'            => 'header-hero-ad',
  145.          'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  146.          'before_widget' => '<section id="%1$s" class="widget %2$s">',
  147.          'after_widget'  => '</section>',
  148.          'before_title'  => '<h2 class="widget-title">',
  149.          'after_title'   => '</h2>',
  150.      ) );
  151.      register_sidebar( array(
  152.      'name'          => esc_html__( 'top-hero-container-widget', 'ifood-theme' ),
  153.      'id'            => 'top-hero-container-widget',
  154.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  155.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  156.      'after_widget'  => '</section>',
  157.      'before_title'  => '<h2 class="widget-title">',
  158.      'after_title'   => '</h2>',
  159.    ) );
  160.    register_sidebar( array(
  161.      'name'          => esc_html__( 'front-widget-feature-tower', 'ifood-theme' ),
  162.      'id'            => 'front-widget-feature-tower',
  163.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  164.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  165.      'after_widget'  => '</section>',
  166.      'before_title'  => '<h2 class="widget-title">',
  167.      'after_title'   => '</h2>',
  168.    ) );
  169.    register_sidebar( array(
  170.      'name'          => esc_html__( 'front-page-below-feature-tower-ad', 'ifood-theme' ),
  171.      'id'            => 'front-page-add-top-widget',
  172.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  173.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  174.      'after_widget'  => '</section>',
  175.      'before_title'  => '<h3 class="display widget-title">',
  176.      'after_title'   => '</h3>',
  177.    ) );
  178.    register_sidebar( array(
  179.      'name'          => esc_html__( 'front-page-video', 'ifood-theme' ),
  180.      'id'            => 'front-widget-video',
  181.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  182.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  183.      'after_widget'  => '</section>',
  184.      'before_title'  => '<h3 class="display widget-title">',
  185.      'after_title'   => '</h3>',
  186.    ) );
  187.    register_sidebar( array(
  188.      'name'          => esc_html__( 'front-page-video-scroll', 'ifood-theme' ),
  189.      'id'            => 'front-widget-video-scroll',
  190.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  191.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  192.      'after_widget'  => '</section>',
  193.      'before_title'  => '<h3 class="display widget-title">',
  194.      'after_title'   => '</h3>',
  195.    ) );
  196.    register_sidebar( array(
  197.      'name'          => esc_html__( 'front-page-video-scroll-mobile', 'ifood-theme' ),
  198.      'id'            => 'front-widget-video-posts',
  199.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  200.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  201.      'after_widget'  => '</section>',
  202.      'before_title'  => '<h3 class="display widget-title">',
  203.      'after_title'   => '</h3>',
  204.    ) );
  205.    register_sidebar( array(
  206.      'name'          => esc_html__( 'front-page-new-recipes', 'ifood-theme' ),
  207.      'id'            => 'front-widget-with-sidebar',
  208.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  209.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  210.      'after_widget'  => '</section>',
  211.      'before_title'  => '<h2 class="display widget-title">',
  212.      'after_title'   => '</h2>',
  213.    ) );
  214.    register_sidebar( array(
  215.      'name'          => esc_html__( 'front-page-new-recipes-sidebar-ad', 'ifood-theme' ),
  216.      'id'            => 'front-page-add-side-widget',
  217.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  218.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  219.      'after_widget'  => '</section>',
  220.      'before_title'  => '<h3 class="display widget-title">',
  221.      'after_title'   => '</h3>',
  222.    ) );
  223.     register_sidebar( array(
  224.       'name'          => esc_html__( 'front-page-content-feature-1', 'ifood-theme' ),
  225.       'id'            => 'front-widget-content-features',
  226.       'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  227.       'before_widget' => '<section id="%1$s" class="widget %2$s">',
  228.       'after_widget'  => '</section>',
  229.       'before_title'  => '<h2 class="display widget-title">',
  230.       'after_title'   => '</h2>',
  231.     ) );
  232.    register_sidebar( array(
  233.      'name'          => esc_html__( 'front-page-content-feature-2', 'ifood-theme' ),
  234.      'id'            => 'front-widget-vertical-1',
  235.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  236.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  237.      'after_widget'  => '</section>',
  238.      'before_title'  => '<h2 class="display widget-title">',
  239.      'after_title'   => '</h2>',
  240.    ) );
  241.    register_sidebar( array(
  242.      'name'          => esc_html__( 'front-page-content-feature-3', 'ifood-theme' ),
  243.      'id'            => 'front-widget-vertical-2',
  244.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  245.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  246.      'after_widget'  => '</section>',
  247.      'before_title'  => '<h2 class="display widget-title">',
  248.      'after_title'   => '</h2>',
  249.    ) );
  250.    register_sidebar( array(
  251.      'name'          => esc_html__( 'front-page-content-feature-4', 'ifood-theme' ),
  252.      'id'            => 'front-widget-vertical-3',
  253.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  254.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  255.      'after_widget'  => '</section>',
  256.      'before_title'  => '<h2 class="display widget-title">',
  257.      'after_title'   => '</h2>',
  258.    ) );
  259.    register_sidebar( array(
  260.      'name'          => esc_html__( 'front-page-content-feature-5', 'ifood-theme' ),
  261.      'id'            => 'front-widget-vertical-4',
  262.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  263.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  264.      'after_widget'  => '</section>',
  265.      'before_title'  => '<h2 class="display widget-title">',
  266.      'after_title'   => '</h2>',
  267.    ) );
  268.    register_sidebar( array(
  269.      'name'          => esc_html__( 'front-page-ad-middle', 'ifood-theme' ),
  270.      'id'            => 'front-page-add-middle-widget',
  271.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  272.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  273.      'after_widget'  => '</section>',
  274.      'before_title'  => '<h3 class="display widget-title">',
  275.      'after_title'   => '</h3>',
  276.    ) );
  277.    register_sidebar( array(
  278.      'name'          => esc_html__( 'front-page-ad-bottom', 'ifood-theme' ),
  279.      'id'            => 'front-page-add-bottom-widget',
  280.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  281.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  282.      'after_widget'  => '</section>',
  283.      'before_title'  => '<h3 class="display widget-title">',
  284.      'after_title'   => '</h3>',
  285.    ) );
  286.    register_sidebar( array(
  287.      'name'          => esc_html__( 'front-page-about', 'ifood-theme' ),
  288.      'id'            => 'front-widget-about',
  289.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  290.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  291.      'after_widget'  => '</section>',
  292.      'before_title'  => '<h2 class="display widget-title">',
  293.      'after_title'   => '</h2>',
  294.    ) );
  295.      register_sidebar( array(
  296.          'name'          => esc_html__( 'sidebar-widget-about', 'ifood-theme' ),
  297.          'id'            => 'sidebar-widget-about',
  298.          'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  299.          'before_widget' => '<section id="%1$s" class="widget %2$s">',
  300.          'after_widget'  => '</section>',
  301.          'before_title'  => '<h3 class="display widget-title">',
  302.          'after_title'   => '</h3>',
  303.      ) );
  304.      register_sidebar( array(
  305.      'name'          => esc_html__( 'all-recipes-1', 'ifood-theme' ),
  306.      'id'            => 'all-recipes-1',
  307.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  308.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  309.      'after_widget'  => '</section>',
  310.      'before_title'  => '<h2 class="widget-title">',
  311.      'after_title'   => '</h2>',
  312.    ) );
  313.      register_sidebar( array(
  314.          'name'          => esc_html__( 'all-recipes-2', 'ifood-theme' ),
  315.          'id'            => 'all-recipes-2',
  316.          'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  317.          'before_widget' => '<section id="%1$s" class="widget %2$s">',
  318.          'after_widget'  => '</section>',
  319.          'before_title'  => '<h2 class="widget-title">',
  320.          'after_title'   => '</h2>',
  321.      ) );
  322.    register_sidebar( array(
  323.      'name'          => esc_html__( 'all-recipes-3', 'ifood-theme' ),
  324.      'id'            => 'all-recipes-3',
  325.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  326.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  327.      'after_widget'  => '</section>',
  328.      'before_title'  => '<h3 class="display widget-title">',
  329.      'after_title'   => '</h3>',
  330.    ) );
  331.    register_sidebar( array(
  332.      'name'          => esc_html__( 'all-recipes-4', 'ifood-theme' ),
  333.      'id'            => 'all-recipes-4',
  334.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  335.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  336.      'after_widget'  => '</section>',
  337.      'before_title'  => '<h3 class="display widget-title">',
  338.      'after_title'   => '</h3>',
  339.    ) );
  340.    register_sidebar( array(
  341.      'name'          => esc_html__( 'all-recipes-5', 'ifood-theme' ),
  342.      'id'            => 'all-recipes-5',
  343.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  344.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  345.      'after_widget'  => '</section>',
  346.      'before_title'  => '<h3 class="display widget-title">',
  347.      'after_title'   => '</h3>',
  348.    ) );
  349.    register_sidebar( array(
  350.      'name'          => esc_html__( 'all-recipes-6', 'ifood-theme' ),
  351.      'id'            => 'all-recipes-6',
  352.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  353.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  354.      'after_widget'  => '</section>',
  355.      'before_title'  => '<h3 class="display widget-title">',
  356.      'after_title'   => '</h3>',
  357.    ) );
  358.    register_sidebar( array(
  359.      'name'          => esc_html__( 'all-recipes-7', 'ifood-theme' ),
  360.      'id'            => 'all-recipes-7',
  361.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  362.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  363.      'after_widget'  => '</section>',
  364.      'before_title'  => '<h3 class="display widget-title">',
  365.      'after_title'   => '</h3>',
  366.    ) );
  367.    register_sidebar( array(
  368.      'name'          => esc_html__( 'all-recipes-ad-1', 'ifood-theme' ),
  369.      'id'            => 'all-recipes-ad-1',
  370.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  371.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  372.      'after_widget'  => '</section>',
  373.      'before_title'  => '<h3 class="display widget-title">',
  374.      'after_title'   => '</h3>',
  375.    ) );
  376.     register_sidebar( array(
  377.       'name'          => esc_html__( 'all-recipes-ad-2', 'ifood-theme' ),
  378.       'id'            => 'all-recipes-ad-2',
  379.       'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  380.       'before_widget' => '<section id="%1$s" class="widget %2$s">',
  381.       'after_widget'  => '</section>',
  382.       'before_title'  => '<h3 class="display widget-title">',
  383.       'after_title'   => '</h3>',
  384.     ) );
  385.    register_sidebar( array(
  386.      'name'          => esc_html__( 'category-horizontal-widget-1', 'ifood-theme' ),
  387.      'id'            => 'category-horizontal-widget-1',
  388.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  389.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  390.      'after_widget'  => '</section>',
  391.      'before_title'  => '<h3 class="display widget-title">',
  392.      'after_title'   => '</h3>',
  393.    ) );
  394.    register_sidebar( array(
  395.      'name'          => esc_html__( 'category-horizontal-widget-2', 'ifood-theme' ),
  396.      'id'            => 'category-horizontal-widget-2',
  397.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  398.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  399.      'after_widget'  => '</section>',
  400.      'before_title'  => '<h3 class="display widget-title">',
  401.      'after_title'   => '</h3>',
  402.    ) );
  403.    register_sidebar( array(
  404.      'name'          => esc_html__( 'category-sidebar', 'ifood-theme' ),
  405.      'id'            => 'category-sidebar',
  406.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  407.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  408.      'after_widget'  => '</section>',
  409.      'before_title'  => '<h3 class="display widget-title">',
  410.      'after_title'   => '</h3>',
  411.    ) );
  412.      register_sidebar( array(
  413.          'name'          => esc_html__( 'page-sidebar', 'ifood-theme' ),
  414.          'id'            => 'page-sidebar',
  415.          'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  416.          'before_widget' => '<section id="%1$s" class="widget %2$s">',
  417.          'after_widget'  => '</section>',
  418.          'before_title'  => '<h3 class="display widget-title">',
  419.          'after_title'   => '</h3>',
  420.      ) );
  421.    register_sidebar( array(
  422.      'name'          => esc_html__( 'post-top-ad', 'ifood-theme' ),
  423.      'id'            => 'post-add-top-widget',
  424.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  425.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  426.      'after_widget'  => '</section>',
  427.      'before_title'  => '<h3 class="display widget-title">',
  428.      'after_title'   => '</h3>',
  429.    ) );
  430.    register_sidebar( array(
  431.      'name'          => esc_html__( 'post-sidebar', 'ifood-theme' ),
  432.      'id'            => 'post-sidebar',
  433.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  434.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  435.      'after_widget'  => '</section>',
  436.      'before_title'  => '<h3 class="display widget-title sidebar-widget-title">',
  437.      'after_title'   => '</h3>',
  438.    ) );
  439.    register_sidebar( array(
  440.      'name'          => esc_html__( 'campaign-sidebar', 'ifood-theme' ),
  441.      'id'            => 'campaign-sidebar',
  442.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  443.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  444.      'after_widget'  => '</section>',
  445.      'before_title'  => '<h3 class="display widget-title">',
  446.      'after_title'   => '</h3>',
  447.    ) );
  448.    register_sidebar( array(
  449.      'name'          => esc_html__( 'before-comments', 'ifood-theme' ),
  450.      'id'            => 'before-comments',
  451.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  452.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  453.      'after_widget'  => '</section>',
  454.      'before_title'  => '<h2 class="widget-title">',
  455.      'after_title'   => '</h2>',
  456.    ) );
  457.      register_sidebar( array(
  458.      'name'          => esc_html__( 'dina-widget', 'ifood-theme' ),
  459.      'id'            => 'dina-widget',
  460.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  461.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  462.      'after_widget'  => '</section>',
  463.      'before_title'  => '<h2 class="widget-title">',
  464.      'after_title'   => '</h2>',
  465.    ) );
  466.      register_sidebar( array(
  467.          'name'          => esc_html__( 'after-post-subscribe', 'ifood-theme' ),
  468.          'id'            => 'after-post',
  469.          'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  470.          'before_widget' => '<section id="%1$s" class="widget %2$s">',
  471.          'after_widget'  => '</section>',
  472.          'before_title'  => '<h2 class="widget-title">',
  473.          'after_title'   => '</h2>',
  474.      ) );
  475.    register_sidebar( array(
  476.      'name'          => esc_html__( 'after-post-content-feature', 'ifood-theme' ),
  477.      'id'            => 'post-featured',
  478.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  479.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  480.      'after_widget'  => '</section>',
  481.      'before_title'  => '<h3 class="display widget-title">',
  482.      'after_title'   => '</h3>',
  483.    ) );
  484.    register_sidebar( array(
  485.      'name'          => esc_html__( 'video-category-featured-video', 'ifood-theme' ),
  486.      'id'            => 'video-page-featured-video-widget',
  487.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  488.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  489.      'after_widget'  => '</section>',
  490.      'before_title'  => '<h3 class="display widget-title">',
  491.      'after_title'   => '</h3>',
  492.    ) );
  493.    register_sidebar( array(
  494.      'name'          => esc_html__( 'video-category-sidebar', 'ifood-theme' ),
  495.      'id'            => 'video-sidebar',
  496.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  497.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  498.      'after_widget'  => '</section>',
  499.      'before_title'  => '<h3 class="display widget-title">',
  500.      'after_title'   => '</h3>',
  501.    ) );
  502.    register_sidebar( array(
  503.      'name'          => esc_html__( 'page-left-sidebar', 'ifood-theme' ),
  504.      'id'            => 'page-left-sidebar',
  505.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  506.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  507.      'after_widget'  => '</section>',
  508.      'before_title'  => '<h2 class="widget-title">',
  509.      'after_title'   => '</h2>',
  510.    ) );
  511.      register_sidebar( array(
  512.          'name'          => esc_html__( 'post-left-sidebar', 'ifood-theme' ),
  513.          'id'            => 'post-left-sidebar',
  514.          'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  515.          'before_widget' => '<section id="%1$s" class="widget %2$s">',
  516.          'after_widget'  => '</section>',
  517.          'before_title'  => '<h3 class="display widget-title">',
  518.          'after_title'   => '</h3>',
  519.      ) );
  520.    register_sidebar( array(
  521.      'name'          => esc_html__( 'page-left-sidebar-mobile', 'ifood-theme' ),
  522.      'id'            => 'after-page',
  523.      'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  524.      'before_widget' => '<section id="%1$s" class="widget %2$s">',
  525.      'after_widget'  => '</section>',
  526.      'before_title'  => '<h2 class="widget-title">',
  527.      'after_title'   => '</h2>',
  528.    ) );
  529.      register_sidebar( array(
  530.             'name'          => esc_html__( 'recipe-index', 'ifood-theme' ),
  531.             'id'            => 'recipe-index',
  532.             'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  533.             'before_widget' => '<section id="%1$s" class="widget %2$s">',
  534.             'after_widget'  => '</section>',
  535.             'before_title'  => '<h2 class="widget-title">',
  536.             'after_title'   => '</h2>',
  537.         ) );
  538.         register_sidebar( array(
  539.              'name'          => esc_html__( 'description-index', 'ifood-theme' ),
  540.              'id'            => 'description-index',
  541.              'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  542.              'before_widget' => '<section id="%1$s" class="widget %2$s">',
  543.              'after_widget'  => '</section>',
  544.              'before_title'  => '<h2 class="widget-title">',
  545.              'after_title'   => '</h2>',
  546.          ) );
  547.          register_sidebar( array(
  548.                 'name'          => esc_html__( 'description-index-ingredients', 'ifood-theme' ),
  549.                 'id'            => 'description-index-ingredients',
  550.                 'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  551.                 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  552.                 'after_widget'  => '</section>',
  553.                 'before_title'  => '<h2 class="widget-title">',
  554.                 'after_title'   => '</h2>',
  555.             ) );
  556.         register_sidebar( array(
  557.        'name'          => esc_html__( 'description-archive', 'ifood-theme' ),
  558.        'id'            => 'description-archive',
  559.        'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  560.        'before_widget' => '<section id="%1$s" class="widget %2$s">',
  561.        'after_widget'  => '</section>',
  562.        'before_title'  => '<h2 class="widget-title">',
  563.        'after_title'   => '</h2>',
  564.      ) );
  565.         register_sidebar( array(
  566.             'name'          => esc_html__( 'a-z-index', 'ifood-theme' ),
  567.             'id'            => 'a-z-index',
  568.             'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  569.             'before_widget' => '<section id="%1$s" class="widget %2$s">',
  570.             'after_widget'  => '</section>',
  571.             'before_title'  => '<h2 class="widget-title">',
  572.             'after_title'   => '</h2>',
  573.         ) );
  574.         register_sidebar( array(
  575.             'name'          => esc_html__( 'categories-index', 'ifood-theme' ),
  576.             'id'            => 'categories-index',
  577.             'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  578.             'before_widget' => '<section id="%1$s" class="widget %2$s">',
  579.             'after_widget'  => '</section>',
  580.             'before_title'  => '<h2 class="widget-title">',
  581.             'after_title'   => '</h2>',
  582.         ) );
  583.         register_sidebar( array(
  584.             'name'          => esc_html__( 'recipe-header-top', 'ifood-theme' ),
  585.             'id'            => 'recipe-header-top',
  586.             'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  587.             'before_widget' => '<section id="%1$s" class="widget %2$s">',
  588.             'after_widget'  => '</section>',
  589.             'before_title'  => '<h2 class="widget-title">',
  590.             'after_title'   => '</h2>',
  591.         ) );
  592.         register_sidebar( array(
  593.             'name'          => esc_html__( 'about-sidebar', 'ifood-theme' ),
  594.             'id'            => 'about-sidebar',
  595.             'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  596.             'before_widget' => '<section id="%1$s" class="widget %2$s">',
  597.             'after_widget'  => '</section>',
  598.             'before_title'  => '<h2 class="widget-title">',
  599.             'after_title'   => '</h2>',
  600.         ) );
  601.         register_sidebar( array(
  602.             'name'          => esc_html__( 'footer-widget', 'ifood-theme' ),
  603.             'id'            => 'footer-widget',
  604.             'description'   => esc_html__( 'Add widgets here.', 'ifood-theme' ),
  605.             'before_widget' => '<section id="%1$s" class="widget %2$s">',
  606.             'after_widget'  => '</section>',
  607.             'before_title'  => '<h2 class="widget-title">',
  608.             'after_title'   => '</h2>',
  609.         ) );
  610.  }
  611.  add_action( 'widgets_init', 'ifood_theme_widgets_init' );
  612.  function theme_scripts() {
  613.    wp_enqueue_script('jquery');
  614.  }
  615.  add_action('wp_enqueue_scripts', 'theme_scripts');
  616.  // include custom jQuery
  617.  if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
  618.  function my_jquery_enqueue() {
  619.     wp_deregister_script('jquery');
  620.     wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://code.jquery.com/jquery-3.5.1.min.js", false, null);
  621.     wp_enqueue_script('jquery');
  622.  }
  623. /**
  624.  * Enqueue scripts and styles.
  625.  */
  626. function ifood_theme_scripts() {
  627.     wp_enqueue_style( 'ifood-theme-style', get_stylesheet_uri() );
  628.  
  629.     wp_enqueue_script( 'ifood-theme-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );
  630.  
  631.     wp_enqueue_script( 'ifood-theme-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
  632.  
  633. wp_enqueue_script( 'ifood-theme-custom-script', get_template_directory_uri() . '/js/custom.js', array(), '20151215', true );
  634.  
  635.     if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  636.         wp_enqueue_script( 'comment-reply' );
  637.     }
  638. }
  639. add_action( 'wp_enqueue_scripts', 'ifood_theme_scripts' );
  640.  
  641. /**
  642.  * Enqueue bootstrap styles and script.
  643.  */
  644. function ifood_bootstrap_scripts() {
  645.  
  646.   wp_enqueue_style( 'bootstrap-theme-style', get_template_directory_uri() . '/bootstrap-4.0.0-alpha.6/scss/bootstrap.min.css' );
  647.   wp_enqueue_style( 'bootstrap-reboot-style', get_template_directory_uri() . '/bootstrap-4.0.0-alpha.6/scss/bootstrap-reboot.min.css' );
  648.   wp_enqueue_style( 'bootstrap-grid-style', get_template_directory_uri() . '/bootstrap-4.0.0-alpha.6/scss/bootstrap-grid.min.css' );
  649.   wp_enqueue_script( 'bootstrap-tether', 'https://npmcdn.com/tether@1.2.4/dist/js/tether.min.js' );
  650.   wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() . '/bootstrap-4.6.0/js/bootstrap.bundle.min.js' );
  651.  
  652. }
  653. add_action( 'wp_enqueue_scripts', 'ifood_bootstrap_scripts' );
  654. /**
  655.  * Enqueue overwrite bootstrap styles and script.
  656.  */
  657. function ifood_bootstrap_overwrite_scripts() {
  658.  
  659.   wp_enqueue_style( 'bootstrap-overwrite-style', get_template_directory_uri() . '/style-overwrite.css' );
  660.  
  661. }
  662. add_action( 'wp_enqueue_scripts', 'ifood_bootstrap_overwrite_scripts' );
  663.  
  664. /**
  665.  * Register a custom CSS file and enqueue it
  666.  */
  667. function ifood_custom_print_css() {
  668.     wp_enqueue_style( 'print-css', get_template_directory_uri() . '/print.css' );
  669. }
  670. add_action( 'wp_enqueue_scripts', 'ifood_custom_print_css' );
  671.  
  672. /**
  673.  * Implement the Custom Header feature.
  674.  */
  675. require get_template_directory() . '/inc/custom-header.php';
  676.  
  677. /**
  678.  * Custom template tags for this theme.
  679.  */
  680. require get_template_directory() . '/inc/template-tags.php';
  681.  
  682. /**
  683.  * Functions which enhance the theme by hooking into WordPress.
  684.  */
  685. require get_template_directory() . '/inc/template-functions.php';
  686.  
  687. /**
  688.  * Customizer additions.
  689.  */
  690. require get_template_directory() . '/inc/customizer.php';
  691.  
  692.  
  693. // Register Custom Navigation Walker
  694.  
  695. require get_template_directory() . '/inc/nav-walker.php';
  696.  
  697. /**
  698.  * Load Jetpack compatibility file.
  699.  */
  700. if ( defined( 'JETPACK__VERSION' ) ) {
  701.     require get_template_directory() . '/inc/jetpack.php';
  702. }
  703.  
  704. // /**
  705. //  * Load font Awesome Icons.
  706. //  */
  707. // add_action( 'wp_enqueue_scripts', 'enqueue_load_fa' );
  708. // function enqueue_load_fa() {
  709. //     wp_enqueue_style( 'load-fa', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' );
  710. // }
  711.  
  712. /**
  713.  * Add post formats.
  714.  */
  715. function add_post_formats() {
  716.     add_theme_support( 'post-formats', array( 'gallery', 'quote', 'video', 'aside', 'image', 'link' ) );
  717. }
  718.  
  719. add_action( 'after_setup_theme', 'add_post_formats', 20 );
  720.  
  721. /**
  722.  * Add social to navigation.
  723.  */
  724.  
  725. add_filter('wp_nav_menu_items', 'add_social_responsive', 10, 2);
  726.  
  727.  function add_social_responsive($items, $args) {
  728.           if( $args->theme_location == 'responsive' )
  729.           $items .= '<li class="social-items d-flex justify-content-center nav-menu-social-items">' .
  730.           '<a href="https://www.pinterest.ca/ifoodreal/" target="_blank" aria-label="pinterest" rel="noreferrer external"><div class="circle-social"><i class="fa fa-pinterest-p" aria-hidden="true"></i></div></a>
  731.          <a href="https://www.instagram.com/ifoodreal/" target="_blank" aria-label="instagram" rel="noreferrer external"><div class="circle-social"><i class="fa fa-instagram" aria-hidden="true"></i></div></a>
  732.          <a href="https://www.youtube.com/user/iFOODreal" target="_blank" aria-label="youtube" rel="noreferrer external"><div class="circle-social"><i class="fa fa-youtube" aria-hidden="true"></i></div></a>
  733.           <a href="https://www.facebook.com/iFOODreal/" target="_blank" aria-label="facebook" rel="noreferrer external"><div class="circle-social"><i class="fa fa-facebook" aria-hidden="true"></i></div></a>' . '</li>';
  734.      return $items;
  735. }
  736.  
  737.  
  738. /**
  739.  * remove trackbacks.
  740.  */
  741.  
  742. function disable_self_trackback( &$links ) {
  743.   foreach ( $links as $l => $link )
  744.         if ( 0 === strpos( $link, get_option( 'home' ) ) )
  745.             unset($links[$l]);
  746. }
  747.  
  748. add_action( 'pre_ping', 'disable_self_trackback' );
  749.  
  750.  
  751.  
  752. // postratings
  753. add_filter( 'wp_postratings_schema_itemtype', 'wp_postratings_schema_itemtype' );
  754. function wp_postratings_schema_itemtype( $itemtype ) {
  755.     return 'itemscope itemtype="http://schema.org/Recipe"';
  756. }
  757. function custom_rating_image_extension() {
  758. return 'png';
  759. }
  760. add_filter( 'wp_postratings_image_extension', 'custom_rating_image_extension' );
  761.  
  762.  
  763. // remove url field from comments
  764.  
  765. add_filter('comment_form_default_fields', 'unset_url_field');
  766. function unset_url_field($fields){
  767.     if(isset($fields['url']))
  768.        unset($fields['url']);
  769.        return $fields;
  770. }
  771.  
  772.  
  773. // numeric posts navigation
  774.  
  775. function numeric_posts_nav() {
  776.  
  777.     if( is_singular() )
  778.         return;
  779.  
  780.     global $wp_query;
  781.  
  782.     /** Stop execution if there's only 1 page */
  783.     if( $wp_query->max_num_pages <= 1 )
  784.         return;
  785.  
  786.     $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
  787.     $max   = intval( $wp_query->max_num_pages );
  788.  
  789.     /** Add current page to the array */
  790.     if ( $paged >= 1 )
  791.         $links[] = $paged;
  792.  
  793.     /** Add the pages around the current page to the array */
  794.     if ( $paged >= 3 ) {
  795.         $links[] = $paged - 1;
  796.         $links[] = $paged - 2;
  797.     }
  798.  
  799.     if ( ( $paged + 2 ) <= $max ) {
  800.         $links[] = $paged + 2;
  801.         $links[] = $paged + 1;
  802.     }
  803.  
  804.     echo '<div class="pagination-navigation col-md-12"><ul class="d-flex justify-content-center">' . "\n";
  805.  
  806.     /** Previous Post Link */
  807.     if ( get_previous_posts_link() )
  808.         printf( '<li>%s</li>' . "\n", get_previous_posts_link() );
  809.  
  810.     /** Link to first page, plus ellipses if necessary */
  811.     if ( ! in_array( 1, $links ) ) {
  812.         $class = 1 == $paged ? ' class="active"' : '';
  813.  
  814.         printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
  815.  
  816.         if ( ! in_array( 2, $links ) )
  817.             echo '<li>…</li>';
  818.     }
  819.  
  820.     /** Link to current page, plus 2 pages in either direction if necessary */
  821.     sort( $links );
  822.     foreach ( (array) $links as $link ) {
  823.         $class = $paged == $link ? ' class="active"' : '';
  824.         printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
  825.     }
  826.  
  827.     /** Link to last page, plus ellipses if necessary */
  828.     if ( ! in_array( $max, $links ) ) {
  829.         if ( ! in_array( $max - 1, $links ) )
  830.             echo '<li>…</li>' . "\n";
  831.  
  832.         $class = $paged == $max ? ' class="active"' : '';
  833.         printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
  834.     }
  835.  
  836.     /** Next Post Link */
  837.     if ( get_next_posts_link() )
  838.         printf( '<li>%s</li>' . "\n", get_next_posts_link() );
  839.  
  840.     echo '</ul></div>' . "\n";
  841.  
  842. }
  843.  
  844.  
  845. //add custom loading.gif icon
  846. add_filter( 'llc_loader_element_content', function () {
  847.     // Use any html element.
  848.     return '<p class="custom-loader"><img src="'.get_template_directory_uri().'/images/loading.gif" alt="loading-icon" height="32" width="32"></p>';
  849. });
  850.  
  851. //Exclude pages from WordPress Search
  852. if (!is_admin()) {
  853. function wpb_search_filter($query) {
  854. if ($query->is_search) {
  855. $query->set('post_type', 'post');
  856. }
  857. return $query;
  858. }
  859. add_filter('pre_get_posts','wpb_search_filter');
  860. }
  861.  
  862.  
  863. //Get the first image from the post
  864. function get_first_image_url() {
  865.   global $post, $posts;
  866.  
  867.   $first_img = '';
  868.   ob_start();
  869.   ob_end_clean();
  870.   $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  871.   $first_img = $matches[1][0];
  872.  
  873.   // Defines a default image here
  874.   if(empty($first_img)){
  875.     $first_img = "/images/default.jpg";
  876.   }
  877.   return $first_img;
  878. }
  879.  
  880. // Social sharing shortcode was here
  881.  
  882.  
  883. /**
  884.  * Disable pinning of all featured images.
  885.  */
  886. add_filter( 'post_thumbnail_html', function( $html ){
  887. // Something already has 'data-pin-nopin', so we don't need to modify.
  888. if ( false !== stripos( $html, 'data-pin-nopin' ) ) {
  889. return $html;
  890. }
  891. // Add 'data-pin-nopin' to the <img> HTML tag.
  892. $html = str_replace( '<img ', '<img data-pin-nopin="true" ', $html );
  893. return $html;
  894. });
  895.  
  896.  
  897. function my_searchwp_live_search_posts_per_page() {
  898.     return 20; // return 20 results
  899. }
  900. add_filter( 'searchwp_live_search_posts_per_page', 'my_searchwp_live_search_posts_per_page' );
  901.  
  902. function __search_by_title_only( $search, &$wp_query )
  903. {
  904.     global $wpdb;
  905.     if ( empty( $search ) )
  906.         return $search; // skip processing – no search term in query
  907.     $q = $wp_query->query_vars;
  908.     $n = ! empty( $q['exact'] ) ? '' : '%';
  909.     $search =
  910.     $searchand = '';
  911.     foreach ( (array) $q['search_terms'] as $term ) {
  912.         $term = esc_sql( like_escape( $term ) );
  913.         $search .= "{$searchand}($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";
  914.         $searchand = ' AND ';
  915.     }
  916.     if ( ! empty( $search ) ) {
  917.         $search = " AND ({$search}) ";
  918.         if ( ! is_user_logged_in() )
  919.             $search .= " AND ($wpdb->posts.post_password = '') ";
  920.     }
  921. return $search; } add_filter( 'posts_search', '__search_by_title_only', 500, 2 );
  922.  
  923. function widget_text_exec_php( $widget_text ) {
  924.     if( strpos( $widget_text, '<' . '?' ) !== false ) {
  925.         ob_start();
  926.         eval( '?>' . $widget_text );
  927.         $widget_text = ob_get_contents();
  928.         ob_end_clean();
  929.     }
  930.     return $widget_text;
  931. }
  932. add_filter( 'widget_text', 'widget_text_exec_php', 99 );
  933.  
  934. include('ratings-post-top.php');
  935.  
  936. add_filter('body_class','add_category_to_single');
  937.   function add_category_to_single($classes) {
  938.     if (is_single() ) {
  939.       global $post;
  940.       foreach((get_the_category($post->ID)) as $category) {
  941.         // add category slug to the $classes array
  942.         $classes[] = $category->category_nicename;
  943.       }
  944.     }
  945.     // return the $classes array
  946.     return $classes;
  947.   }
  948.  
  949. // replace wordpress logo in login panel
  950.     function my_login_logo() { ?>
  951.     <style type="text/css">
  952.         #login h1 a, .login h1 a {
  953.             background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/images/ifoodreal-logo.png);
  954.                         height: 62px !important;
  955.         width: 80% !important;
  956.         background-size: 90% !important;
  957.         line-height: inherit !important;
  958.                         margin: 0 auto 0 !important;
  959.         }
  960.     </style>
  961. <?php }
  962. add_action( 'login_enqueue_scripts', 'my_login_logo' );
  963.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement