Still relevant method of embedding images in WP Theme in 2018

someone questioned me today that I am not doing it correctly? <?php echo get_bloginfo(‘template_url’) ?>/images/logo.png There are 2 possible reasons this could be considered ‘incorrect’: get_bloginfo is a very old function that does multiple things, this particular function was replaced by get_template_directory_uri and get_stylesheet_directory_uri Security! You didn’t escape anything! The entire thing should be wrapped … Read more

bloginfo(‘template_directory’) img src

You cannot use bloginfo() while your are outputting using echo because bloginfo it self also out puts string using echo. Below will work for you, you also have extra double quote which i have removed…. <?php $attch_id_1 = pn_get_attachment_id_from_url(get_post_meta($post->ID, ‘img1’, true)); $image_attributes_1 = wp_get_attachment_image_src( $attch_id_1, ‘full’); $attch_id_2 = pn_get_attachment_id_from_url(get_post_meta($post->ID, ‘img2’, true)); $image_attributes_2 = wp_get_attachment_image_src( $attch_id_2, … Read more

How do I create a dynamically-updated copyright statement?

Here’s what I use: function oenology_copyright() { global $wpdb; $copyright_dates = $wpdb->get_results(” SELECT YEAR(min(post_date_gmt)) AS firstdate, YEAR(max(post_date_gmt)) AS lastdate FROM $wpdb->posts WHERE post_status=”publish” “); $output=””; if($copyright_dates) { $copyright = “&copy; ” . $copyright_dates[0]->firstdate; if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) { $copyright .= ‘-‘ . $copyright_dates[0]->lastdate; } $output = $copyright; } return $output; } Of course, if there’s a … Read more

Right way to add HTML bloginfo name using a filter

You can’t check the context while the filter callback is called, because the element is already in the frontend. There are 3 solutions though: 1. jQuery Search for the element and add html to the places in the name. 2. PHP in element Get the bloginfo(‘name’); in the element and change it on that place … Read more

Is it possible to change the template_directory?

You can filter template_directory_uri: <?php add_filter( ‘template_directory_uri’, function( $template_dir_uri ){ return str_replace( ‘http://example.com’, ‘https://cdn.example.com’, $template_dir_uri ); }); This will change URIs so they point at a CDN subdomain served via HTTPS.

Filter the blog’s title without using global variables

You can encapsulate the logic in a class: class NameSwitch { private $state = false; private $string; public function __construct( $string ) { $this->string = $string; } public function change_state() { $this->state = ! $this->state; return $this->state; } public function replace( $output, $show = NULL ) { if ( ‘name’ !== $show ) return $output; … Read more

Filter the blog title displayed in the header

Remove that filter/function and apply your markup in the PHP template/page file. If you need help post where you output the title. CLASS Here is how I might set this up using a class: if ( ! class_exists( ‘ThemeCustomizations’ ) ) { class ThemeCustomizations { static $inBody = false; public static function set_in_body_true() { static::$inBody … Read more

How to use tinyMCE for user “biographical info” without messing with any core file?

Not sure if this is the perfect way to do it, but it worked for me by removing the description element using jQuery and then adding editor for the description element. /******************************************* * TinyMCE EDITOR “Biographical Info” USER PROFILE *******************************************/ function biographical_info_tinymce() { if ( basename($_SERVER[‘PHP_SELF’]) == ‘profile.php’ || basename($_SERVER[‘PHP_SELF’]) == ‘user-edit.php’ && function_exists(‘wp_tiny_mce’) ) … Read more

bloginfo(‘stylesheet_directory’) vs. get_stylesheet_directory_uri() and include(‘file.php’) vs. get_template_part()

get_stylesheet_directory_uri() returns a value, it doesn’t print anything. So you have to use: echo get_stylesheet_directory_uri(); get_template_part() is just a wrapper for locate_template(). But the latter has one advantage: It returns the path of the file it has found. Try the following: $path = locate_template( ‘sidebar-front.php’, TRUE ); echo $path;