Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

PKG_VERSION placeholder seems not to work in markup files #34

Closed
renestalder opened this issue Jun 2, 2015 · 5 comments
Closed

PKG_VERSION placeholder seems not to work in markup files #34

renestalder opened this issue Jun 2, 2015 · 5 comments

Comments

@renestalder
Copy link
Contributor

e.g. using it in functions.php, it doesn't get replaced on compilation.

@renestalder
Copy link
Contributor Author

Okay, it works in comments, but not somewhere else. Wanted behaviour?

@xarem
Copy link
Member

xarem commented Jun 4, 2015

It works in markup files (in comments and in the code) but it looks like it works only for the first replacement in every file.

Example:

src:

wp_enqueue_style('made_fonts', get_template_directory_uri() . '/fonts.css', [], '{PKG_VERSION}');
wp_enqueue_style('made_style', get_stylesheet_uri(), [], '{PKG_VERSION}');
wp_enqueue_script('made_scripts', get_template_directory_uri() . '/app.js', [], '{PKG_VERSION}', true);

dist:

wp_enqueue_style('made_fonts', get_template_directory_uri() . '/fonts.css', [], '0.0.0');
wp_enqueue_style('made_style', get_stylesheet_uri(), [], '{PKG_VERSION}');
wp_enqueue_script('made_scripts', get_template_directory_uri() . '/app.js', [], '{PKG_VERSION}', true);

@renestalder
Copy link
Contributor Author

This might only work if you remove the comment in the head of the default template. I've already tested to set a variable at start, after the first replacement which is the comment.

How about reading the package.json in PHP separately and setting a global variable for use in markup files? I'm bothered that there is a performance drop in compilation if the replace script of gulp would have to replace all instances of all markup files.

@xarem
Copy link
Member

xarem commented Jun 4, 2015

By default, we add the current version to the theme's style.css (https://github.com/whatwedo/gulp-wp-theme/blob/master/src/resources/stylus/style.styl#L6)

Therefore, you can use a WordPress internal function to get the current theme version:

https://codex.wordpress.org/Function_Reference/wp_get_theme#Display_the_Current_Theme.27s_Version

But anyway this bug should be fixed

@renestalder
Copy link
Contributor Author

Uhh.... didn't know about that.

Solves the problem entirely and IMHO should be used instead of replaces in markup.
https://codex.wordpress.org/Function_Reference/wp_get_theme

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants