How do I add a template to a theme using a plugin?

Here is a fairly simple approach I was able to get working within a plugin. You’ll want to reference https://developer.wordpress.org/reference/hooks/theme_page_templates/ and https://developer.wordpress.org/reference/hooks/template_include/ as you review the code below. <?php //Add our custom template to the admin’s templates dropdown add_filter( ‘theme_page_templates’, ‘pluginname_template_as_option’, 10, 3 ); function pluginname_template_as_option( $page_templates, $theme, $post ){ $page_templates[‘template-landing.php’] = ‘Example Landing Page’; … Read more

Trying to manage templates on a blog with lots of custom taxonomies

Page templates can be stored within the page-templates or templates subdirectory within a theme, but this does not apply to custom post type or taxonomy templates. Fortunately, the template_include filter can be used to change the template that will be loaded. In the example below, template files are stored in the /theme-name/templates/ directory. /** * … Read more

How to set global variables in template page?

Anywhere in your script, you can define a global variable as follow: Using the superglobal $GLOBALS array. This array is predefined by PHP, and is available in all scopes. It’s an associate array, containing all global variables as a key-value pair. ie: the key will be the variable name, and value will be the value … Read more

Why aren’t my posts showing?

This doesn’t work the way you think it does because get_pages doesn’t do what you think it does. First, understand that all pages, all content, in WordPress is really a “post”. A “Page” is just a special type of post. Now, in a normal environment, you wouldn’t call “get_” anything. This is why you’re confused, … Read more

How can I get the content of the home page?

alternative to using the default loop in the front-page.php template: if( have_posts() ) { while( have_posts() ) { the_post(); the_content(); } } you could try using: if( get_option( ‘page_on_front’ ) ) { echo apply_filters( ‘the_content’, get_post( get_option( ‘page_on_front’ ) )->post_content ); } https://codex.wordpress.org/Option_Reference

Can I use require() function in a template file?

You are seeing this error because you are requireing the file with a relative path. As @Mark Kapulun pointed out in the comments you should not use relative paths when requireing files. Instead you want to be explicit and use absolute paths. Use get_template_directory() which returns the Absolute path to the directory of the current … Read more

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