Custom image upload

May be you are not returning correctly from function, Try this, function insert_attachment($file_handler, $post_id, $setthumb=false) { // check to make sure its a successful upload // changes start if ($_FILES[$file_handler][‘error’] !== UPLOAD_ERR_OK) { return __return_false(); } // changes end require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’); require_once(ABSPATH . “wp-admin” . ‘/includes/file.php’); require_once(ABSPATH . “wp-admin” . ‘/includes/media.php’); $attach_id … Read more

How to Include HTML in Excerpts?

The excerpt is created in -> wp-includes/formatting.php with this code: function wp_trim_excerpt($text) { // Fakes an excerpt if needed global $post; if ( ” == $text ) { $text = get_the_content(”); $text = apply_filters(‘the_content’, $text); $text = str_replace(‘\]\]\>’, ‘]]>’, $text); $text = strip_tags($text); $excerpt_length = 55; $words = explode(‘ ‘, $text, $excerpt_length + 1); if … Read more

Appearance -> Menu -> Menu Structure : Add plain HTML code as an element

You can add your flag (plain) html into menu at last li tag. <?php function add_last_nav_item($items, $args) { if ($args->menu->slug == ‘topbar-menu’) { // change your menu slug name // Add your html $item = ‘<li class=”searchbox”> <input type=”search” placeholder=”Search……” name=”search” class=”searchbox-input” onkeyup=”buttonUp();” required> <input type=”submit” class=”searchbox-submit” value=””> <span class=”searchbox-icon”><i class=”fa fa-search”></i></span> </li>’; $items = … Read more

How can I change the title of an Add New page in Admin for custom post type

When you’re registering new post type with register_post_type, you can pass labels parameter (which is an array of labels used for that CPT). You can customize these labels: ‘name’ – general name for the post type, usually plural. The same and overridden by $post_type_object->label. Default is Posts/Pages ‘singular_name’ – name for one object of this … Read more

How do I add some HTML before & after the content for all posts?

Make use of the the_content filter. This way you can adjust/add/remove certain stuff from the content add_filter( ‘the_content’, function ( $content ) { // Make sure we only target the main query’s content, adjust as needed if ( !in_the_loop() ) return $content; // We are targeting the correct content, so lets add what we need … Read more

How do I add HTML to a PHP function [closed]

You can use ‘echo’ (or ‘print’) to enclose HTML, but sometimes that gets a bit messy with complex HTML, not to mention having to escape quote/double-quote character. So try something like this: function myfunction() { // after this next, plain HTML ?> <div class=”myclass”><h1 align=”center”>This is a heading</h1></div> <!– more HTML code here –> <?php … Read more

Blank space at beginning of tag?

It looks like your site’s title is empty. Fill it out or try for example: add_filter( ‘wp_title’, function( $title ) { return trim( $title ); } ); to remove the blank space in front. For your setup, the following part of wp_title() is responsible for the blank space: $title = $prefix . implode( ” $sep … Read more

To echo or not to echo?

The main differences are: the first snippet has html inside php while the second one has php inside html. Both approaches are basically valid, both are fine. I would however always prefer (and recommend) to have php inside html because chances are that a third person / designer might have less difficulties in understanding the code … Read more