- This topic has 21 replies, 8 voices, and was last updated 2 years, 9 months ago by
Fernando.
-
AuthorPosts
-
September 12, 2022 at 9:28 am #2340820
Zarar
OK, I solved it. Create a Hook element at wp_head:
<?php if (function_exists('z_taxonomy_image')) { ?> <meta property="og:image" content="<?php echo z_taxonomy_image_url();?> " /> <meta name="twitter:card" content="summary_large_image" /> <meta name="twitter:image" content="<?php echo z_taxonomy_image_url();?>" /> <?php }?>
Check out working example for Twitter/social here: https://twitter.com/raptorsrepublic/status/1569352226996654082
November 28, 2022 at 6:10 pm #2440138Richard
I went to the add featured image to category page and noted the warning “This plugin hasn’t been tested with the latest 3 major releases of WordPress. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.” is this still the way to add a featured imgage to category page?
generatepress newbie
November 28, 2022 at 6:39 pm #2440160Fernando Customer Support
Hi Richard,
This is just one way to add a featured image to a Category page. If it’s still working, then it should be good.
Otherwise, you can use ACF plugin. Here’s an article showing how to add and show an Image field to a taxonomy page: https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
You should also be able to use GenerateBlocks to grab the custom ACF image through its Dynamic settings. Reference: https://docs.generateblocks.com/article/image-overview/#dynamic-data
For instance, if you have a custom field called ‘myimage’ which returns the Image ID, here’s a sample Hook Element to show it: https://share.getcloudapp.com/5zu2mx0R
Sample code:
<?php $term = get_queried_object(); $image = get_field('myimage', $term); $size = 'full'; // (thumbnail, medium, large, full or custom size) if( $image ) { echo wp_get_attachment_image( $image, $size ); } ?>
November 28, 2022 at 9:19 pm #2440290Richard
when I tried to create a hook in the Execute PHP field I got this message :Unable to execute PHP as DISALLOW_FILE_EDIT is defined
I assume this is a security measure, how would I turn it off and then maybe back on afterwards???
November 28, 2022 at 10:02 pm #2440338Fernando Customer Support
I see. This would mean that the wp-config file for that site is disallowing PHP Edits, or it could be a security plugin.
This article explains the server-level requirements:
https://docs.generatepress.com/article/disallow-php-execution/
Security-wise, disallowing PHP Edits is recommended by WordPress as an extra layer of security. By disabling file editing, you prevent bad people who gain access to your Dashboard (bad in itself) from executing PHP and gaining access to your server.
The alternative would be is to just add the PHP Snippet provided here to allow editing in Hooks only:
https://docs.generatepress.com/article/generate_hooks_execute_php/
December 1, 2022 at 1:49 pm #2445597Richard
so you are suggesting I could edit the wp-config file line define( ‘DISALLOW_FILE_EDIT’, true ); to change the “true” to “false” and after making the changes edit it back to “true”
December 1, 2022 at 7:09 pm #2445945Fernando Customer Support
No, that’s not what I was suggesting. PHP code isn’t one-time execution. It runs every time it’s opened/read. In your case, that code runs every time someone opens your category page.
It’s either you set that to false, remove that, or add this snippet instead: https://docs.generatepress.com/article/generate_hooks_execute_php/
-
AuthorPosts
- You must be logged in to reply to this topic.