Personal Favorites – Functions.php / Enque / Header / Footer


how to write and test a function

https://premium.wpmudev.org/blog/how-to-write-and-activate-a-function-in-wordpress/
https://www.youtube.com/watch?v=c56d84Eek5M
https://premium.wpmudev.org/blog/functions-file/ https://premium.wpmudev.org/academy/ FIX ACF https://www.wpbeginner.com/wp-tutorials/how-to-fix-custom-fields-not-showing-in-wordpress/
https://premium.wpmudev.org/blog/wordpress-hooks/

pieces

MORE FUNCTIONS HACKS TO CHECK OUT::
https://perishablepress.com/stupid-wordpress-tricks/

https://www.smashingmagazine.com/2009/08/10-useful-wordpress-hook-hacks/ this one is really good!!
https://www.collectiveray.com/wp/wordpress-tips-tricks-hacks
https://www.collectiveray.com/wp/wordpress-tips-tricks-hacks
http://tutorial.xfinitysoft.com/tutorials/how-to-do-ab-split-testing-in-wordpress-using-google-analytics/
prism – for code
https://crambler.com/how-to-implement-prism-js-syntax-highlighting-into-your-wordpress-site/



adding last updated to the page

This will get an area on page for last time it was updated – can be styled using – .last-modified –
https://pagely.com/blog/display-post-last-updated-wordpress/
[code language=”css”] function display_last_updated_date( $content ) { $original_time = get_the_time(‘U’); $modified_time = get_the_modified_time(‘U’); if ($modified_time >= $original_time + 86400) { $updated_time = get_the_modified_time(‘h:i a’); $updated_day = get_the_modified_time(‘F jS, Y’); $modified_content .= ‘<p class="last-modified">This post was last updated on ‘. $updated_day . ‘ at ‘. $updated_time .'</p>’; } $modified_content .= $content; return $modified_content; } add_filter( ‘the_content’, ‘display_last_updated_date’ ); /* https://www.smashingmagazine.com/2009/08/10-useful-wordpress-hook-hacks/ */ /* //////////////////////////////// /////////// enque explained /////////////////////////////////*/ /* https://code.tutsplus.com/tutorials/loading-css-into-wordpress-the-right-way–cms-20402 */ /* wp_enqueue_style( $handle, $src, $deps, $ver, $media ); You can include these parameters: $handle is simply the name of the stylesheet. $src is where it is located. The rest of the parameters are optional. $deps refers to whether or not this stylesheet is dependent on another stylesheet. If this is set, this stylesheet will not be loaded unless its dependent stylesheet is loaded first. $ver sets the version number. $media can specify which type of media to load this stylesheet in, such as ‘all’, ‘screen’, ‘print’ or ‘handheld.’ – ‘all’ is default So if you wanted to load a stylesheet named “slider.css” in a folder named “CSS” in you theme’s root directory, you would use: wp_enqueue_style( ‘slider’, get_template_directory_uri() . ‘/css/slider.css’,false,’1.1′,’all’); +++++++++++++++++++++++++ wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer); You can include these parameters: $handle is the name for the script. $src defines where the script is located. $deps is an array that can handle any script that your new script depends on, such as jQuery. $ver lets you list a version number. $in_footer is a boolean parameter (true/false) that allows you to place your scripts in the footer of your HTML document rather then in the header, so that it does not delay the loading of the DOM tree. Your enqueue function may look like this: null, // example of no version number… // …and no CSS media type array(), // when there is no array wp_enqueue_script( ‘script’, get_template_directory_uri() . ‘/js/script.js’, array ( ‘jquery’ ), 1.1, true); */ /* //////////////////////////////// /////////// enque with hooks – both a style and script /////////////////////////////////*/ /* function wpdocs_theme_name_scripts() { wp_enqueue_style( ‘slider’, get_template_directory_uri() . ‘/css/slider.css’,false,’1.1′,’all’); wp_enqueue_script( ‘script’, get_template_directory_uri() . ‘/js/script.js’, array ( ‘jquery’ ), 1.1, true); } add_action( ‘wp_enqueue_scripts’, ‘wpdocs_theme_name_scripts’ ); */ /* long explanation version of how hooks enque works function wpdocs_theme_name_scripts() { wp_enqueue_style( ‘prism-style’, // handle name get_stylesheet_uri() . ‘/js/example.js’, // the URL of the stylesheet array(), // no dependent styles… array( ‘bootstrap-main’ ), // when bootstrap-main is the dependent… ‘1.0.0’, null, // example of no version number… ‘screen’, // CSS media type is screen… // no CSS media type… ); wp_enqueue_script( ‘prism-script’, get_stylesheet_uri() . ‘/js/example.js’, array(), ‘1.0.0’, true ); } add_action( ‘wp_enqueue_scripts’, ‘wpdocs_theme_name_scripts’ ); */ /* wp_enqueue_scripts for loading scripts and styles in the front-end of our website, admin_enqueue_scripts for loading scripts and styles in the pages of our administration panel, login_enqueue_scripts for loading scripts and styles in the WordPress login page. Here are the examples for these three actions: // load css into the website’s front-end function mytheme_enqueue_style() { wp_enqueue_style( ‘mytheme-style’, get_stylesheet_uri() ); } add_action( ‘wp_enqueue_scripts’, ‘mytheme_enqueue_style’ ); // load css into the admin pages function mytheme_enqueue_options_style() { wp_enqueue_style( ‘mytheme-options-style’, get_template_directory_uri() . ‘/css/admin.css’ ); } add_action( ‘admin_enqueue_scripts’, ‘mytheme_enqueue_options_style’ ); // load css into the login page function mytheme_enqueue_login_style() { wp_enqueue_style( ‘mytheme-options-style’, get_template_directory_uri() . ‘/css/login.css’ ); } add_action( ‘login_enqueue_scripts’, ‘mytheme_enqueue_login_style’ ); */ /* //////////////////////////////// /////////// Regular Enque /////////////////////////////////*/ function twentysixteen_scripts() { // enqueue style wp_enqueue_style(‘twentysixteen-style’, get_stylesheet_uri()); // enqueue script wp_enqueue_script(‘twentysixteen-script’, get_template_directory_uri() .’/js/functions.js’, array(‘jquery’), ‘20150825’, true); } add_action(‘wp_enqueue_scripts’, ‘twentysixteen_scripts’); /* //////////////////////////////// /////////// Enque parent styles in child theme /////////////////////////////////*/ // enqueue styles for child theme // @ https://digwp.com/2016/01/include-styles-child-theme/ function example_enqueue_styles() { // enqueue parent styles wp_enqueue_style(‘parent-theme’, get_template_directory_uri() .’/style.css’); } add_action(‘wp_enqueue_scripts’, ‘example_enqueue_styles’); /* //////////////////////////////// /////////// Enque to partent directory /////////////////////////////////*/ add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ ); function theme_enqueue_styles() { wp_enqueue_style( ‘parent-style’, get_template_directory_uri() . ‘/style.css’ ); } /* //////////////////////////////// /////////// Enqueue parent and child stylesheets /////////////////////////////////*/ // enqueue styles for child theme // @ https://digwp.com/2016/01/include-styles-child-theme/ function example_enqueue_styles() { // enqueue parent styles wp_enqueue_style(‘parent-theme’, get_template_directory_uri() .’/style.css’); // enqueue child styles wp_enqueue_style(‘child-theme’, get_stylesheet_directory_uri() .’/style.css’, array(‘parent-theme’)); } add_action(‘wp_enqueue_scripts’, ‘example_enqueue_styles’); /* //////////////////////////////// This function checks if the current theme is a child theme. If so, it loads the parent styles and the child styles. If the current theme is not a child theme, only the parent styles are loaded. Notice the handling of the dependencies parameter, $deps, which is set to false if the child theme is not active. /////////////////////////////////*/ // conditional enqueue styles function example_enqueue_styles() { $deps = false; if (is_child_theme()) { $deps = array(‘parent-styles’); // load parent styles if active child theme wp_enqueue_style(‘parent-styles’, trailingslashit(get_template_directory_uri()) .’style.css’, false); } // load active theme stylesheet wp_enqueue_style(‘theme-styles’, get_stylesheet_uri(), $deps); } add_action(‘wp_enqueue_scripts’, ‘example_enqueue_styles’); /* //////////////////////////////// If you are developing themes for distribution, it is considered best practice to first register your stylesheets before enqueueing them. /////////////////////////////////*/ wp_register_style(‘child-theme’, get_stylesheet_directory_uri() .’/style.css’, array(‘parent-theme’)); wp_enqueue_style(‘child-theme’); /* //////////////////////////////// If you need to disable a parent style, you can do this: /////////////////////////////////*/ // disable parent theme styles function example_disable_parent_styles() { wp_dequeue_style(‘parent-theme’); } add_action(‘wp_enqueue_scripts’, ‘example_disable_parent_styles’); null, // example of no version number… // …and no CSS media type /* //////////////////////////////// /////////// adding JQuery to functions /////////////////////////////////*/ /* jQuery(document).ready(function($){ // Code goes here }); */ /* jQuery(function($){ – should also be in the include */ /* EXAMPLE – how to run a script in the fucntions.php file and using jQuery(function($){ */ /* function typed_script_init() { wp_enqueue_script( ‘typedJS’, ‘https://pro.crunchify.com/typed.min.js&#8217;, array(‘jquery’) ); } add_action(‘wp_enqueue_scripts’, ‘typed_script_init’); function typed_init() { echo ‘<script> jQuery(function($){ $(".element").typed({ strings: ["App Shah…", " an Engineer (MS)…","a WordPress Lover…", "a Java Developer…"], typeSpeed:100, backDelay:1000, loop:true }); });</script>’; } add_action(‘wp_footer’, ‘typed_init’); */ /* /////////////// function to sense blog page so you can target it //////////////*/ /*/////////////////////////////////////*/ /*You can use the following in your themes functions.php file:*/ function is_blog () { return ( is_archive() || is_author() || is_category() || is_home() || is_single() || is_tag()) && ‘post’ == get_post_type(); } /* And then put this in the file you are checking: <?php if (is_blog()) { echo ‘You are on a blog page’; } ?> You can use Hooks in your functions.php file to hook the above, to make that appear on every page. */ /* Add a Fixed (Floating) Footer or Header Bar in WordPress in One Line of Code http://www.beliefmedia.com/floating-footer-header */ /*
Add a Fixed (Floating) Footer or Header Bar in WordPress in One Line of Code
style="position: fixed; bottom: 0; set to btm of site style="position: fixed; top: 0; or top of site div.beliefmedia_fixedbar a:visited { color: #ffffff; } div.beliefmedia_fixedbar a:link { color: #ffffff; } div.beliefmedia_fixedbar a:hover { color: #ffffff; } */ /* Add a Fixed (Floating) Footer or Header Bar in WordPress in One Line of Code http://www.beliefmedia.com/floating-footer-header Color examples: rgba(1, 1, 1, 0.8) or #09A3E2 */ /* function beliefmedia_floating_message_footer($lineheight = ’35’, $color = ‘rgba(1, 1, 1, 0.8)’) { echo ‘<div style="position: fixed; z-index: 5; bottom: 0; width: 100%; color: #ffffff; line-height: ‘ . $lineheight . ‘px; text-align: center; padding-bottom: 10px; padding-top: 10px; -webkit-box-shadow: 0px 0px 8px 0px #000000; -moz-box-shadow: 0px 0px 8px 0px #000000; box-shadow: 0px 0px 8px 0px #000000; background-color: ‘ . $color . ‘; color: ‘ . $color . ‘;"><div style="color: white; text-decoration: bold; font-size: 14px;">This is a test of a message that you’ll see when using our code…</div></div>’; } add_action(‘wp_footer’, ‘beliefmedia_floating_message_footer’); */ /* Add a Fixed (Floating) Footer or Header Bar in WordPress in One Line of Code http://www.beliefmedia.com/floating-footer-header Color examples: rgba(1, 1, 1, 0.8) or #09A3E2 */ /*originall was fixed position – kept it there at all times – stickly may be best but have to figure out */ function beliefmedia_floating_message_footer($lineheight = ’35’, $color = ‘rgba(255, 102, 0, 0.96)’) { echo ‘<div class="SuperNavFooter" style="position: relative; z-index: 5; bottom: 0; width: 100%; color: #ffffff; line-height: ‘ . $lineheight . ‘px; text-align: center; padding-bottom: 10px; padding-top: 10px; -webkit-box-shadow: 0px 0px 1px 0px #000000; -moz-box-shadow: 0px 0px 1px 0px #000000; box-shadow: 0px 0px 1px 0px #000000; background-color: ‘ . $color . ‘; color: ‘ . $color . ‘;"><div class="SuperNavLinksWrap" style="color: #0099ff; text-transform: uppercase; text-decoration: none; font-weight: bold; font-size: .9em;"><a href="https://shawneee.com/whoompwomp&quot; target="_blank">whoompwomp</a>&nbsp;|&nbsp;<a href="https://shawneee.com/aesop&quot; target="_blank">aesop</a>&nbsp;|&nbsp<a href="https://shawneee.com/clients&quot; target="_blank">clients</a>&nbsp;|&nbsp;<a href="https://shawneee.com/client_experience&quot; target="_blank">whoompwomp</a>&nbsp;|&nbsp; <a href="https://shawneee.com/eyeball&quot; target="_blank">client experience</a>&nbsp;|&nbsp;<a href="https://shawneee.com/project_manager&quot; target="_blank">project manager</a><br><a href="https://mailgun.com&quot; target="_blank">mailgun.com</a>&nbsp;|&nbsp;<a href="https://www.advancedcustomfields.com&quot; target="_blank">advanced custom fields</a>&nbsp;|&nbsp;<a href="https://elementor.com/&quot; target="_blank">elementor</a>&nbsp;|&nbsp;<a href="https://smartslider3.com/&quot; target="_blank">smart slider 3</a></div></div>’; } add_action(‘wp_footer’, ‘beliefmedia_floating_message_footer’); */ /* http://www.beliefmedia.com/floating-footer-header Post or Page Specific Messages Sometimes it’s important to only offer specific messages on only certain pages and our second function will facilitate this. To keep the function as lightweight as possible, you’ll have to update the message array containing specific post IDs and messages that relate to the particular page where you want a fixed message bar to render */ /* Add a Fixed (Floating) Footer or Header Bar in WordPress in One Line of Code http://www.beliefmedia.com/floating-footer-header */ /* div.beliefmedia_fixedbar a:visited { color: #ffffff; } div.beliefmedia_fixedbar a:link { color: #ffffff; } div.beliefmedia_fixedbar a:hover { color: #ffffff; } */ /* function beliefmedia_floating_message_footer_pages() { global $wp_query; $post_id = $wp_query->post->ID; $messagearray = array( ‘5’ => ‘Message for this page..’, ’20’ => ‘Another message’, ’55’ => ‘… and another message.’ ); if ( (array_key_exists($post_id, $messagearray)) && (!is_front_page()) && (is_single()) ) { echo ‘<div style="position: fixed; z-index: 5; bottom: 0; width: 100%; color: #ffffff; line-height: 35px; text-align: center; padding-bottom: 10px; padding-top: 10px; -webkit-box-shadow: 0px 0px 8px 0px #000000; -moz-box-shadow: 0px 0px 8px 0px #000000; box-shadow: 0px 0px 8px 0px #000000; background-color: rgba(1, 1, 1, 0.8); color: rgba(1, 1, 1, 0.8);"><div class="beliefmedia_fixedbar" style="color: white; text-decoration: bold; font-size: 14px; color:#FFFFFF;">’ . $messagearray["$post_id"] . ‘</div></div>’; } } add_action(‘wp_footer’, ‘beliefmedia_floating_message_footer_pages’); */ /* Page Specific Messages, Otherwise a Default Message If you wanted to return a specific message for certain pages and a default message on others, use the following (it’s the same function as above with an else statement). If required you should use the CSS style code from above. http://www.beliefmedia.com/floating-footer-header */ /* Add a Fixed (Floating) Footer or Header Bar in WordPress in One Line of Code http://www.beliefmedia.com/floating-footer-header */ function beliefmedia_floating_message_footer_page($lineheight = ’35’, $color = ‘rgba(1, 1, 1, 0.8)’) { global $wp_query; $post_id = $wp_query->post->ID; $messagearray = array( ‘5’ => ‘Message for this page..’, ’20’ => ‘Another message’, ’55’ => ‘… and another message.’ ); if ( (is_single()) && (!is_front_page()) ) { $default_message = ‘This is the default message to show on every page’; $message = (array_key_exists($post_id, $messagearray)) ? $messagearray["$post_id"] : $default_message; echo ‘<div style="position: fixed; z-index: 5; bottom: 0; width: 100%; color: #ffffff; line-height: ‘ . $lineheight . ‘px; text-align: center; padding-bottom: 10px; padding-top: 10px; -webkit-box-shadow: 0px 0px 8px 0px #000000; -moz-box-shadow: 0px 0px 8px 0px #000000; box-shadow: 0px 0px 8px 0px #000000; background-color: ‘ . $color . ‘; color: ‘ . $color . ‘;"><div class="beliefmedia_fixedbar" style="color: white; text-decoration: bold; font-size: 14px; color:#FFFFFF;">’ . $message . ‘</div></div>’; } } add_action(‘wp_footer’, ‘beliefmedia_floating_message_footer_page’); /*————————————* ADD A STYLE SHEET FOR THE LOGIN PAGE – SEE OVERVIEW FOR CSS TAG LIST *————————————*/ //Replace style-login.css with the name of your custom CSS file function my_custom_login_stylesheet() { wp_enqueue_style( ‘custom-login’, get_stylesheet_directory_uri() . ‘/style-login.css’ ); } //This loads the function above on the login page add_action( ‘login_enqueue_scripts’, ‘my_custom_login_stylesheet’ ); /*————————————* FORCE NORMAL NON CURLY QUOTES *————————————*/ /* Use normal quotes instead of curly quotes If you have ever shared a code snippet on WordPress, you might have noted that by default, WP turns normal quotes to smart codes, which could break the code snippet you’re about to publish. To disable this feature, insert the following code snippet to your functions.php file – another of those WordPress tips which seems small but is quite essential */ remove_filter(‘the_content’, ‘wptexturize’); /*————————————* A/B TESTING GOOGLE ANALYTICS *————————————*/ /* https://www.crazyegg.com/blog/ab-testing-google-analytics/ https://neilpatel.com/blog/how-to-run-an-ab-test-in-google-analytics/ https://www.collectiveray.com/wp/wordpress-tips-tricks-hacks A/B testing different versions of your page will help you improve the conversion rate. Here’s how to do A/B test on your site using Google Analytics. 1. Make sure you’ve installed Google Analytics on your site using the above tip. 2. In your Google Analytics account, click the behavior tab>> click experiments>> choose your experiment objectives and configure your experiment. Learn more about this step from the official site. 3. Find the page id of your original page, and replace $page_id with the id of your original page to the below code. Then, get the experiment code from Analytics and add it to the below code <?php if (is_page($page_id)) : ?> Add Content Experiment Code Here <?php endif; ?> 4. Save this code to the header file and click next>>start experiment in Google Analytics. */ /*————————————* TRACK FILE DOWNLAODS *————————————*/ /* Track file downloads using Google Analytics Using Google Analytics’ event tracking functionality, you can track file downloads without a plugin. See the below example code for event tracking. <a onclick="_gaq.push([‘_trackEvent’,’Download’,’PDF’,this.href]);" href="https://cdn.collectiveray.com/ebook.pdf&quot; target="_blank">Download ebooks</a> https://www.collectiveray.com/wordpress/wordpress-tips-and-tricks/how-to-track-wordpress-downloads-using-plugins-or-natively.html */ /* Display AdSense ads only to search engines If you look at the total ad clicks you receive on your website, you’ll find that search engines visitors are more likely to click the contextual ads like AdSense than any other visitor. So restricting your ad to display only to the visitors that come from search engine can help you increase the CTR of your ad. To display ads only to search engine visitors, add the following code to your functions.php file. */ /* $ r e f = $_SERVER[‘HTTP_REFERER’]; $ S E = array(‘/search?’, ‘images.google.’, ‘web.info.com’, ‘search.’, ‘del.icio.us/search’, ‘soso.com’, ‘/search/’, ‘.yahoo.’); foreach ($SE as $source) { if (strpos($ref,$source)!==false) { setcookie("sevisitor", 1, time()+3600, "/", ".yourdomain.com"); $sevisitor=true; } } function visits_from_searchengine(){ global $sevisitor; if ($sevisitor==true || $_COOKIE["sevisitor"]==1) { return true; } return false; } /* Make sure you change yourdomain.com to your domain. Then, add the following code snippet to single.php file. <?php if (function_exists(‘visits_from_searchengine’)) { if (visits_from_searchengine()) { ?> YOUR CODE HERE <?php } } ?> Don’t forget to add your AdSense code by replacing YOUR CODE HERE. */ /*————————————* ADS IN POSTS – *————————————*/ /* Wrap ads in post wherever you want In functions.php file, add the below code snippet. In addition, make sure you insert your ad codes inside it. */ function googleadsense($content){ $adsensecode = ‘Your Ad Codes Here’; $pattern = ‘<!-googlead->’; $content = str_replace($pattern, $adsensecode, $content); return $content; } add_filter(‘the_content’, ‘googleadsense’); /* Insert <!-googlead-> in your posts and pages wherever you want to display the ad. */ /*————————————* ADS IN POSTS – *————————————*/ /* Display ads using shortcodes Insert the shortcode, [adsense] anywhere inside the posts and pages content where you want the ads to be displayed. Just add the below-given lines to your functions.php file. */ function showads() { return ‘ ADS CODE HERE ‘; } add_shortcode(‘adsense’, ‘showads’); /*————————————* NS SALES PAGE *————————————*/ /* Redirect to custom page after registration Paste the below lines to the functions to redirect users to a custom page after registration */ function __my_registration_redirect(){ return home_url( ‘/my-page’ ); } add_filter( ‘registration_redirect’, ‘__my_registration_redirect’ ); /*————————————* SHOW NUMBER OF SEARCH RESTULS *————————————*/ /* Display the number of search results found in your WordPress search results page by adding the following line of code to your search.php file Open your search.php file in your theme and add the following code: <h2 class="pagetitle">Search Result for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(”); _e(‘<span class="search-terms">’); echo $key; _e(‘</span>’); _e(‘ &mdash; ‘); echo $count . ‘ ‘; _e(‘articles’); wp_reset_query(); ?></h2> The code above will display something like this: Search Result for twitter — 15 articles You can also highlight the search term by adding .search-terms CSS class to your theme’s stylesheet. Here is a simple CSS to get you started: .search-terms { background-color:yellow; color:blue; } */ /*————————————* EXCLUDE CATEGORIES FROM SEARCH *————————————*/ /* When a user does a search on your site, sometimes you may want not to show search results from a particular category that contains promotional contents, portfolio items, etc. Simply add the following code to functions.php file to exclude specific categories from search. */ function wcs_exclude_category_search( $query ) { if ( is_admin() || ! $query->is_main_query() ) return; if ( $query->is_search ) { $query->set( ‘cat’, ‘-22, -21’ ); } } add_action( ‘pre_get_posts’, ‘wcs_exclude_category_search’, 1 ); /*————————————* EXCLUDE PAGES FROM SEARCH *————————————*/ /* If you want to avoid displaying particular pages as the search results, add the following code snippet to functions.php file. //Exclude pages from WordPress Search if (!is_admin()) { function wpb_search_filter($query) { if ($query->is_search) { $query->set(‘post_type’, ‘post’); } return $query; } add_filter(‘pre_get_posts’,’wpb_search_filter’); */ /*————————————* make gallery default to using medium size images *————————————*/ /* Register shortcode_atts_gallery filter callback */ add_filter( ‘shortcode_atts_gallery’, ‘meks_gallery_atts’, 10, 3 ); /* Change attributes of wp gallery to modify image sizes for your needs */ function meks_gallery_atts( $output, $pairs, $atts ) { /* You can use these sizes: – thumbnail – medium – large – full or, if your theme/plugin generate additional custom sizes you can use them as well */ /* $output[‘size’] = ‘medium’; //i.e. This will change all your gallery images to "medium" size return $output; } */ /*————————————* ADDING FILE K SIZE COLUMN TO MEDIA GRID
How to add File Size admin column in WordPress Media Library
*————————————*/ /*add_filter( ‘manage_media_columns’, ‘sk_media_columns_filesize’ ); */ /** * Filter the Media list table columns to add a File Size column. * * @param array $posts_columns Existing array of columns displayed in the Media list table. * @return array Amended array of columns to be displayed in the Media list table. */ /* function sk_media_columns_filesize( $posts_columns ) { $posts_columns[‘filesize’] = __( ‘File Size’, ‘my-theme-text-domain’ ); return $posts_columns; } add_action( ‘manage_media_custom_column’, ‘sk_media_custom_column_filesize’, 10, 2 ); /** * Display File Size custom column in the Media list table. * * @param string $column_name Name of the custom column. * @param int $post_id Current Attachment ID. */ function sk_media_custom_column_filesize( $column_name, $post_id ) { if ( ‘filesize’ !== $column_name ) { return; } $bytes = filesize( get_attached_file( $post_id ) ); echo size_format( $bytes, 2 ); } add_action( ‘admin_print_styles-upload.php’, ‘sk_filesize_column_filesize’ ); /** * Adjust File Size column on Media Library page in WP admin */ function sk_filesize_column_filesize() { echo ‘<style> .fixed .column-filesize { width: 10%; } </style>’; } */ /*————————————* adding excerpt to pages *————————————*/ add_post_type_support( ‘page’, ‘excerpt’ ); /*————————————* ADD CATEGORIES AND TAGS TO PAGES *————————————*/ function add_cats_and_tags_to_pages_definition() { register_taxonomy_for_object_type(‘post_tag’, ‘page’); register_taxonomy_for_object_type(‘category’, ‘page’); } add_action( ‘init’, ‘add_cats_and_tags_to_pages_definition’ ); /*————————————* ADD CATEGORIES TO IMAGES *————————————*/ /* https://code.tutsplus.com/articles/applying-categories-tags-and-custom-taxonomies-to-media-attachments–wp-32319 */ /* Applying Categories to Attachments The first step is to enable categories for attachments. You do this using the register_taxonomy_for_object_type() function. In your plugin file or theme functions file, add the following: function wptp_add_categories_to_attachments() { register_taxonomy_for_object_type( ‘category’, ‘attachment’ ); } add_action( ‘init’ , ‘wptp_add_categories_to_attachments’ ); Save the file and refresh the Media Editing screen. You’ll see that categories are now available: attachments-and-taxonomies-media-editing-screen-with-categories A column will also appear for categories in the Media Library screen, as you can see: attachments-and-taxonomies-media-library-screen-with-categories Note: I’m working with images here, but this will all work for all types of attachment files. Applying Tags to Attachments If you prefer to work with tags rather than categories (or perhaps both), you use the same function. Add the following to your functions file or plugin file: 1 2 3 4 5 // apply tags to attachments function wptp_add_tags_to_attachments() { register_taxonomy_for_object_type( ‘post_tag’, ‘attachment’ ); } add_action( ‘init’ , ‘wptp_add_tags_to_attachments’ ); As before, this will add tags to the Media Editing screen: attachments-and-taxonomies-media-editing-screen-with-tags It will also add a ‘Tags’ column to the Media Library screen: attachments-and-taxonomies-media-library-screen-with-tags Taking It Further – Creating a Custom Taxonomy for Attachments In some cases you may not want to work with the existing categories or tags when classifying your attachments, in which case you can register a custom taxonomy and apply that to the ‘attachment’ post type. In the example above I added a tag to my image to show where it was taken. Let’s say I want to create a hierarchical taxonomy called ‘Locations’, which I can use to classify and display all of my images. You do this using the register_taxonomy() function. In your plugin file or functions file, add the following: // register new taxonomy which applies to attachments function wptp_add_location_taxonomy() { $labels = array( ‘name’ => ‘Locations’, ‘singular_name’ => ‘Location’, ‘search_items’ => ‘Search Locations’, ‘all_items’ => ‘All Locations’, ‘parent_item’ => ‘Parent Location’, ‘parent_item_colon’ => ‘Parent Location:’, ‘edit_item’ => ‘Edit Location’, ‘update_item’ => ‘Update Location’, ‘add_new_item’ => ‘Add New Location’, ‘new_item_name’ => ‘New Location Name’, ‘menu_name’ => ‘Location’, ); $args = array( ‘labels’ => $labels, ‘hierarchical’ => true, ‘query_var’ => ‘true’, ‘rewrite’ => ‘true’, ‘show_admin_column’ => ‘true’, ); register_taxonomy( ‘location’, ‘attachment’, $args ); } add_action( ‘init’, ‘wptp_add_location_taxonomy’ ); This creates a new, hierarchical taxonomy which can be used with attachments only. If you wanted to apply it to other content types, you would replace the ‘attachment’ parameter in the register_taxonomy() function with an array containing the slugs of all the content types you wanted to include, for example: register_taxonomy( ‘location’, array( ‘attachment’, ‘post’ ), $args ); The Media Editing screen now displays the new taxonomy: */ /*————————————* AUTO UPDATE BIG PARTS *————————————*/ /* Auto update wordpress*/ define( ‘WP_AUTO_UPDATE_CORE’ , true ); /* Auto update all plugins */ define( ‘WP_AUTO_UPDATE_CORE’ , true ); /* Auto update all themes */ add_filter( ‘auto_update_theme’ , ‘__return_true’ ); /*————————————* CONVERT COLORS TO RGBA *————————————*/ /* Colors convert to rgba Give function hex code (e.g. #eeeeee), returns array of RGB values. */ /* Convert hexdec color string to rgb(a) string */ /* function hex2rgba($color, $opacity = false) { $default = ‘rgb(0,0,0)’; //Return default if no color provided if(empty($color)) return $default; //Sanitize $color if "#" is provided if ($color[0] == ‘#’ ) { $color = substr( $color, 1 ); } //Check if color has 6 or 3 characters and get values if (strlen($color) == 6) { $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ); } elseif ( strlen( $color ) == 3 ) { $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ); } else { return $default; } //Convert hexadec to rgb $rgb = array_map(‘hexdec’, $hex); //Check if opacity is set(rgba or rgb) if($opacity){ if(abs($opacity) > 1) $opacity = 1.0; $output = ‘rgba(‘.implode(",",$rgb).’,’.$opacity.’)’; } else { $output = ‘rgb(‘.implode(",",$rgb).’)’; } //Return rgb(a) color string return $output; } */ /* So far so good! Now we are going to show you how this function can be helpful whilst creating dynamic CSS with a simple example below. Usage example: */ /* Here’s a usage example how to use this function for dynamicaly created CSS */ /* $color = ‘#ffa226’; $rgb = hex2rgba($color); $rgba = hex2rgba($color, 0.7); */ /* CSS output */ /* echo ‘ div.example{ background: ‘.$rgb.’; color: ‘.$rgba.’; } ‘; */ /* Here’s a usage example how to use this function for dynamicaly created CSS */ /* $color = ‘#ffa226’; $rgb = hex2rgba($color); $rgba = hex2rgba($color, 0.7); */ /* CSS output */ /* echo ‘ div.example{ background: ‘.$rgb.’; color: ‘.$rgba.’; } ‘; */ /*————————————* UPLOAD / USE ANY FILE TYPE *————————————*/ /* Enable WordPress to Upload Any File Type You Want By default, WordPress only enables you to upload a very limited range of file types, including common media formats such as .png and .jpg. With this code, you’ll be able to force your installation to allow more types: */ function my_myme_types($mime_types){ $mime_types[‘svg’] = ‘image/svg+xml’; return $mime_types; } add_filter(‘upload_mimes’, ‘my_myme_types’, 1, 1); /*————————————* featured image in admin pages *————————————*/ /** * Change Display Size of Featured Image Thumbnail in WordPress Admin Dashboard add_filter( ‘admin_post_thumbnail_size’, function ( $size, $thumbnail_id, $post ) { $sizes = get_intermediate_image_sizes(); $result = array_search( ‘thumbnail’, $sizes ); $size = is_numeric( $result ) ? $sizes[ $result ] : array( 300, 99999 ); // 300 width forever high no cropping return $size; }, 10, 3 ); /*————————————* adding custom size images to wordpress *————————————*/ /*
How to Change Featured Image Sizes in WordPress
There are two different ways of resizing a featured image. To resize it proportionally (i.e. to avoid stretching or compressing the image) use the following code: set_post_thumbnail_size( 50, 50 ); // 50 pixels wide by 50 pixels tall, resize mode you can also choose to resize the image by cropping it with this code: set_post_thumbnail_size( 50, 50, true ); // 50 pixels wide by 50 pixels tall, crop mode This sets the default size of featured images. Adding Additional Image Sizes It’s also possible to add as many additional image sizes as you need by adding an extra line of code for each image size: add_image_size( ‘category-thumb’, 300, 9999 ); // 300 pixels wide (and unlimited height) You can then use this new size in your theme template with the following code: <?php the_post_thumbnail( ‘category-thumb’ ); ?> This feature is handy if you want to display featured images in a number of different ways. For example, you may want to set a thumbnail size for your image galleries and a larger size for your post header. Remember that the images you upload must be at least as big as the dimensions you have set for your featured images. If you upload smaller images, they will be scaled up and will end up looking pixelated and blurry. */ /* more image stuff another way to add – */ /* https://www.elegantthemes.com/blog/tips-tricks/how-to-change-thumbnail-size-in-wordpress-and-why-you-want-to */ /* This enables the function that lets you set new image sizes add_theme_support( ‘post-thumbnails’ ); // These are the new image sizes we cooked up add_image_size( ‘post-image’, 660 ); // Now we register the size so it appears as an option within the editor add_filter( ‘image_size_names_choose’, ‘my-custom-image-sizes’ ); function my-custom-image-sizes( $sizes ) { return array_merge( $sizes, array( ‘post-image’ => __( ‘Post Images’ ), ) ); } */ /*————————————* adding favicons / etc. to header of site *————————————*/ /* adding favicon stuff to header */ add_action(‘wp_head’,’shawneee_favicons’, 20); function shawneee_favicons() { ?> <!– shawneee favicons –> <link rel="apple-touch-icon" sizes="180×180" href="/get_stylesheet_directory_uri()./favicon_package/apple-touch-icon.png"> <link rel="icon" type="image/png" sizes="32×32" href="/get_stylesheet_directory_uri()./favicon_package/favicon-32×32.png"> <link rel="icon" type="image/png" sizes="16×16" href="/get_stylesheet_directory_uri()./favicon_package/favicon-16×16.png"> <link rel="manifest" href="/get_stylesheet_directory_uri()./favicon_package/site.webmanifest"> <link rel="mask-icon" href="/get_stylesheet_directory_uri()./favicon_package/safari-pinned-tab.svg" color="#ff6600"> <link rel="shortcut icon" href="/get_stylesheet_directory_uri()./favicon_package/favicon.ico"> <meta name="msapplication-TileColor" content="#ff6600"> <meta name="msapplication-config" content="/get_stylesheet_directory_uri()./favicon_package/browserconfig.xml"> <meta name="theme-color" content="#ff6600"> <?php } /*————————————* ADD ANALYTICS *————————————*/ /* adding analytics to header */ add_action(‘wp_head’,’shawneee_analytics’, 20); function shawneee_analytics() { ?> <!– Global site tag (gtag.js) – Google Analytics –> <!– shawneee analytics –> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-139688905-1"></script&gt; <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag(‘js’, new Date()); gtag(‘config’, ‘UA-139688905-1’); </script> <?php } /*————————————* Fix footer credit EXTRA THEME – but could rewrite other parts with same code idea *————————————*/ /* footer credit EXTRA THEME */ /* add_action(‘wp_head’,’shawneee_footercredit’, 20); function shawneee_footercredit() { <script> jQuery(function($){ $(‘#footer-info’).html(‘&copy; ‘+(new Date).getFullYear()+’ <a href="https://extrabooster.com">Extra Booster</a>’); }); </script> */ /*————————————* Fix for p and br adding – have to use <br class="clear"> to get brs in – *————————————*/ /* change this: remove_filter(‘the_excerpt’, ‘wpautop’); to this: */ remove_filter(‘the_content’, ‘wpautop’); /*————————————* then have to use <br class="clear"> to get brs in – *————————————*/ /*————————————* ADD CATEGORIES AND TAGS TO PAGES *————————————*/ function add_cats_and_tags_to_pages_definition() { register_taxonomy_for_object_type(‘post_tag’, ‘page’); register_taxonomy_for_object_type(‘category’, ‘page’); } add_action( ‘init’, ‘add_cats_and_tags_to_pages_definition’ ); /*————————————* SET UP NO POST CATEGORY – still have to figure this out – *————————————*/ function wcs_exclude_category_search( $query ) { if ( is_admin() || ! $query->is_main_query() ) return; if ( $query->is_search ) { $query->set( ‘cat’, ‘-22, -21’ ); } } add_action( ‘pre_get_posts’, ‘wcs_exclude_category_search’, 1 ); /*————————————* ENQUEUE CSS FOR ADMIN *————————————*/ // Update CSS within in Admin /* this goes to main theme folder – function load_custom_wp_admin_style() { wp_register_style( ‘custom_wp_admin_css’, get_template_directory_uri() . ‘/admin-style.css’, false, ‘1.0.0’ ); wp_enqueue_style( ‘custom_wp_admin_css’ ); } add_action( ‘admin_enqueue_scripts’, ‘load_custom_wp_admin_style’ ); */ /* to child theme folder */ function admin_style() { wp_enqueue_style(‘admin-style’, get_stylesheet_directory_uri().’/css/admin_style.css’, false, ‘1.0.0’ ); } add_action(‘admin_enqueue_scripts’, ‘admin_style’); /*————————————* Adding Classes to Divs with no class names – ADMIN https://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
Loading Scripts Correctly in the WordPress Admin
*————————————*/ function my_scripts_method() { wp_enqueue_script( ‘custom-script’, get_stylesheet_directory_uri() . ‘/js/admin_custom_script.js’, array( ‘jquery’ ) ); } add_action( ‘admin_enqueue_scripts’, ‘my_scripts_method’ ); /*————————————* Adding Classes to Divs with no class names – FRONT END *————————————*/ /*————————————* Adding Classes to Divs with no class names – ADMIN https://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
Loading Scripts Correctly in the WordPress Admin
*————————————*/ function my_scripts_method() { wp_enqueue_script( ‘custom-script’, get_stylesheet_directory_uri() . ‘/js/admin_custom_script.js’, array( ‘jquery’ ) ); } add_action( ‘admin_enqueue_scripts’, ‘my_scripts_method’ ); /*————————————* Adding Classes to Divs with no class names – FRONT END *————————————*/ /* add classes to divs without FRONT END */ add_action(‘wp_head’,’shawneee_addfrclassyclass’, 20); function shawneee_addfrclassyclass() { ?> <!— add classes to divs without FRONT END –> <script> jQuery(function($){ $(window).bind("load", function() { // runs code after page is loaded // place your code here $(‘div:not([class])’).addClass(function(i) { return ‘ClassyDiv’ + i; }); });// end load code });// jquery for $ </script> <?php } /*————————————* Writing Content from functions into page *————————————*/ /** * Display the theme credit * * @since 1.0.0 * @return void */ function storefront_credit() { ?> <!– this was other header that was tested ?php echo do_shortcode(""); ?–> <div class="InstagramFeed"> <?php echo do_shortcode(‘[instagram-feed]’); ?> </div> <div class="site-info BtmOfSiteInfo"> <strong><?php echo esc_html( apply_filters( ‘storefront_copyright_text’, $content = ‘&copy; ‘ . get_bloginfo( ‘name’ ) . ‘ ‘ . date( ‘Y’ ) ) ); ?> <br>Producers &amp; Distributors of Sustainable Caviar<br> Sausalito, Ca | USA</strong><br><br> <div class="disclaimertxt">This website and its content is the exclusive copyright and intellectual property of California Caviar Company, LLC. All rights reserved under United States and International Copyright Laws. Any redistribution or reproduction of part or all of the contents, including photography, in any media is prohibited. You may not re-write, edit, distribute or commercially exploit any content of this site without the express written consent of California Caviar Company, LLC. Nor may you transmit it or store it in any other website or other form of electronic retrieval system. Your use of this Website infers acceptance of our Terms of Use. Please view our Privacy policy.</div> <?php if ( apply_filters( ‘storefront_credit_link’, true ) ) { ?> <br /> <?php echo ‘<a href="/customer-support/contact-us/" target="_self" title="’ . esc_attr__( ‘Contact Us’) . ‘" rel="author">’ . esc_html__( ‘Contact Us’) . ‘</a>&nbsp;<span role="separator" aria-hidden="true"></span>&nbsp;’; ?> <?php echo ‘<a href="/my-account/" target="_self" title="’ . esc_attr__( ‘My Account’) . ‘" rel="author">’ . esc_html__( ‘My Account’) . ‘</a>&nbsp;<span role="separator" aria-hidden="true"></span>&nbsp;’; ?> <?php echo ‘<a href="/customer-support/ordering-return-policy/" target="_self" title="’ . esc_attr__( ‘Ordering &amp; Return Policy’) . ‘" rel="author">’ . esc_html__( ‘Ordering &amp; Return Policy’) . ‘</a>&nbsp;’; ?> <br> <?php echo ‘<a href="/terms-of-use/" target="_self" title="’ . esc_attr__( ‘Terms Of Use’) . ‘" rel="author">’ . esc_html__( ‘Terms Of Use’) . ‘</a>&nbsp;<span role="separator" aria-hidden="true"></span>&nbsp;’; ?> <?php if ( apply_filters( ‘storefront_privacy_policy_link’, true ) && function_exists( ‘the_privacy_policy_link’ ) ) { the_privacy_policy_link( ”, ” ); } ?> <?php } ?> <br><br> Rue La La and Gilt – specific voucher codes / landing page<br><br> TOCK – time booking – new open table<br><br> VOUCHERS – currently 6 are working<br><br> CHEF PORTAL – CHANGE IN PRICING -LOGIN – HOW TO SET UP<br><br> SHIPPING ISSUES – work out with Russ<br><br> no shipping friday sat sunday <br> hawaii / alaska special pricing<br> Other shipping issues<br> </div><!– .site-info –> <?php } /*————————————* ENQUEUE TO PARENT DIRECTORY *————————————*/ wp_enqueue_style( ‘reset’, get_template_directory_uri() . ‘/css/reset.css’,false,’1.1′,’all’); wp_enqueue_style( ‘rebuild’, get_template_directory_uri() . ‘/css/rebuild.css’,false,’1.1′,’all’); wp_enqueue_style( ‘standard’, get_template_directory_uri() . ‘/css/standard.css’,false,’1.1′,’all’); wp_enqueue_style( ‘aileron’, get_template_directory_uri() . ‘/css/aileron.css’,false,’1.1′,’all’); wp_enqueue_style( ‘isotope’, get_template_directory_uri() . ‘/css/isotope.css’,false,’1.1′,’all’); wp_enqueue_style( ‘modern_scale_typography’, get_template_directory_uri() . ‘/css/modern_scale_typography.css’,false,’1.1′,’all’); /*————————————* ENQUEUE CSS FOR ADMIN *————————————*/ // Update CSS within in Admin – MAIN THEME function admin_style() { wp_enqueue_style(‘admin-style’, get_template_directory_uri().’/css/admin_style.css’); } add_action(‘admin_enqueue_scripts’, ‘admin_style’); /*————————————* USING HOOKS TO TARGET A SPECIFIC ADMIN PAGE *————————————*/ function my_enqueue($hook) { if ( ‘edit.php’ != $hook ) { return; } wp_enqueue_script( ‘my_custom_script’, get_template_directory_uri() . ‘/myscript.js’ ); } add_action( ‘admin_enqueue_scripts’, ‘my_enqueue’ ); /*————————————* CHANGE JQUERY THAT IS USED – ADD NEW *————————————*/ // remove original jquery version and put new version in its place – include custom jQuery function shapeSpace_include_custom_jquery() { wp_deregister_script(‘jquery’); wp_enqueue_script(‘jquery’, ‘https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js&#8217;, array(), null, true); } add_action(‘wp_enqueue_scripts’, ‘shapeSpace_include_custom_jquery’); /*————————————* USE GOOGLE JQUERY INSTEAD OF INSTALLED VERSION – *————————————*/ /* Replace default WordPress jQuery script with Google Library If you are sure that you want to change the core jQuery version, in that case you may add the following code in your active theme’s functions.php file. */ //Making jQuery Google API function modify_jquery() { if (!is_admin()) { wp_deregister_script(‘jquery-core’); wp_register_script(‘jquery-core’, ‘http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js&#8217;, true, ‘1.11.3’); wp_enqueue_script(‘jquery-core’); wp_deregister_script(‘jquery-migrate’); wp_register_script(‘jquery-migrate’, ‘http://cdn.yourdomain.com/wp-includes/js/jquery/jquery-migrate.min.js&#8217;, true, ‘1.2.1’); wp_enqueue_script(‘jquery-migrate’); } } add_action( ‘init’, ‘register_jquery’ ); /*————————————* adding outside js *————————————*/ // add other js files to parent directory – can also so to child with get_stylesheet_directory_uri(). wp_enqueue_script( ‘isotope.pkgd’, get_template_directory_uri() . ‘/js/isotope.pkgd.min.js’, array ( ‘jquery’ ), 1.1, false); wp_enqueue_script( ‘isotope_docs’, get_template_directory_uri() . ‘/js/isotope_docs.min.js’, array ( ‘jquery’ ), 1.1, true); wp_enqueue_script( ‘isotope_initialize’, get_template_directory_uri() . ‘/js/isotope_initialize.js’, array ( ‘jquery’ ), 1.1, true); /*————————————* ENQUEUE OTHER STYLES *————————————*/ /* calling css for fonts */ function add_theme_typekitcodes() { wp_enqueue_style( ‘style’, ‘https://use.typekit.net/acp8xby.css&#8217;, ‘all’);} add_action( ‘wp_enqueue_scripts’, ‘add_theme_typekitcodes’ ); /* fontawesome */ function add_theme_fontawesomecodes() { wp_enqueue_style( ‘style’, ‘https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css&#8217;, ‘all’);} add_action( ‘wp_enqueue_scripts’, ‘add_theme_fontawesomecodes’ ); /* font awesome local from taken storefront theme – in caviar site */ add_action(‘wp_enqueue_scripts’, function(){ wp_enqueue_style( ‘fontawesassetsnav’, get_stylesheet_directory_uri(). ‘/css/fontawesome_assets.css’,false,’2.0′,’all’); }, 777); add_action(‘wp_enqueue_scripts’, function(){ wp_enqueue_style( ‘cacavnav’, get_stylesheet_directory_uri(). ‘/css/californiacaviar_nav.css’,false,’1.1′,’all’); }, 888); add_action(‘wp_enqueue_scripts’, function(){ wp_enqueue_style( ‘cacavmain’, get_stylesheet_directory_uri(). ‘/css/californiacaviar_main.css’,false,’1.1′,’all’); }, 999); // add scripts to head of WordPress // add scripts to head of WordPress /* add_action(‘wp_head’, function(){ ?> Enter tracking code here… <?php }); */ /* */ /* add to header of page */ /*add_action(‘wp_head’, ‘your_function_name’); function your_function_name(){ ?> PASTE HEADER CODE HERE <?php }; */ /* add to footer */ /*add_action(‘wp_footer’, ‘your_function_name’); function your_function_name(){ ?> PASTE FOOTER CODE HERE <?php }; */ /* add only to homepage */ /* add_action(‘wp_head’, ‘your_function_name’); function your_function_name(){ if(is_front_page()) { ?> PASTE HEADER CODE HERE <?php } }; */ /* speciifc posts and pages */ /* swap ID add_action(‘wp_head’, ‘your_function_name’); function your_function_name(){ if(is_single(73790)) { ?> PASTE HEADER CODE HERE <?php } }; */ /*————————————* JQUERY IN FOOTER – *————————————*/ function custom_scripts_method() { wp_register_script(‘customscripts’, get_template_directory_uri() . ‘/js/jquery.min.js’, array(‘jquery’), ‘1.0.0’, true); wp_enqueue_script(‘customscripts’); } add_action(‘wp_enqueue_scripts’, ‘custom_scripts_method’); /* First, you register your script through the wp_register_script() function. It takes 5 parameters $handle – The first parameter that is a unique name of your script. The function is using a handle name as “customscripts”. It is a required field and should be in all lowercase. $src – It is the location of your script. If you are loading it locally, better to use content_url, bloginfo(“template_url”), or get_template_directory_uri(). It is optional. $deps – Specifies an array of dependencies. It will load the jQuery if it is not being loaded already. This is also an optional field. $ver – This is the version of your script. This parameter is not mandatory. $in_footer – If you want to place your script in the footer, you will set it to true. If in the header, then you would make it false. simpler – for new scripts*/ function my_theme_scripts() { wp_enqueue_script( ‘my-great-script’, get_template_directory_uri() . ‘/js/my-great-script.js’, array( ‘jquery’ ), ‘1.0.0’, true ); } add_action( ‘wp_enqueue_scripts’, ‘my_theme_scripts’ ); /*look at – what to do about it jquery already being laoded */ function load_jquery() { // Only use this method when not in wp-admin if (!is_admin()) { // Discover the correct protocol to use $protocol = ‘http:’; if ($_SERVER[‘HTTPS’]==’on’) { $protocol = ‘https:’; } // Settings for the script, change these to your liking // jQuery version you want $jquery_version = ‘2.0.3’; // The url you want it from. Default to Google CDN $jquery_url = $protocol . ‘//ajax.googleapis.com/ajax/libs/jquery/’ . $jquery_version . ‘/jquery.min.js’; // Load in footer, default to footer $footer_load = true; // Deregister the original version of jQuery wp_deregister_script(‘jquery’); // Register the new version wp_register_script(‘jquery’, $jquery_url, false, $jquery_version, $footer_load); // Add it back into the queue wp_enqueue_script(‘jquery’); } } add_action(‘template_redirect’, ‘load_jquery’); add_action(‘wp_enqueue_scripts’, ‘my_scripts_method’); /*————————————* PAGE HEADER STUFF *————————————*/ /* "If this is a single post view, show the post title; if this is a multi-post view, show the blog name and description." */ /* "If this is a single post view, show the post title; if this is a multi-post view, show the blog name and description." */ function gretathemes_meta_description() { global $post; if ( is_singular() ) { $des_post = strip_tags( $post->post_content ); $des_post = strip_shortcodes( $post->post_content ); $des_post = str_replace( array("n", "r", "t"), ‘ ‘, $des_post ); $des_post = mb_substr( $des_post, 0, 300, ‘utf8’ ); echo ‘<meta name="description" content="’ . $des_post . ‘" />’ . "n"; } if ( is_home() ) { echo ‘<meta name="description" content="’ . get_bloginfo( "description" ) . ‘" />’ . "n"; } if ( is_category() ) { $des_cat = strip_tags(category_description()); echo ‘<meta name="description" content="’ . $des_cat . ‘" />’ . "n"; } } add_action( ‘wp_head’, ‘gretathemes_meta_description’); /* "If this is a single post view, show the post title; if this is a multi-post view, show the blog name and description." <meta name="description" content="<?php if ( is_single() ) { single_post_title(”, true); } else { bloginfo(‘name’); echo " – "; bloginfo(‘description’); } ?>" /> <meta name="description" content="<?php bloginfo(‘description’); ?>" /> <title><?php bloginfo(‘name’); ?><?php wp_title(); ?></title> <meta name="description" content="This is the description sentence or short paragraph about the article or post." /> <meta name="resource-type" content="document" /> <meta http-equiv="content-type" content="text/html; charset=US-ASCII" /> <meta http-equiv="content-language" content="en-us" /> <meta name="author" content="Harriet Smith" /> <meta name="contact" content="harrietsmith@harrietsmith.us" /> <meta name="copyright" content="Copyright (c)1997-2004 Harriet Smith. All Rights Reserved." /> <meta name="description" content="Story about my dog giving birth to puppies." /> <meta name="keywords" content="stories, tales, harriet, smith, harriet smith, storytelling, day, life, dog, birth, puppies, happy" /> */ [/code]
Scroll to Top