Support Forums for LiveMesh Themes & Plugins › Forums › Peak Theme Support › Customizing Campaigns and Slugs
Tagged: campaigns custom slugs
- This topic has 7 replies, 3 voices, and was last updated 7 years, 7 months ago by emakundi.
-
AuthorPosts
-
August 31, 2016 at 4:01 am #23824emakundiMember
Hi there!
I have a couple questions about some customizations.
I would like to add more information on the “Show Campaign” widget on the homepage like a quote and some campaign information. I was able to change the php to have that information show on the “Campaigns” page but I can’t figure it out for the “Show Campaign” widget. Is this possible?
Is it also possible to change the slugs? For example, I would like to change “https://www.livemeshthemes.com/peak/campaign/nutrition-is-life/” to “https://www.livemeshthemes.com/peak/somethingdifferent/nutrition-is-life/”. And also “https://www.livemeshthemes.com/peak/campaign_category/calamity/” to “https://www.livemeshthemes.com/peak/somethingdifferent_category/calamity/”.
Thank you!!
August 31, 2016 at 4:37 pm #23839VeenaModeratorIs it also possible to change the slugs?
Pls modify file plugins/livemesh-tools/includes/register-post-types.php line no:354 from'rewrite' => array('slug' => 'campaign'),
to
'rewrite' => array('slug' => 'somethingdifferent'),
And modify line no:364 from
'rewrite' => true,
to
'rewrite' => array('slug' => 'somethingdifferent_category'),
And you will need to visit Settings->Permalinks once for the slug change to take effect.
September 1, 2016 at 8:48 am #23864emakundiMemberHi Phoenix,
Thank you for you reply. I have modified the lines you mentioned and added this code to my functions.php file in my child theme:
$register_post_types_path = get_stylesheet_directory() . '/framework/plugins/livemesh-tools/includes/'; include_once($register_pot_types_path . 'register-post-types.php');
I visited Settings -> Permalinks after I FTPed the register-post-types.php file but the slugs did not updated. Do I need to change something in Settings -> Permalinks?
Is there anything else I should change in the register-post-types.php file to change the slugs?
Thanks again!!
September 1, 2016 at 11:06 am #23868emakundiMemberHello again Pheonix,
I think my issue has something to do with “flushing rewrite rules” but I am not sure how to go about it.
https://codex.wordpress.org/Function_Reference/register_post_type#Flushing_Rewrite_on_Activation
I tried including the code snippet for plugin activation:
function my_rewrite_flush() { lm_register_campaign_post_type(); flush_rewrite_rules(); } register_activation_hook( __FILE__, 'my_rewrite_flush' );
after this snippet of code in register-post-types.php:
if (!function_exists('lm_register_campaign_post_type')) { ... }
but it is not working.
Do you have any idea how to go about this?
Thank you!
September 1, 2016 at 1:57 pm #23873RaghavendraModeratorOverriding in child theme for plugin functions does not seem to work and your child theme function will not get called prior to the plugin one (and hence will be ignored). Since this is a plugin that is rarely updated by us, if at all, and does very little other than registering custom post types, may be you can just modify the plugin, rename it and activate the same instead of the Livemesh Tools one.
You can also consider this solution and see if it works –
September 2, 2016 at 6:38 am #23892emakundiMemberHi meteorite,
I managed to change the slug in my child theme by inserting this in my child theme’s functions.php file:
add_action('init', 'change_campaign_slug', 100); function change_campaign_slug() { $args = get_post_type_object('campaign'); $args->rewrite['slug'] = 'entrepreneur'; register_post_type($args->name, $args); } function my_rewrite_flush() { change_campaign_slug(); flush_rewrite_rules(); } register_activation_hook( __FILE__, 'my_rewrite_flush' );
I visited Settings -> Permalinks and save the settings and the slug was updated.
However, I am also trying to change the campaign category slug. I tried the following code in my child theme’s functions.php file:
add_action('init', 'change_campaign_category_slug'); function change_campaign_category_slug() { $taxonomy = get_object_taxonomies('campaign', 'names'); $taxononmy->rewrite['slug'] = 'entrepreneur_category'; register_taxonomy($taxonomy->name, $taxonomy); } function my_rewrite_flush_2() { change_campaign_category_slug(); flush_rewrite_rules(); } register_activation_hook( __FILE__, 'my_rewrite_flush_2' );
but the ‘campaign_category’ does not change to ‘entrepreneur_category’. Any ideas on how to rewrite post object taxonomies?
Thank you!
September 2, 2016 at 7:46 am #23893RaghavendraModeratorI hit upon a small idea to solve this issue (I wish we had made your job a little easier with filters) – create a small plugin which overwrites the lm_register_campaign_post_type() method of livemesh tools plugin and best of all, it works! It helps change the slug of both campaign as well as campaign category to department and department_category. We just need to ensure that this method definition is called prior to the one in Livemesh Tools. Since the Livemesh Tools loads the function through a filter, our job is made easy.
You just need to visit once Settings->Permalinks. Pls have a look at the attached file which is actually a plugin which you need to activate in plugins admin.
September 2, 2016 at 8:58 am #23900emakundiMemberAmazing!!! Works like a charm, thank you so much!
-
AuthorPosts
- The topic ‘Customizing Campaigns and Slugs’ is closed to new replies.