Skip to content

Instantly share code, notes, and snippets.

View someguy9's full-sized avatar
🏠
Working from home

Andy Feliciotti someguy9

🏠
Working from home
View GitHub Profile
<?php
// Display post title using post ID
echo get_the_title( 5 );
// Display post title and safely escape value
echo esc_html( get_the_title() );
// Using the_title function to automatically echo the title, while you can append or prepend the title using the function as displayed below
the_title( 'Before:', ' - After' )
@someguy9
someguy9 / wordpress-display-title.php
Last active October 25, 2022 15:34
WordPress get current page title
<?php
// Display post title
echo get_the_title();
@someguy9
someguy9 / php-current-page-url-with-query-string.php
Created July 11, 2022 12:51
Get current page URL with query string in PHP
<?php
$url_parts = parse_url( home_url() );
$current_url_with_query_string = $url_parts['scheme'] . "://" . $url_parts['host'] . add_query_arg( NULL, NULL );
echo $current_url_with_query_string;
@someguy9
someguy9 / wordpress-get-current-slug.php
Created July 11, 2022 12:40
Get the current slug in WordPress.
<?php
global $wp;
$current_slug = add_query_arg( array(), $wp->request );
echo $current_slug;
@someguy9
someguy9 / wordpress-get-current-url.php
Created July 11, 2022 12:29
Get current page URL in WordPress
<?php
global $wp;
$current_url = home_url( add_query_arg( array(), $wp->request ) );
echo $current_url;
@someguy9
someguy9 / generatepress-dark-mode.css
Last active May 6, 2022 12:23
Starter for adding darkmode to your Generatepress site
@media (prefers-color-scheme: dark) {
:root {
--contrast: #fff;
--contrast-2: #000;
--contrast-3: #000;
--base: #1e1e1e;
--base-2: #212121;
--base-3: #212121;
--accent: #1e90ff;
--global-color-8: rgba(180, 180, 191, 0.1);
<?php
$meta_query_args = array(
'post_type' => 'page',
'order' => 'ASC',
'meta_key' => 'city_name',
'orderby' => 'meta_value'
);
$meta_query = new WP_Query( $meta_query_args );
<?php
$meta_query_args = array(
'meta_query' => array(
'relation' => 'AND',
array(
array(
'key' => 'city_name',
'value' => array('New York City', 'London', 'San Francisco'),
'compare' => 'IN'
),
@someguy9
someguy9 / wordpress-query-post-meta-value-multiple.php
Created April 29, 2022 21:30
Query multiple meta key values in WordPress
<?php
$meta_query_args = array(
'meta_query' => array(
array(
'key' => 'city_name',
'value' => array('New York City', 'London', 'San Francisco'),
'compare' => 'IN'
)
)
);
@someguy9
someguy9 / wordpress-query-post-meta-value.php
Created April 29, 2022 21:09
Query Posts By a Meta Value
<?php
$meta_query_args = array(
'meta_query' => array(
array(
'key' => 'featured_post',
'value' => 'yes',
'compare' => '='
)
)
);