Skip to content

Instantly share code, notes, and snippets.

<?php
/*
Plugin Name: WordPress Simple Google Analytics Plugin
Description: Lägger till Google Analytics-kod i <head> eller <footer> genom WordPress-hook
* Version: 1.0
* Author: D. Andersson
* Author URI: https://dandersson.nu
*/
defined( 'ABSPATH' ) or exit;
@deeman
deeman / functions.php
Created May 6, 2020 17:58
Manually Add Google Analytics Code to WordPress in functions.php
<?php
add_action('wp_footer', 'add_googleanalytics');
function add_googleanalytics() { ?>
// Paste your Google Analytics code here
<?php }
?>
@deeman
deeman / functions.php
Created December 19, 2019 12:23
Add Featured Image in WordPress RSS Feed
function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '<div>' . get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'margin-bottom: 15px;' ) ) . '</div>' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');
@deeman
deeman / functions.php
Created December 5, 2019 12:17
NoIndex WooCommerce 'Order by' archives - via PHP
// Woocommerce SEO — Noindex 'Order by' archives
// Prevent indexing "Order by"
add_action( 'wp_head', 'woo_prevent_indexing_orderby' );
if(!function_exists('woo_prevent_indexing_orderby')){
function woo_prevent_indexing_orderby () {
if (isset($_GET['orderby'])){
echo '<meta name="robots" content="noindex, nofollow">';
}
}
@deeman
deeman / robots.txt
Last active February 4, 2020 10:29
Custom WordpPress/WooCommerce Robots.txt
User-agent: *
Disallow: /wp-admin/
Disallow: /?s=
Disallow: /search/
Allow: /admin/admin-ajax.php
Disallow: /cgi-bin/
Disallow: /wp-content/cache/
Disallow: /trackback/
Disallow: */trackback/
@deeman
deeman / functions.php
Created November 27, 2019 10:09
Genesis Framework: Customize Post Navigations
//CUSTOM POST NAVIGATIONS
//* Customize the next page link
add_filter ( 'genesis_next_link_text' , 'sp_next_page_link' );
function sp_next_page_link ( $text ) {
return '&#x000BB;';
}
//* Customize the previous page link
add_filter ( 'genesis_prev_link_text' , 'sp_previous_page_link' );
function sp_previous_page_link ( $text ) {
return '&#x000AB;';
@deeman
deeman / functions.php
Created October 5, 2019 13:41
Genesis Framework: Modify the Comments Submit Button Text
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Customize the submit button text in comments
add_filter( 'comment_form_defaults', 'sp_comment_submit_button' );
function sp_comment_submit_button( $defaults ) {
$defaults['label_submit'] = __( 'Submit', 'custom' );
return $defaults;
}
@deeman
deeman / functions.php
Created October 5, 2019 13:40
Genesis Framework: Modify the Comments Link Text
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Modify the comment link text in comments
add_filter( 'genesis_post_info', 'sp_post_info_filter' );
function sp_post_info_filter( $post_info ) {
return '[post_comments zero="Leave a Comment" one="1 Comment" more="% Comments"]';
}
@deeman
deeman / functions.php
Created September 29, 2019 11:34
WordPress: How to change default excerpt length
function new_excerpt_length($length) {
return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');
@deeman
deeman / function-popular-post-template.php
Last active September 29, 2019 11:30
WordPress: Show most popular posts without a plugin
//Add this anywhere in your template where you wish to display the posts.
<?php
$popular_posts_args = array(
'posts_per_page' => 3,
'meta_key' => 'my_post_viewed',
'orderby' => 'meta_value_num',
'order'=> 'DESC'
);