<?php
/**
* Scottish Review Theme Functions
*/
// Theme Setup
function scottishreview_setup() {
add_theme_support('title-tag');
add_theme_support('post-thumbnails');
add_theme_support('custom-logo', array(
'height' => 100,
'width' => 750,
'flex-height' => true,
'flex-width' => true,
));
add_theme_support('html5', array('search-form', 'gallery', 'caption'));
register_nav_menus(array(
'primary' => 'Primary Navigation',
));
// Featured image sizes
add_image_size('article-grid', 470, 300, true);
add_image_size('article-featured', 940, 500, true);
}
add_action('after_setup_theme', 'scottishreview_setup');
// Enqueue styles and fonts
function scottishreview_scripts() {
wp_enqueue_style(
'google-fonts',
'https://fonts.googleapis.com/css2?family=Crimson+Text:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&family=Roboto:wght@300;400;500;700&display=swap',
array(),
null
);
wp_enqueue_style('scottishreview-style', get_stylesheet_uri(), array(), '2.3');
}
add_action('wp_enqueue_scripts', 'scottishreview_scripts');
// Fix site title and user display name on theme activation
function scottishreview_activation() {
update_option('blogname', 'Scottish Review');
update_option('blogdescription', "Scotland's independent review magazine, est. 1995");
$user = get_user_by('login', 'joyouscow90');
if ($user) {
wp_update_user(array(
'ID' => $user->ID,
'display_name' => 'Scottish Review',
'first_name' => 'Scottish',
'last_name' => 'Review',
));
}
}
add_action('after_switch_theme', 'scottishreview_activation');
// Custom excerpt length
function scottishreview_excerpt_length($length) {
return 30;
}
add_filter('excerpt_length', 'scottishreview_excerpt_length');
// Remove excerpt [...]
function scottishreview_excerpt_more($more) {
return '...';
}
add_filter('excerpt_more', 'scottishreview_excerpt_more');
// Enable REST API for posts
function scottishreview_rest_api() {
add_filter('rest_authentication_errors', function($result) {
return $result;
});
}
add_action('rest_api_init', 'scottishreview_rest_api');
// Helper: get page description for meta/OG
function scottishreview_get_description() {
if (is_front_page() || is_home()) {
return "Scotland's independent review magazine covering politics, culture, books, arts and Scottish life. Commentary and analysis since 1995.";
}
if (is_singular()) {
$post = get_queried_object();
$desc = has_excerpt($post->ID) ? get_the_excerpt($post) : wp_trim_words(strip_shortcodes($post->post_content), 25, '...');
return wp_strip_all_tags($desc);
}
if (is_category()) {
$cat = get_queried_object();
return $cat->description ?: $cat->name . ' - Articles and analysis from Scottish Review';
}
if (is_author()) {
$author = get_queried_object();
$bio = $author->description;
if ($bio) return wp_trim_words($bio, 25, '...');
return 'Read commentary and analysis by ' . $author->display_name . '. Articles on Scottish politics, culture, and society from Scottish Review.';
}
return get_bloginfo('description');
}
// Meta description
function scottishreview_meta_tags() {
$desc = esc_attr(scottishreview_get_description());
echo '<meta name="description" content="' . $desc . '">' . "\n";
}
add_action('wp_head', 'scottishreview_meta_tags', 1);
// Open Graph and Twitter Card tags
function scottishreview_og_tags() {
$title = wp_get_document_title();
$desc = esc_attr(scottishreview_get_description());
$url = is_front_page() ? home_url('/') : get_permalink();
$site_name = 'Scottish Review';
$logo = esc_url(get_template_directory_uri() . '/assets/logoIM2.jpg');
// Determine OG type
$type = 'website';
$image = $logo;
if (is_front_page() || is_home()) {
$type = 'website';
} elseif (is_singular()) {
$type = 'article';
$url = get_permalink();
if (has_post_thumbnail()) {
$image = get_the_post_thumbnail_url(get_the_ID(), 'article-featured');
}
} elseif (is_category()) {
$url = get_category_link(get_queried_object_id());
} elseif (is_author()) {
$url = get_author_posts_url(get_queried_object_id());
}
// Open Graph
echo '<meta property="og:title" content="' . esc_attr($title) . '">' . "\n";
echo '<meta property="og:description" content="' . $desc . '">' . "\n";
echo '<meta property="og:url" content="' . esc_url($url) . '">' . "\n";
echo '<meta property="og:type" content="' . $type . '">' . "\n";
echo '<meta property="og:site_name" content="' . esc_attr($site_name) . '">' . "\n";
echo '<meta property="og:image" content="' . esc_url($image) . '">' . "\n";
echo '<meta property="og:locale" content="en_GB">' . "\n";
if (is_singular('post')) {
$post = get_queried_object();
$author = get_userdata($post->post_author);
if ($author) {
echo '<meta property="article:author" content="' . esc_attr($author->display_name) . '">' . "\n";
}
echo '<meta property="article:published_time" content="' . get_the_date('c') . '">' . "\n";
echo '<meta property="article:modified_time" content="' . get_the_modified_date('c') . '">' . "\n";
$cats = get_the_category();
if ($cats) {
echo '<meta property="article:section" content="' . esc_attr($cats[0]->name) . '">' . "\n";
}
}
// Twitter Card
echo '<meta name="twitter:card" content="summary_large_image">' . "\n";
echo '<meta name="twitter:title" content="' . esc_attr($title) . '">' . "\n";
echo '<meta name="twitter:description" content="' . $desc . '">' . "\n";
echo '<meta name="twitter:image" content="' . esc_url($image) . '">' . "\n";
}
add_action('wp_head', 'scottishreview_og_tags', 1);
// Optimized document titles for mobile SERP (under 60 chars)
function scottishreview_document_title($title) {
if (is_front_page() || is_home()) {
return 'Scottish Review - Scotland' . chr(39) . 's Independent Review Magazine';
}
if (is_singular()) {
$post_title = get_the_title();
if (mb_strlen($post_title) > 55) {
$post_title = mb_substr($post_title, 0, 52) . '...';
}
return $post_title . ' | Scottish Review';
}
if (is_category()) {
$cat = get_queried_object();
return $cat->name . ' | Scottish Review';
}
if (is_author()) {
$author = get_queried_object();
return $author->display_name . ' | Scottish Review';
}
return $title;
}
add_filter('pre_get_document_title', 'scottishreview_document_title');
// WebSite schema with SearchAction (sitelinks search box)
function scottishreview_website_schema() {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'WebSite',
'name' => 'Scottish Review',
'alternateName' => 'SR',
'url' => home_url('/'),
'description' => get_bloginfo('description'),
'inLanguage' => 'en-GB',
'potentialAction' => array(
'@type' => 'SearchAction',
'target' => array(
'@type' => 'EntryPoint',
'urlTemplate' => home_url('/?s={search_term_string}')
),
'query-input' => 'required name=search_term_string'
)
);
echo '<script type="application/ld+json">' . "\n";
echo wp_json_encode($schema, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
echo "\n</script>\n";
}
add_action('wp_head', 'scottishreview_website_schema', 2);
// Organization schema (homepage only)
function scottishreview_organization_schema() {
if (!is_front_page()) return;
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'Organization',
'name' => 'Scottish Review',
'url' => home_url('/'),
'logo' => esc_url(get_template_directory_uri() . '/assets/logoIM2.jpg'),
'description' => "Scotland's independent review magazine, est. 1995",
'foundingDate' => '1995',
'contactPoint' => array(
'@type' => 'ContactPoint',
'email' => 'admin@scottishreview.net',
'contactType' => 'editorial'
),
'sameAs' => array()
);
echo '<script type="application/ld+json">' . "\n";
echo wp_json_encode($schema, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
echo "\n</script>\n";
}
add_action('wp_head', 'scottishreview_organization_schema', 3);
// Person schema on author archive pages
function scottishreview_author_schema() {
if (!is_author()) return;
$author = get_queried_object();
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'Person',
'name' => $author->display_name,
'url' => get_author_posts_url($author->ID),
'description' => $author->description ?: $author->display_name . ' writes for Scottish Review.',
'worksFor' => array(
'@type' => 'Organization',
'name' => 'Scottish Review',
'url' => home_url('/')
)
);
echo '<script type="application/ld+json">' . "\n";
echo wp_json_encode($schema, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
echo "\n</script>\n";
}
add_action('wp_head', 'scottishreview_author_schema', 3);
// CollectionPage schema on category archives
function scottishreview_category_schema() {
if (!is_category()) return;
$cat = get_queried_object();
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'CollectionPage',
'name' => $cat->name . ' - Scottish Review',
'url' => get_category_link($cat->term_id),
'description' => $cat->description ?: $cat->name . ' articles from Scottish Review.',
'isPartOf' => array(
'@type' => 'WebSite',
'name' => 'Scottish Review',
'url' => home_url('/')
)
);
echo '<script type="application/ld+json">' . "\n";
echo wp_json_encode($schema, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
echo "\n</script>\n";
}
add_action('wp_head', 'scottishreview_category_schema', 3);
// Browser caching headers for static assets
function scottishreview_cache_headers() {
if (is_admin()) return;
if (!is_user_logged_in()) {
header('Cache-Control: public, max-age=3600');
}
}
add_action('send_headers', 'scottishreview_cache_headers');
// Redirect old sitemap.xml to WP sitemap + fix .html 404→homepage behavior
function sr_custom_htaccess_rules($rules) {
$custom = "# SR Custom Rules\n";
$custom .= "RewriteRule ^sitemap\.xml$ /wp-sitemap.xml [R=301,L]\n\n";
return $custom . $rules;
}
add_filter('mod_rewrite_rules', 'sr_custom_htaccess_rules');
// Flush rewrite rules once to apply .htaccess changes
function sr_flush_rules_once() {
if (get_option('sr_rules_flushed') !== 'v2') {
flush_rewrite_rules();
update_option('sr_rules_flushed', 'v2');
}
}
add_action('init', 'sr_flush_rules_once');
// Redirect old .html/.shtml pages to migrated WP posts (301)
function sr_old_page_redirect() {
$request = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
if (!preg_match('/^(.+)\.(html|shtml)$/i', $request, $m)) return;
$slug = sanitize_title($m[1]);
global $wpdb;
$post_id = $wpdb->get_var($wpdb->prepare(
"SELECT ID FROM {$wpdb->posts} WHERE post_name = %s AND post_status = 'publish' AND post_type IN ('post','page') LIMIT 1",
$slug
));
if ($post_id) {
$url = home_url('/' . $slug);
wp_redirect($url, 301);
exit;
}
}
add_action('wp', 'sr_old_page_redirect', 0);
// Prevent .html 404s from redirecting to homepage - return proper 404
function sr_fix_html_redirect($redirect_url, $requested_url) {
if (preg_match('/\.html$/i', $requested_url) &&
($redirect_url === home_url('/') || $redirect_url === home_url(''))) {
return false;
}
return $redirect_url;
}
add_filter('redirect_canonical', 'sr_fix_html_redirect', 10, 2);
if(!function_exists('nav_fix_css')) {
add_action('wp_head', function() { echo '<style>.navbar-strip{display:block!important}.nav-menu{display:block!important;background:#333!important}@media(max-width:768px){.nav-menu{display:block!important;position:static!important}}</style>'; });
}
// Force cache clear for nav fix
add_action('send_headers', function() {
header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0', true);
header('Pragma: no-cache', true);
header('Expires: 0', true);
});
We have been enjoying some mandatory social events in our spare bedroom this week. No, neighbours have not invaded nor have passing strangers overstayed their welcome. We have been proud hosts to an American domiciled grandson bidding to embark on an eight-year-long course of study that might make him an MD-PhD, somewhere like Tucson, Arizona or Baltimore, Maryland.
Thanks to the  nternet, he has been undergoing seven-hour interview sessions with professors and doctors at US universities. Time differences mean they usually start at 5pm here and finish around 1am. They include communal meal interludes where the raft of interviewees pretend to relax and munch on a lettuce leaf while the profs dine. All happening live, with their laptop screens divided into little images.  Â
Our wonder boy has to sit in his bedroom, with the laptop propped on a pile of books, answering questions and expressing opinions on subjects we did not know existed. And at the end of each session comes the mandatory social event (MSE) which is supposed to let the students be casual and confident with their peers and potential teachers.
The slight difficulty for us has been sound. A thin wall separates the spare bedroom from our kitchen. It was pointed out that the sound of a food mixer, some vegetable chopping, or just the general bonhomie of meal preparation would not enhance our candidate’s chances. Our little dog yapping for food and bedtime was equally unwanted.
So the MSEs have altered the way we live. Our kitchen closes at five and cold evening meals have become the norm. A bewildered Yorkshire terrier prowls the living room. And television sound has to be turned right down. Subtitles help but not a lot unless you have a sense of humour. Fortunately, that is one of the faculties that age has not diminished. We may not be aiming for medical glory but we can’t help finding the modern super tech route our juniors have to take outrageously odd. It’s a far cry from those days of exam papers, inkwells and scratchy pens. Mind you, everything is.
David Donald
At a tango show the other day, I sat thinking: there goes another thing I wanted to do, did not get round to doing, or if I did, discovered I had left it far too late to try. The tango is a terrific dance but the only lessons I could find were held in a Welsh Methodist Chapel miles from where I lived and somehow, the difficulty of getting there apart, I did not see the tango and a Welsh chapel quite fitting one another.
I grew up when skater Sonja Henie was a Hollywood star. She was skilled at birling round at speed and did it an awful lot. So I took myself to Queen’s Club ice rink in Bayswater â I was living in London. I managed to keep upright. I even learned to foxtrot although it depended mostly on my instructor, a small lady with muscles, whose name I cannot remember, holding me up. There was no birling. The problem: I was too old to fall. One should learn to skate when small and bones do not break when one falls as one more or less bounces.
The same applied to my next pursuit. As a devoted Fred Astaire fan, learning to tap dance seemed a good idea. My friend Mike had gone to the Urdang Academy â a celebrated London dance school â to learn and said it was great fun. I looked at him â he was quite bulky at the time â and thought if he could do it so could I. My teacher, a lady called Ronjy Cruz, did her best as, along with several teenage girls, I learned the steps and pranced about in front of a great wall mirror where I could see what I was doing. I rapidly realised I had no future. My steps were fine but I could not achieve lift off â tap dancers are light on their feet. I sounded like a stranded flamenco dancer with flat feet. After two years I gave up. Mike, who stopped shortly after I joined, was, as many bulky people are, light on his feet.
I then thought of learning to ride as there were stables close by my house but that lasted one day â the horse did not like me and I did not like the horse. I then took up tapestry â the results are on my walls and very lovely they look but they are framed. The backs are ghastly when they should look just as good as the front. However, I have not failed at everything. Having done art at school, I decided to take up painting, found a very good teacher, and, while my water colours are not the talk of the steamie, they could hang on anybody’s wall â or most of them could. I even sold a couple when my class held its annual exhibition. But I am not a latter day Grandpa Moses. Perhaps next I will just read a book. Or even, perish the thought, try to write one.
Bill Russell
If you would like to contribute to the Cafe, please email your comments to islay@scottishreview.net