Created
May 15, 2018 05:21
-
-
Save DmitriyRF/c560292e17b31e87800153b60cc5e6fc to your computer and use it in GitHub Desktop.
Adding separate page to WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_action( 'wp_enqueue_scripts', 'add_assets_to_enqueue', 20 ); | |
| function add_assets_to_enqueue() { | |
| if ( is_page_template('page-tempalate_name.php') ) { | |
| global $wp_scripts; | |
| global $wp_styles; | |
| $styles_to_keep = array("wp-admin", "admin-bar", "dashicons", "open-sans");//wordpress default styles | |
| // loop over all of the registered scripts | |
| foreach ($wp_styles->registered as $handle_st => $data) | |
| { | |
| if ( in_array($handle_st, $styles_to_keep) ) continue; | |
| // remove it | |
| wp_deregister_style($handle_st); | |
| wp_dequeue_style($handle_st); | |
| } | |
| foreach ($wp_scripts->registered as $handle_sc => $data) | |
| { | |
| // remove it | |
| // wp_deregister_script($handle_sc); | |
| wp_dequeue_script($handle_sc); | |
| } | |
| wp_enqueue_style( 'bootstrap', https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"', array(), null, 'all' ); | |
| wp_enqueue_style( 'google-fonts', 'https://fonts.googleapis.com/css?family=Roboto:300,400', array(), null, 'all' ); | |
| wp_enqueue_style( 'gcr-font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css', array(), null, 'all' ); | |
| //returns the URL to the root theme | |
| wp_enqueue_style( 'theme-stylesheet', get_template_directory_uri() .'/stylesheet-lp.css', array('bootstrap'), null, 'all' ); | |
| // OR | |
| //eturn the URL to the current child theme | |
| wp_enqueue_style( 'theme-stylesheet', get_stylesheet_directory_uri() .'/stylesheet-lp.css', array('bootstrap'), null, 'all' ); | |
| //wp_enqueue_script( 'jquery'); | |
| wp_enqueue_script( 'jquery-3.3.1', 'https://code.jquery.com/jquery-3.3.1.slim.min.js', array(), false, false ); | |
| wp_enqueue_script( 'popper-1.14.0', 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js', array('jquery-3.3.1'), false, false ); | |
| wp_enqueue_script( 'bootstrap-4.1.0', 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js', array('popper-1.14.0'), false, false ); | |
| //returns the URL to the root theme | |
| wp_enqueue_script( 'page-tempalte-script', get_template_directory_uri() . '/script-lp.js', array('jquery'), false, false ); | |
| //eturn the URL to the current child theme | |
| wp_enqueue_script( 'page-tempalte-script', get_stylesheet_directory_uri() . '/script-lp.js', array('jquery'), false, false ); | |
| wp_localize_script( 'page-tempalte-script', "ajax_object", array( | |
| 'ajax_url' => admin_url( 'admin-ajax.php') | |
| )); | |
| } | |
| } | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Template Name: Full Width Page | |
| * Template Post Type: post, page, event | |
| * | |
| * @package WordPress | |
| * @subpackage Twenty_Fourteen | |
| * @since Twenty Fourteen 1.0 | |
| */ | |
| ?> | |
| <body class="page page-id-{number} page-template page-template-full-width-page-php"> | |
| <?php | |
| /* | |
| Page Template | |
| page-{slug}.php | |
| page-{id}.php | |
| page.php | |
| singular.php | |
| index.php | |
| */ | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment