How to create WP Editor using javascript

Thanks to Jacob Peattie’s comment I can answer this using JS only. Actually we did something similar, but prior 4.8 and it wasn’t this easy, so we did use wp_editor() in the end. But now, you can do so using wp.editor object in JavaScript. There are 3 main functions wp.editor.initialize = function( id, settings ) … Read more

Replace image attributes for lazyload plugin (data-src)

instead of replacing the alt tag you could add-an-attribute-to-a-tag function add_lazyload($content) { $dom = new DOMDocument(); @$dom->loadHTML($content); foreach ($dom->getElementsByTagName(‘img’) as $node) { $oldsrc = $node->getAttribute(‘src’); $node->setAttribute(“data-original”, $oldsrc ); $newsrc=””.get_template_directory_uri().’/library/images/nothing.gif’; $node->setAttribute(“src”, $newsrc); } $newHtml = $dom->saveHtml(); return $newHtml; } note: i didn’t quite tested this code, so be careful 🙂

How to disable content pagination?

EDIT – Now that 4.4 is out, you should use the content_pagination filter. See birgire’s answer below. You can add formatting to raw post content by applying the content filters directly to $post->post_content: echo apply_filters( ‘the_content’, $post->post_content ); This will bypass pagination by not using the get_the_content function, which is what the_content uses internally to … Read more

Why declare $post globally?

In the tutorial (Example 1), he has to declare the global $post so that he can access the post_parent from it. In a function like that, the $post is not a global variable unless he makes it so. In the codex (Example 2), it is declared global because the sample code is just a sample, … Read more

Fatal error: Call to undefined function post_exists()

The files in wp-admin are only loaded when you’re in the admin area… when you’re looking at pages or posts those functions aren’t loaded. In that case you’d need to require the file first, so you’d want to do something like this in your function: if ( ! is_admin() ) { require_once( ABSPATH . ‘wp-admin/includes/post.php’ … Read more

How to display the page title/content in the Posts page?

I’m assuming the following: You’re using a Static Front Page You have a separate static page assigned to display the blog posts index You have created the home.php template file in your Theme The static page assigned to display the blog posts index is titled Blog You have added some post content to this static … Read more

Get the current post ID as a variable in Javascript

You can pass variables to javascript using wp_localize_script function: https://codex.wordpress.org/Function_Reference/wp_localize_script Add the following to functions.php if(!function_exists(‘load_my_script’)){ function load_my_script() { global $post; $deps = array(‘jquery’); $version= ‘1.0’; $in_footer = true; wp_enqueue_script(‘my-script’, get_stylesheet_directory_uri() . ‘/js/my-script.js’, $deps, $version, $in_footer); wp_localize_script(‘my-script’, ‘my_script_vars’, array( ‘postID’ => $post->ID ) ); } } add_action(‘wp_enqueue_scripts’, ‘load_my_script’); And your js file (theme-name/js/my-script.js): jQuery(document).ready(function($) { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)